Skip to content

Commit

Permalink
Support zero-shaped arrays
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
mrocklin committed Apr 17, 2017
1 parent 28505c3 commit 18791ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sparse/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ def __init__(self, coords, data=None, shape=None, has_duplicates=True):
self.shape = tuple(shape)
self.data = np.asarray(data)
self.coords = np.asarray(coords)
self.coords = self.coords.astype(np.min_scalar_type(max(self.shape)))
if self.shape:
dtype = np.min_scalar_type(max(self.shape))
else:
dtype = np.int_
self.coords = self.coords.astype(dtype)
assert len(data) == self.coords.shape[1]
self.has_duplicates = has_duplicates

Expand Down
1 change: 1 addition & 0 deletions sparse/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_to_scipy_sparse():
[(3, 4), (5, 4, 3), ((1, 0), (1, 2))],
[(3, 4, 5), (4,), (1, 0)],
[(4,), (3, 4, 5), (0, 1)],
[(4,), (4,), (0, 0)],
])
def test_tensordot(a_shape, b_shape, axes):
a = random_x(a_shape)
Expand Down

0 comments on commit 18791ba

Please sign in to comment.