Skip to content

Commit 487809e

Browse files
committed
perf: use -1 in shape for presence check in COO.reshape
Replace `any(d == -1 for d in shape)` with `-1 in shape`. The latter is a C-level tuple containment, the former a Python-level generator. On this machine (micro): 221 ns -> 45 ns per check. End-to-end on the PR's repro (median of 3): reshape(a.shape): 0.4 us -> 0.2 us (matches main; erases the regression introduced by running the -1 check unconditionally) reshape((-1, K)): 2.7 us -> 2.3 us (small incremental win) Pure readability / perf nit; semantics are identical since shape is already a tuple of ints by the line above.
1 parent 71bbf2d commit 487809e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

sparse/numba_backend/_coo/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ def reshape(self, shape, order="C"):
10701070
if order not in {"C", None}:
10711071
raise NotImplementedError("The `order` parameter is not supported")
10721072

1073-
if any(d == -1 for d in shape):
1073+
if -1 in shape:
10741074
extra = int(self.size / np.prod([d for d in shape if d != -1]))
10751075
shape = tuple([d if d != -1 else extra for d in shape])
10761076
if self.shape == shape:

0 commit comments

Comments
 (0)