MCPcopy Create free account
hub / github.com/numpy/numpy / offset_bounds_from_strides

Function offset_bounds_from_strides

numpy/core/src/common/mem_overlap.c:659–689  ·  view source on GitHub ↗

Gets a half-open range [start, end) of offsets from the data pointer */

Source from the content-addressed store, hash-verified

657
658/* Gets a half-open range [start, end) of offsets from the data pointer */
659NPY_VISIBILITY_HIDDEN void
660offset_bounds_from_strides(const int itemsize, const int nd,
661 const npy_intp *dims, const npy_intp *strides,
662 npy_intp *lower_offset, npy_intp *upper_offset)
663{
664 npy_intp max_axis_offset;
665 npy_intp lower = 0;
666 npy_intp upper = 0;
667 int i;
668
669 for (i = 0; i < nd; i++) {
670 if (dims[i] == 0) {
671 /* If the array size is zero, return an empty range */
672 *lower_offset = 0;
673 *upper_offset = 0;
674 return;
675 }
676 /* Expand either upwards or downwards depending on stride */
677 max_axis_offset = strides[i] * (dims[i] - 1);
678 if (max_axis_offset > 0) {
679 upper += max_axis_offset;
680 }
681 else {
682 lower += max_axis_offset;
683 }
684 }
685 /* Return a half-open range */
686 upper += itemsize;
687 *lower_offset = lower;
688 *upper_offset = upper;
689}
690
691
692/* Gets a half-open range [start, end) which contains the array data */

Callers 3

array_strides_setFunction · 0.85
PyArray_CheckStridesFunction · 0.85
get_array_memory_extentsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected