Skip to content

Use np.multiply.reduce() instead of np.prod() for better performance #12

@SaFE-APIOpt

Description

@SaFE-APIOpt

chemopt/gmm.py

Line 29 in 926440b

modes = np.array([1/np.prod(cov) for cov in self.cov])

In the line:
modes = np.array([1 / np.prod(cov) for cov in self.cov])
it is recommended to use np.multiply.reduce() instead of np.prod():
modes = np.array([1 / np.multiply.reduce(cov) for cov in self.cov])
np.prod() is a wrapper around np.multiply.reduce() and introduces additional overhead such as input validation and type handling. In performance-sensitive calculations, using np.multiply.reduce() results in a shorter execution path and better efficiency while maintaining the same functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions