@@ -503,8 +503,8 @@ cdef extern from "b2nd.h":
503503 int b2nd_to_cframe(const b2nd_array_t * array, uint8_t ** cframe, int64_t * cframe_len,
504504 c_bool * needs_free);
505505
506- int b2nd_squeeze(b2nd_array_t * array)
507- int b2nd_squeeze_index(b2nd_array_t * array, const c_bool * index)
506+ int b2nd_squeeze(b2nd_array_t * array, b2nd_array_t ** view )
507+ int b2nd_squeeze_index(b2nd_array_t * array, b2nd_array_t ** view, const c_bool * index)
508508 int b2nd_resize(b2nd_array_t * array, const int64_t * new_shape, const int64_t * start)
509509 int b2nd_copy(b2nd_context_t * ctx, b2nd_array_t * src, b2nd_array_t ** array)
510510 int b2nd_concatenate(b2nd_context_t * ctx, b2nd_array_t * src1, b2nd_array_t * src2,
@@ -2530,7 +2530,7 @@ cdef class NDArray:
25302530 cdef c_bool mask_[B2ND_MAX_DIM]
25312531 for i in range (ndim):
25322532 mask_[i] = mask[i]
2533- _check_rc(b2nd_squeeze_index(array, mask_), " Error while squeezing sliced array" )
2533+ _check_rc(b2nd_squeeze_index(array, & array, mask_), " Error while squeezing sliced array" )
25342534 ndarray = blosc2.NDArray(_schunk = PyCapsule_New(array.sc, < char * > " blosc2_schunk*" , NULL ),
25352535 _array = PyCapsule_New(array, < char * > " b2nd_array_t*" , NULL ))
25362536
@@ -2604,19 +2604,6 @@ cdef class NDArray:
26042604 _check_rc(b2nd_resize(self .array, new_shape_, NULL ),
26052605 " Error while resizing the array" )
26062606
2607- def squeeze (self , mask = None ):
2608- cdef c_bool mask_[B2ND_MAX_DIM]
2609- if mask is None :
2610- _check_rc(b2nd_squeeze(self .array), " Error while performing the squeeze" )
2611- else :
2612- for i in range (self .ndim):
2613- mask_[i] = mask[i]
2614- _check_rc(b2nd_squeeze_index(self .array, mask_), " Error while squeezing array" )
2615-
2616- # this squeezes even if not asked for by mask - may have to use in future though
2617- # if self.array.shape[0] == 1 and self.ndim == 1:
2618- # self.array.ndim = 0
2619-
26202607 def as_ffi_ptr (self ):
26212608 return PyCapsule_New(self .array, < char * > " b2nd_array_t*" , NULL )
26222609
@@ -3001,3 +2988,22 @@ def expand_dims(arr1: NDArray, axis_mask: list[bool], final_dims: int) -> blosc2
30012988 new_base = arr1 if arr1.base is None else arr1.base
30022989 return blosc2.NDArray(_schunk = PyCapsule_New(view.sc, < char * > " blosc2_schunk*" , NULL ),
30032990 _array = PyCapsule_New(view, < char * > " b2nd_array_t*" , NULL ), _base = new_base)
2991+
2992+ def squeeze (arr1: NDArray , axis_mask: list[bool]) -> blosc2.NDArray:
2993+ """
2994+ Remove axis from NDArray object at specified dimensions.
2995+ """
2996+ cdef b2nd_array_t *view
2997+ cdef c_bool mask_[B2ND_MAX_DIM]
2998+ for i in range(arr1.ndim ):
2999+ mask_[i] = axis_mask[i]
3000+ _check_rc(b2nd_squeeze_index(arr1.array, & view, mask_), " Error while squeezing array" )
3001+
3002+ # this squeezes even if not asked for by mask - may have to use in future though
3003+ # if arr1.array.shape[0] == 1 and arr1.ndim == 1:
3004+ # arr1.array.ndim = 0
3005+
3006+ # create view with reference to self to hold onto
3007+ new_base = arr1 if arr1.base is None else arr1.base
3008+ return blosc2.NDArray(_schunk = PyCapsule_New(view.sc, < char * > " blosc2_schunk*" , NULL ),
3009+ _array = PyCapsule_New(view, < char * > " b2nd_array_t*" , NULL ), _base = new_base)
0 commit comments