-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
MAINT: Remove the RELAXED_STRIDES_CHECKING env variable #21039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``NPY_RELAXED_STRIDES_CHECKING`` has been removed | ||
------------------------------------------------- | ||
NumPy cannot be compiled with ``NPY_RELAXED_STRIDES_CHECKING=0`` | ||
anymore. Relaxed strides have been the default for many years and | ||
the option was initially introduced to allow a smoother transition. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -834,11 +834,9 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); | |
* 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS. Arrays with | ||
* more then one dimension can be C_CONTIGUOUS and F_CONTIGUOUS | ||
* at the same time if they have either zero or one element. | ||
* If NPY_RELAXED_STRIDES_CHECKING is set, a higher dimensional | ||
* array is always C_CONTIGUOUS and F_CONTIGUOUS if it has zero elements | ||
* and the array is contiguous if ndarray.squeeze() is contiguous. | ||
* I.e. dimensions for which `ndarray.shape[dimension] == 1` are | ||
* ignored. | ||
* A higher dimensional array is always C_CONTIGUOUS and F_CONTIGUOUS if it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "or" instead of "and"? This make is sound like the array is both, which is probably true for empty arrays, but squeezed arrays might be one of the other. Maybe rewrite? |
||
* has zero elements or when `array.squeeze()` is contiguous. | ||
* I.e. dimensions for which `array.shape[dimension] == 1` are ignored. | ||
*/ | ||
|
||
/* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,20 +105,11 @@ PyArray_UpdateFlags(PyArrayObject *ret, int flagmask) | |
* | ||
* According to these rules, a 0- or 1-dimensional array is either both | ||
* C- and F-contiguous, or neither; and an array with 2+ dimensions | ||
* can be C- or F- contiguous, or neither, but not both. Though there | ||
* there are exceptions for arrays with zero or one item, in the first | ||
* case the check is relaxed up to and including the first dimension | ||
* with shape[i] == 0. In the second case `strides == itemsize` will | ||
* can be true for all dimensions and both flags are set. | ||
* | ||
* When NPY_RELAXED_STRIDES_CHECKING is set, we use a more accurate | ||
* definition of C- and F-contiguity, in which all 0-sized arrays are | ||
* contiguous (regardless of dimensionality), and if shape[i] == 1 | ||
* then we ignore strides[i] (since it has no affect on memory layout). | ||
* With these new rules, it is possible for e.g. a 10x1 array to be both | ||
* C- and F-contiguous -- but, they break downstream code which assumes | ||
* that for contiguous arrays strides[-1] (resp. strides[0]) always | ||
* contains the itemsize. | ||
* can be C- or F- contiguous, or neither, but not both (unless it has only | ||
* a single element). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not true, Maybe "one dimensional and contiguous"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is true based on the simplified (old) rules that are given above? |
||
* We correct this, however. When a dimension has length 1, its stride is | ||
* never used and thus has no effect on the memory layout. | ||
* The above rules thus only apply when ignorning all size 1 dimenions. | ||
*/ | ||
static void | ||
_UpdateContiguousFlags(PyArrayObject *ap) | ||
|
@@ -131,7 +122,6 @@ _UpdateContiguousFlags(PyArrayObject *ap) | |
sd = PyArray_ITEMSIZE(ap); | ||
for (i = PyArray_NDIM(ap) - 1; i >= 0; --i) { | ||
dim = PyArray_DIMS(ap)[i]; | ||
#if NPY_RELAXED_STRIDES_CHECKING | ||
/* contiguous by definition */ | ||
if (dim == 0) { | ||
PyArray_ENABLEFLAGS(ap, NPY_ARRAY_C_CONTIGUOUS); | ||
|
@@ -144,17 +134,6 @@ _UpdateContiguousFlags(PyArrayObject *ap) | |
} | ||
sd *= dim; | ||
} | ||
#else /* not NPY_RELAXED_STRIDES_CHECKING */ | ||
if (PyArray_STRIDES(ap)[i] != sd) { | ||
is_c_contig = 0; | ||
break; | ||
} | ||
/* contiguous, if it got this far */ | ||
if (dim == 0) { | ||
break; | ||
} | ||
sd *= dim; | ||
#endif /* not NPY_RELAXED_STRIDES_CHECKING */ | ||
} | ||
if (is_c_contig) { | ||
PyArray_ENABLEFLAGS(ap, NPY_ARRAY_C_CONTIGUOUS); | ||
|
@@ -167,24 +146,13 @@ _UpdateContiguousFlags(PyArrayObject *ap) | |
sd = PyArray_ITEMSIZE(ap); | ||
for (i = 0; i < PyArray_NDIM(ap); ++i) { | ||
dim = PyArray_DIMS(ap)[i]; | ||
#if NPY_RELAXED_STRIDES_CHECKING | ||
if (dim != 1) { | ||
if (PyArray_STRIDES(ap)[i] != sd) { | ||
PyArray_CLEARFLAGS(ap, NPY_ARRAY_F_CONTIGUOUS); | ||
return; | ||
} | ||
sd *= dim; | ||
} | ||
#else /* not NPY_RELAXED_STRIDES_CHECKING */ | ||
if (PyArray_STRIDES(ap)[i] != sd) { | ||
PyArray_CLEARFLAGS(ap, NPY_ARRAY_F_CONTIGUOUS); | ||
return; | ||
} | ||
if (dim == 0) { | ||
break; | ||
} | ||
sd *= dim; | ||
#endif /* not NPY_RELAXED_STRIDES_CHECKING */ | ||
} | ||
PyArray_ENABLEFLAGS(ap, NPY_ARRAY_F_CONTIGUOUS); | ||
return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1533,8 +1533,9 @@ PyArray_EquivTypenums(int typenum1, int typenum2) | |
|
||
/*** END C-API FUNCTIONS **/ | ||
/* | ||
* NPY_RELAXED_STRIDES_CHECKING: If the strides logic is changed, the | ||
* order specific stride setting is not necessary. | ||
* NOTE: The order specific stride setting is not necessary to preserve | ||
* contiguity and could be removed. However, this way the resulting | ||
* strides do currently look clearer for fortran order inputs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "strides look better for . . ."? |
||
*/ | ||
static NPY_STEALS_REF_TO_ARG(1) PyObject * | ||
_prepend_ones(PyArrayObject *arr, int nd, int ndmin, NPY_ORDER order) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,11 +244,9 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, | |
* in order to get the right orientation and | ||
* because we can't just re-use the buffer with the | ||
* data in the order it is in. | ||
* NPY_RELAXED_STRIDES_CHECKING: size check is unnecessary when set. | ||
*/ | ||
Py_INCREF(self); | ||
if ((PyArray_SIZE(self) > 1) && | ||
((order == NPY_CORDER && !PyArray_IS_C_CONTIGUOUS(self)) || | ||
if (((order == NPY_CORDER && !PyArray_IS_C_CONTIGUOUS(self)) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just check if this is correct. |
||
(order == NPY_FORTRANORDER && !PyArray_IS_F_CONTIGUOUS(self)))) { | ||
int success = 0; | ||
success = _attempt_nocopy_reshape(self, ndim, dimensions, | ||
|
@@ -1000,7 +998,6 @@ PyArray_Flatten(PyArrayObject *a, NPY_ORDER order) | |
* If an axis flagged for removal has a shape larger than one, | ||
* the aligned flag (and in the future the contiguous flags), | ||
* may need explicit update. | ||
* (check also NPY_RELAXED_STRIDES_CHECKING) | ||
* | ||
* For example, this can be used to remove the reduction axes | ||
* from a reduction result once its computation is complete. | ||
|
@@ -1024,6 +1021,6 @@ PyArray_RemoveAxesInPlace(PyArrayObject *arr, const npy_bool *flags) | |
/* The final number of dimensions */ | ||
fa->nd = idim_out; | ||
|
||
/* May not be necessary for NPY_RELAXED_STRIDES_CHECKING (see comment) */ | ||
/* NOTE: This is only necessary if a dimension with size != 1 was removed */ | ||
PyArray_UpdateFlags(arr, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to move this to the other one (so use_wheel is just that and nothing else) and rename that one.