forked from FEniCS/fiat
-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Line 70 in 637894a
| sub_cmps = [0] + list(numpy.prod(e.value_shape(), dtype=int) |
In the line:
sub_cmps = [0] + list(numpy.prod(e.value_shape(), dtype=int) for e in self.elements()) it is recommended to replace numpy.prod() with numpy.multiply.reduce() for better performance. While both functions yield the same result, numpy.prod() is a wrapper around numpy.multiply.reduce() and includes additional overhead such as input validation, type conversion, and internal logic for handling parameters like dtype, keepdims, and initial.
In scenarios where only a straightforward element-wise product is needed—as in computing the total number of components from e.value_shape()—using numpy.multiply.reduce() provides a more efficient execution path with fewer internal function calls. A direct replacement like the following preserves functionality while reducing overhead:
sub_cmps = [0] + list(numpy.multiply.reduce(e.value_shape()).item() for e in self.elements())
Metadata
Metadata
Assignees
Labels
No labels