Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/3533.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduced the runtime of the test suite by simplifying test cases.
128 changes: 49 additions & 79 deletions tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,21 +601,16 @@ def test_get_orthogonal_selection_1d_bool(store: StorePath) -> None:
# noinspection PyStatementEffect
def test_get_orthogonal_selection_1d_int(store: StorePath) -> None:
# setup
a = np.arange(1050, dtype=int)
a = np.arange(550, dtype=int)
z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,))

np.random.seed(42)
# test with different degrees of sparseness
for p in 2, 0.5, 0.1, 0.01:
# unordered
for p in 0.5, 0.01:
# sorted integer arrays
ix = np.random.choice(a.shape[0], size=int(a.shape[0] * p), replace=True)
_test_get_orthogonal_selection(a, z, ix)
# increasing
ix.sort()
_test_get_orthogonal_selection(a, z, ix)
# decreasing
ix = ix[::-1]
_test_get_orthogonal_selection(a, z, ix)

selections = basic_selections_1d + [
# test wraparound
Expand Down Expand Up @@ -660,12 +655,12 @@ def _test_get_orthogonal_selection_2d(
# noinspection PyStatementEffect
def test_get_orthogonal_selection_2d(store: StorePath) -> None:
# setup
a = np.arange(10000, dtype=int).reshape(1000, 10)
a = np.arange(5400, dtype=int).reshape(600, 9)
z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3))

np.random.seed(42)
# test with different degrees of sparseness
for p in 0.5, 0.1, 0.01:
for p in 0.5, 0.01:
# boolean arrays
ix0 = np.random.binomial(1, p, size=a.shape[0]).astype(bool)
ix1 = np.random.binomial(1, 0.5, size=a.shape[1]).astype(bool)
Expand All @@ -679,16 +674,12 @@ def test_get_orthogonal_selection_2d(store: StorePath) -> None:
for selection in selections:
_test_get_orthogonal_selection(a, z, selection)

# integer arrays
# sorted integer arrays
ix0 = np.random.choice(a.shape[0], size=int(a.shape[0] * p), replace=True)
ix1 = np.random.choice(a.shape[1], size=int(a.shape[1] * 0.5), replace=True)
_test_get_orthogonal_selection_2d(a, z, ix0, ix1)
ix0.sort()
ix1.sort()
_test_get_orthogonal_selection_2d(a, z, ix0, ix1)
ix0 = ix0[::-1]
ix1 = ix1[::-1]
_test_get_orthogonal_selection_2d(a, z, ix0, ix1)

for selection_2d in basic_selections_2d:
_test_get_orthogonal_selection(a, z, selection_2d)
Expand All @@ -709,65 +700,60 @@ def _test_get_orthogonal_selection_3d(
) -> None:
selections = [
# single value
(84, 42, 4),
(60, 15, 4),
(-1, -1, -1),
# index all axes with array
(ix0, ix1, ix2),
# mixed indexing with single array / slices
(ix0, slice(15, 25), slice(1, 5)),
(slice(50, 70), ix1, slice(1, 5)),
(slice(50, 70), slice(15, 25), ix2),
(ix0, slice(15, 25, 5), slice(1, 5, 2)),
(slice(50, 70, 3), ix1, slice(1, 5, 2)),
(slice(50, 70, 3), slice(15, 25, 5), ix2),
(ix0, slice(10, 20), slice(1, 5)),
(slice(30, 50), ix1, slice(1, 5)),
(slice(30, 50), slice(10, 20), ix2),
(ix0, slice(10, 20, 5), slice(1, 5, 2)),
(slice(30, 50, 3), ix1, slice(1, 5, 2)),
(slice(30, 50, 3), slice(10, 20, 5), ix2),
# mixed indexing with single array / ints
(ix0, 42, 4),
(84, ix1, 4),
(84, 42, ix2),
(ix0, 15, 4),
(60, ix1, 4),
(60, 15, ix2),
# mixed indexing with single array / slice / int
(ix0, slice(15, 25), 4),
(42, ix1, slice(1, 5)),
(slice(50, 70), 42, ix2),
(ix0, slice(10, 20), 4),
(15, ix1, slice(1, 5)),
(slice(30, 50), 15, ix2),
# mixed indexing with two array / slice
(ix0, ix1, slice(1, 5)),
(slice(50, 70), ix1, ix2),
(ix0, slice(15, 25), ix2),
(slice(30, 50), ix1, ix2),
(ix0, slice(10, 20), ix2),
# mixed indexing with two array / integer
(ix0, ix1, 4),
(42, ix1, ix2),
(ix0, 42, ix2),
(15, ix1, ix2),
(ix0, 15, ix2),
]
for selection in selections:
_test_get_orthogonal_selection(a, z, selection)


