Skip to content

Commit

Permalink
better fix for empty SimpleSparse case, enabling .array()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrognlie committed Mar 15, 2021
1 parent cfb5207 commit 0949b5a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sequence_jacobian/jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ def array(self):
if self.indices is not None:
return self.indices, self.xs
else:
if not self.elements:
# empty SimpleSparse
return np.empty((0, 2), dtype=int), np.empty(0)

indices, xs = zip(*self.elements.items())
self.indices, self.xs = np.array(indices), np.array(xs)
return self.indices, self.xs
Expand Down Expand Up @@ -559,8 +563,6 @@ def __matmul__(self, A):
return multiply_rs_rs(self, A)
elif isinstance(A, np.ndarray):
# multiply SimpleSparse by matrix or vector, multiply_rs_matrix uses slicing
if not self.elements:
return np.zeros_like(A)
indices, xs = self.array()
if A.ndim == 2:
return multiply_rs_matrix(indices, xs, A)
Expand Down

0 comments on commit 0949b5a

Please sign in to comment.