Skip to content

Commit

Permalink
Bugfix for row-wise combining of 2D SparseNdarrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Sep 28, 2023
1 parent 55bed28 commit 0b5fdb5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.3.2

- Bugfix for row-wise combining of 2-dimensional `SparseNdarray`s.

## Version 0.3.1

- Added a `wrap()` method that dispatches to different `DelayedArray` subclasses based on the seed.
Expand Down
2 changes: 1 addition & 1 deletion src/delayedarray/SparseNdarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ def _recursive_concatenate_SparseNdarray(contents: list, final_shape: Tuple[int,
_coerce_concatenated_SparseNdarray_types(new_contents, payload=payload, dim=dim)
return new_contents

elif dim == len(final_shape) - 2:
elif dim == 1:
new_contents = []
for i in range(final_shape[dim]):
outidx = []
Expand Down
29 changes: 28 additions & 1 deletion tests/test_SparseNdarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ def test_SparseNdarray_transpose():
#######################################################


def test_SparseNdarray_concatenate_simple():
def test_SparseNdarray_concatenate_3d():
test_shape = (10, 20, 30)
contents = mock_SparseNdarray_contents(test_shape, lower=-100, upper=100, dtype=numpy.int16)
y = delayedarray.SparseNdarray(test_shape, contents)
Expand Down Expand Up @@ -1118,6 +1118,33 @@ def test_SparseNdarray_concatenate_simple():
assert (numpy.array(combined) == numpy.concatenate((ref, ref2), axis=2)).all()


def test_SparseNdarray_concatenate_2d():
test_shape = (55, 20)
contents = mock_SparseNdarray_contents(test_shape, lower=-100, upper=100, dtype=numpy.int16)
y = delayedarray.SparseNdarray(test_shape, contents)
ref = numpy.array(y)

# Combining on the first dimension.
test_shape2 = (25, 20)
contents2 = mock_SparseNdarray_contents(test_shape2, lower=-100, upper=100, dtype=numpy.int16)
y2 = delayedarray.SparseNdarray(test_shape2, contents2)
ref2 = numpy.array(y2)

combined = numpy.concatenate((y, y2))
assert isinstance(combined, delayedarray.SparseNdarray)
assert (numpy.array(combined) == numpy.concatenate((ref, ref2))).all()

# Combining on the last dimension.
test_shape2 = (55, 15)
contents2 = mock_SparseNdarray_contents(test_shape2, lower=-100, upper=100, dtype=numpy.int16)
y2 = delayedarray.SparseNdarray(test_shape2, contents2)
ref2 = numpy.array(y2)

combined = numpy.concatenate((y, y2), axis=1)
assert isinstance(combined, delayedarray.SparseNdarray)
assert (numpy.array(combined) == numpy.concatenate((ref, ref2), axis=1)).all()


def test_SparseNdarray_concatenate_1d():
test_shape = (10,)
contents = mock_SparseNdarray_contents(test_shape, lower=-100, upper=100, dtype=numpy.int16)
Expand Down

0 comments on commit 0b5fdb5

Please sign in to comment.