def test_get_orthogonal_selection_3d(store: StorePath) -> None:
# setup
a = np.arange(100000, dtype=int).reshape(200, 50, 10)
a = np.arange(32400, dtype=int).reshape(120, 30, 9)
z = zarr_array_from_numpy_array(store, a, chunk_shape=(60, 20, 3))

np.random.seed(42)
# test with different degrees of sparseness
for p in 0.5, 0.1, 0.01:
for p in 0.5, 0.01:
# boolean arrays
ix0 = np.random.binomial(1, p, size=a.shape[0]).astype(bool)
ix1 = np.random.binomial(1, 0.5, size=a.shape[1]).astype(bool)
ix2 = np.random.binomial(1, 0.5, size=a.shape[2]).astype(bool)
_test_get_orthogonal_selection_3d(a, z, ix0, ix1, ix2)

# integer arrays
# sorted integer arrays
ix0 = np.random.choice(a.shape[0], size=int(a.shape[0] * p), replace=True)
ix1 = np.random.choice(a.shape[1], size=int(a.shape[1] * 0.5), replace=True)
ix2 = np.random.choice(a.shape[2], size=int(a.shape[2] * 0.5), replace=True)
_test_get_orthogonal_selection_3d(a, z, ix0, ix1, ix2)
ix0.sort()
ix1.sort()
ix2.sort()
_test_get_orthogonal_selection_3d(a, z, ix0, ix1, ix2)
ix0 = ix0[::-1]
ix1 = ix1[::-1]
ix2 = ix2[::-1]
_test_get_orthogonal_selection_3d(a, z, ix0, ix1, ix2)


def test_orthogonal_indexing_edge_cases(store: StorePath) -> None:
Expand Down Expand Up @@ -805,24 +791,21 @@ def _test_set_orthogonal_selection(

def test_set_orthogonal_selection_1d(store: StorePath) -> None:
# setup
v = np.arange(1050, dtype=int)
v = np.arange(550, dtype=int)
a = np.empty(v.shape, dtype=int)
z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,))

# test with different degrees of sparseness
np.random.seed(42)
for p in 0.5, 0.1, 0.01:
for p in 0.5, 0.01:
# boolean arrays
ix = np.random.binomial(1, p, size=a.shape[0]).astype(bool)
_test_set_orthogonal_selection(v, a, z, ix)

# integer arrays
# sorted integer arrays
ix = np.random.choice(a.shape[0], size=int(a.shape[0] * p), replace=True)
_test_set_orthogonal_selection(v, a, z, ix)
ix.sort()
_test_set_orthogonal_selection(v, a, z, ix)
ix = ix[::-1]
_test_set_orthogonal_selection(v, a, z, ix)

# basic selections
for selection in basic_selections_1d:
Expand Down Expand Up @@ -870,28 +853,24 @@ def _test_set_orthogonal_selection_2d(

def test_set_orthogonal_selection_2d(store: StorePath) -> None:
# setup
v = np.arange(10000, dtype=int).reshape(1000, 10)
v = np.arange(5400, dtype=int).reshape(600, 9)
a = np.empty_like(v)
z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3))

np.random.seed(42)
# test with different degrees of sparseness
for p in 0.5, 0.1, 0.01:
for p in 0.5, 0.01:
# boolean arrays
ix0 = np.random.binomial(1, p, size=a.shape[0]).astype(bool)
ix1 = np.random.binomial(1, 0.5, size=a.shape[1]).astype(bool)
_test_set_orthogonal_selection_2d(v, a, z, ix0, ix1)

# integer arrays
# sorted integer arrays
ix0 = np.random.choice(a.shape[0], size=int(a.shape[0] * p), replace=True)
ix1 = np.random.choice(a.shape[1], size=int(a.shape[1] * 0.5), replace=True)
_test_set_orthogonal_selection_2d(v, a, z, ix0, ix1)
ix0.sort()
ix1.sort()
_test_set_orthogonal_selection_2d(v, a, z, ix0, ix1)
ix0 = ix0[::-1]
ix1 = ix1[::-1]
_test_set_orthogonal_selection_2d(v, a, z, ix0, ix1)

