Skip to content

Commit

Permalink
only use c-contiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
normanrz committed Nov 26, 2024
1 parent ac61fae commit 5625e94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/zarr/codecs/_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING

import numcodecs
import numpy as np
from numcodecs.compat import ensure_ndarray_like

from zarr.abc.codec import ArrayBytesCodec
Expand All @@ -19,10 +20,10 @@

def ensure_contiguous(arr: NDArrayLike) -> NDArrayLike:
flags = getattr(arr, "flags", None)
if flags is not None and (flags.c_contiguous or flags.f_contiguous):
if flags is not None and flags.c_contiguous:
return arr
else:
return arr.copy()
return np.ascontiguousarray(arr)


@dataclass(frozen=True)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@ def test_v2_non_contiguous() -> None:
arr[slice(6, 9, None), slice(3, 6, None)] = a[
slice(6, 9, None), slice(3, 6, None)
] # The slice on the RHS is important

a = np.ones((3, 3), order="F")
assert a.flags.f_contiguous
arr[slice(6, 9, None), slice(3, 6, None)] = a

a = np.ones((3, 3), order="C")
assert a.flags.c_contiguous
arr[slice(6, 9, None), slice(3, 6, None)] = a

0 comments on commit 5625e94

Please sign in to comment.