Skip to content

Commit 5e00ba5

Browse files
committed
Add setitem tests and resolve comments
1 parent 6028669 commit 5e00ba5

4 files changed

Lines changed: 1 addition & 103 deletions

File tree

src/blosc2/lazyexpr.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -46,67 +46,6 @@
4646
import numexpr
4747

4848

49-
# No longer used
50-
# def compute_slice_shape(shape, slice_obj, dont_squeeze=False):
51-
# # Handle None or empty slice case
52-
# if slice_obj is None or slice_obj == ():
53-
# return shape
54-
55-
# # Use ndindex to handle slice calculations
56-
# try:
57-
# idx = ndindex.ndindex(slice_obj).expand(shape)
58-
# return idx.shape
59-
# except Exception:
60-
# # Fall back to manual processing
61-
# if not isinstance(slice_obj, tuple):
62-
# slice_obj = (slice_obj,)
63-
64-
# result = []
65-
# shape_idx = 0
66-
# dims_reduced = 0
67-
68-
# # Process slice components
69-
# for i, s in enumerate(slice_obj):
70-
# if i >= len(shape):
71-
# break
72-
73-
# if isinstance(s, slice):
74-
# start = 0 if s.start is None else max(0, s.start if s.start >= 0 else shape[i] + s.start)
75-
# stop = (
76-
# shape[i]
77-
# if s.stop is None
78-
# else min(shape[i], s.stop if s.stop >= 0 else shape[i] + s.stop)
79-
# )
80-
# step = 1 if s.step is None else abs(s.step)
81-
82-
# if start < stop:
83-
# result.append((stop - start - 1) // step + 1)
84-
# else:
85-
# result.append(0)
86-
# shape_idx += 1
87-
# elif isinstance(s, int) or np.isscalar(s):
88-
# if dont_squeeze:
89-
# result.append(1)
90-
# shape_idx += 1
91-
# else:
92-
# # Integer indexing reduces dimensionality
93-
# dims_reduced += 1
94-
# shape_idx += 1
95-
# continue
96-
# elif s is Ellipsis:
97-
# # Fill in with remaining dimensions
98-
# remaining_dims = len(shape) - (len(slice_obj) - 1 + dims_reduced)
99-
# result.extend(shape[shape_idx : shape_idx + remaining_dims])
100-
# shape_idx += remaining_dims
101-
# continue
102-
103-
# # Add any remaining dimensions
104-
# if shape_idx < len(shape):
105-
# result.extend(shape[shape_idx:])
106-
107-
# return tuple(result)
108-
109-
11049
def ne_evaluate(expression, local_dict=None, **kwargs):
11150
"""Safely evaluate expressions using numexpr when possible, falling back to numpy."""
11251
if local_dict is None:

src/blosc2/ndarray.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,47 +1020,6 @@ def __setitem__(self, key, value):
10201020
super().__setitem__(key, value)
10211021

10221022

1023-
# No longer used
1024-
# def extract_values(arr, indices: np.ndarray[np.int_], max_cache_size: int = 10) -> np.ndarray:
1025-
# """
1026-
# Extract values from a chunked and compressed array using an array of indices.
1027-
1028-
# Parameters
1029-
# ----------
1030-
# arr : blosc2.NDArray
1031-
# The chunked and compressed array.
1032-
# indices : np.ndarray
1033-
# The array of indices to extract values from.
1034-
# max_cache_size : int
1035-
# The maximum number of chunks to cache.
1036-
1037-
# Returns
1038-
# -------
1039-
# extracted_values : np.ndarray
1040-
# The extracted values.
1041-
# """
1042-
# # Initialize the result array
1043-
# extracted_values = np.empty(len(indices), dtype=arr.dtype)
1044-
1045-
# # Limited size dictionary to store decompressed chunks
1046-
# chunk_cache = LimitedSizeDict(max_cache_size)
1047-
1048-
# # Iterate through the indices and extract values
1049-
# chunk_size = int(arr.chunks[0])
1050-
# for i, idx in enumerate(indices):
1051-
# chunk_idx = idx // chunk_size
1052-
# if chunk_idx not in chunk_cache:
1053-
# # Compute the bounds for this chunk
1054-
# start = chunk_idx * chunk_size
1055-
# end = start + chunk_size
1056-
# chunk_cache[chunk_idx] = arr[start:end]
1057-
1058-
# local_idx = idx % chunk_size
1059-
# extracted_values[i] = chunk_cache[chunk_idx][local_idx]
1060-
1061-
# return extracted_values
1062-
1063-
10641023
def detect_aligned_chunks( # noqa: C901
10651024
key: Sequence[slice], shape: Sequence[int], chunks: Sequence[int], consecutive: bool = False
10661025
) -> list[int]:

tests/array-api-xfails.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
array_api_tests/test_array_object.py::test_getitem
21
array_api_tests/test_array_object.py::test_setitem
32
array_api_tests/test_array_object.py::test_getitem_masking

tests/ndarray/test_setitem.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
([12, 13, 14, 15, 16], [5, 5, 5, 5, 5], [2, 2, 2, 2, 2], (slice(1, 9, 2), ..., slice(3, 6)), np.float32),
2020
([12, 13], [5, 5], [2, 2], (slice(11, 2, -1), slice(6, 2, -1)), np.float32),
2121
([25, 13, 22], [5, 5, 3], [2, 2, 1], (slice(17, 2, -3), 0, slice(6, 2, -1)), np.float32),
22+
([25, 13, 22], [5, 5, 3], [2, 2, 1], (np.s_[-5:-15:-1], np.s_[-3:-11:-2], slice(6, 2, -1)), np.float32),
2223
]
2324

2425

0 commit comments

Comments
 (0)