Skip to content

Commit

Permalink
Merge pull request #15 from scalableminds/fix-transpose-codec-non-sel…
Browse files Browse the repository at this point in the history
…f-inverse-order

Fix transpose codec non self inverse order
  • Loading branch information
normanrz authored Jun 4, 2024
2 parents 7de598f + 46e8722 commit 360a981
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 17 additions & 0 deletions tests/test_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,23 @@ async def test_transpose(
)


@pytest.mark.parametrize("order", [[1, 2, 0], [1, 2, 3, 0], [3, 2, 4, 0, 1]])
def test_transpose_non_self_inverse(store: Store, order):
shape = [i + 3 for i in range(len(order))]
data = np.arange(0, np.prod(shape), dtype="uint16").reshape(shape)
a = Array.create(
store / "transpose_non_self_inverse",
shape=data.shape,
chunk_shape=data.shape,
dtype=data.dtype,
fill_value=0,
codecs=[codecs.transpose_codec(order), codecs.bytes_codec()],
)
a[:, :] = data
read_data = a[:, :]
assert np.array_equal(data, read_data)


def test_transpose_invalid(
store: Store,
):
Expand Down
4 changes: 1 addition & 3 deletions zarrita/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,7 @@ async def decode(
self,
chunk_array: np.ndarray,
) -> np.ndarray:
inverse_order = [0 for _ in range(self.array_metadata.ndim)]
for x, i in enumerate(self.order):
inverse_order[x] = i
inverse_order = np.argsort(self.order)
chunk_array = chunk_array.transpose(inverse_order)
return chunk_array

Expand Down

0 comments on commit 360a981

Please sign in to comment.