@@ -355,6 +355,43 @@ cdef class usm_ndarray:
355355 " byte_offset is not a multiple of item_size." )
356356 return byte_offset // item_size
357357
358+ @property
359+ def _element_offset (self ):
360+ """ Returns the offset of the zero-index element of the array, in elements,
361+ relative to the start of memory allocation"""
362+ return self .get_offset()
363+
364+ @property
365+ def _byte_bounds (self ):
366+ """ Returns a 2-tuple with pointers to the end-points of the array"""
367+ cdef Py_ssize_t min_disp = 0
368+ cdef Py_ssize_t max_disp = 0
369+ cdef Py_ssize_t step_ = 0
370+ cdef Py_ssize_t dim_ = 0
371+ cdef int it = 0
372+ cdef Py_ssize_t _itemsize = self .get_itemsize()
373+
374+ if ((self .flags_ & USM_ARRAY_C_CONTIGUOUS) or (self .flags_ & USM_ARRAY_F_CONTIGUOUS)):
375+ return (
376+ self ._pointer,
377+ self ._pointer + shape_to_elem_count(self .nd_, self .shape_) * _itemsize
378+ )
379+
380+ for it in range (self .nd_):
381+ dim_ = self .shape[it]
382+ if dim_ > 0 :
383+ step_ = self .strides[it]
384+ if step_ > 0 :
385+ max_disp += step_ * (dim_ - 1 )
386+ else :
387+ min_disp += step_ * (dim_ - 1 )
388+
389+ return (
390+ self ._pointer + min_disp * _itemsize,
391+ self ._pointer + (max_disp + 1 ) * _itemsize
392+ )
393+
394+
358395 cdef char * get_data(self ):
359396 """ Returns the USM pointer for this array."""
360397 return self .data_
0 commit comments