for selection in basic_selections_2d:
_test_set_orthogonal_selection(v, a, z, selection)
Expand All @@ -907,20 +886,20 @@ def _test_set_orthogonal_selection_3d(
) -> None:
selections = (
# single value
(84, 42, 4),
(60, 15, 4),
(-1, -1, -1),
# index all axes with bool array
(ix0, ix1, ix2),
# mixed indexing with single bool array / slice or int
(ix0, slice(15, 25), slice(1, 5)),
(slice(50, 70), ix1, slice(1, 5)),
(slice(50, 70), slice(15, 25), ix2),
(ix0, 42, 4),
(84, ix1, 4),
(84, 42, ix2),
(ix0, slice(15, 25), 4),
(slice(50, 70), ix1, 4),
(slice(50, 70), 42, ix2),
(ix0, slice(10, 20), slice(1, 5)),
(slice(30, 50), ix1, slice(1, 5)),
(slice(30, 50), slice(10, 20), ix2),
(ix0, 15, 4),
(60, ix1, 4),
(60, 15, ix2),
(ix0, slice(10, 20), 4),
(slice(30, 50), ix1, 4),
(slice(30, 50), 15, ix2),
# indexing with two arrays / slice
(ix0, ix1, slice(1, 5)),
# indexing with two arrays / integer
Expand All @@ -932,37 +911,28 @@ def _test_set_orthogonal_selection_3d(

def test_set_orthogonal_selection_3d(store: StorePath) -> None:
# setup
v = np.arange(100000, dtype=int).reshape(200, 50, 10)
v = np.arange(32400, dtype=int).reshape(120, 30, 9)
a = np.empty_like(v)
z = zarr_array_from_numpy_array(store, a, chunk_shape=(60, 20, 3))

np.random.seed(42)
# test with different degrees of sparseness
for p in 0.5, 0.1, 0.01:
for p in 0.5, 0.01:
# boolean arrays
ix0 = np.random.binomial(1, p, size=a.shape[0]).astype(bool)
ix1 = np.random.binomial(1, 0.5, size=a.shape[1]).astype(bool)
ix2 = np.random.binomial(1, 0.5, size=a.shape[2]).astype(bool)
_test_set_orthogonal_selection_3d(v, a, z, ix0, ix1, ix2)

# integer arrays
# sorted integer arrays
ix0 = np.random.choice(a.shape[0], size=int(a.shape[0] * p), replace=True)
ix1 = np.random.choice(a.shape[1], size=int(a.shape[1] * 0.5), replace=True)
ix2 = np.random.choice(a.shape[2], size=int(a.shape[2] * 0.5), replace=True)
_test_set_orthogonal_selection_3d(v, a, z, ix0, ix1, ix2)

# sorted increasing
ix0.sort()
ix1.sort()
ix2.sort()
_test_set_orthogonal_selection_3d(v, a, z, ix0, ix1, ix2)

# sorted decreasing
ix0 = ix0[::-1]
ix1 = ix1[::-1]
ix2 = ix2[::-1]
_test_set_orthogonal_selection_3d(v, a, z, ix0, ix1, ix2)


def test_orthogonal_indexing_fallback_on_get_setitem(store: StorePath) -> None:
z = zarr_array_from_numpy_array(store, np.zeros((20, 20)))
Expand Down Expand Up @@ -1128,13 +1098,13 @@ def _test_set_coordinate_selection(

def test_set_coordinate_selection_1d(store: StorePath) -> None:
# setup
v = np.arange(1050, dtype=int)
v = np.arange(550, dtype=int)
a = np.empty(v.shape, dtype=v.dtype)
z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,))

np.random.seed(42)
# test with different degrees of sparseness
for p in 2, 0.5, 0.1, 0.01:
for p in 0.5, 0.01:
n = int(a.size * p)
ix = np.random.choice(a.shape[0], size=n, replace=True)
_test_set_coordinate_selection(v, a, z, ix)
Expand All @@ -1152,13 +1122,13 @@ def test_set_coordinate_selection_1d(store: StorePath) -> None:

def test_set_coordinate_selection_2d(store: StorePath) -> None:
# setup
v = np.arange(10000, dtype=int).reshape(1000, 10)
v = np.arange(5400, dtype=int).reshape(600, 9)
a = np.empty_like(v)
z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3))

np.random.seed(42)
# test with different degrees of sparseness
for p in 2, 0.5, 0.1, 0.01:
for p in 0.5, 0.01:
n = int(a.size * p)
ix0 = np.random.choice(a.shape[0], size=n, replace=True)
ix1 = np.random.choice(a.shape[1], size=n, replace=True)
Expand Down