8000 MAINT: remove relaxed strides debug build setting by rgommers · Pull Request #24717 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: remove relaxed strides debug build setting #24717

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

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
MAINT: remove relaxed strides debug build setting
This follows up on gh-21039. As noted there, this doesn't really
serve any purpose anymore and historically seems to have resulted in
only 2 bug reports.
  • Loading branch information
rgommers committed Sep 15, 2023
commit 94b9f2a78733d322cea8fd02c76c39beecb11aec
20 changes: 1 addition & 19 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Linux tests
# This file is meant for testing across supported Python versions, build types
# and interpreters (PyPy, python-dbg, a pre-release Python in summer time),
# build-via-sdist, run benchmarks, measure code coverage, and other build
# options like relaxed-strides.
# options.

on:
push:
Expand Down Expand Up @@ -172,24 +172,6 @@ jobs:
run: |
spin bench --quick

relaxed_strides_debug:
needs: [smoke_test]
runs-on: ubuntu-latest
if: github.event_name != 'push'
env:
CHECK_BLAS: 1
NPY_USE_BLAS_ILP64: 1
NPY_RELAXED_STRIDES_DEBUG: 1
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
submodules: recursive
fetch-depth: 0
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: '3.11'
- uses: ./.github/actions

sdist:
needs: [smoke_test]
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions doc/release/upcoming_changes/24717.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The "relaxed strides" debug build option, which was previously enabled through
the ``NPY_RELAXED_STRIDES_DEBUG`` environment variable or the
``-Drelaxed-strides-debug`` config-settings flag, has been removed.
3 changes: 0 additions & 3 deletions doc/source/reference/arrays.ndarray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ base offset itself is a multiple of `self.itemsize`. Understanding
for C-style contiguous arrays or ``self.strides[0] == self.itemsize`` for
Fortran-style contiguous arrays is true.

``NPY_RELAXED_STRIDES_DEBUG=1`` can be used to help find errors when
incorrectly relying on the strides in C-extension code (see below warning).

Data in new :class:`ndarrays <ndarray>` is in the :term:`row-major` (C)
order, unless otherwise specified, but, for example, :ref:`basic
array slicing <arrays.indexing>` often produces :term:`views <view>`
Expand Down
16 changes: 1 addition & 15 deletions doc/source/reference/global_state.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ See :ref:`runtime-simd-dispatch`.
Debugging-related options
=========================

Relaxed strides checking
------------------------

The *compile-time* environment variable::

NPY_RELAXED_STRIDES_DEBUG=0

can be set to help debug code written in C which iterators through arrays
manually. When an array is contiguous and iterated in a contiguous manner,
its ``strides`` should not be queried. This option can help find errors where
the ``strides`` are incorrectly used.
For details see the :ref:`memory layout <memory-layout>` documentation.


Warn if no memory allocation policy when deallocating data
----------------------------------------------------------

Expand All @@ -84,4 +70,4 @@ be emitted. A better alternative is to use a ``PyCapsule`` with a deallocator
and set the ``ndarray.base``.

.. versionchanged:: 1.25.2
This variable is only checked on the first import.
This variable is only checked on the first import.
2 changes: 0 additions & 2 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ option('test-simd', type: 'array',
description: 'Specify a list of CPU features to be tested against NumPy SIMD interface')
option('test-simd-args', type: 'string', value: '',
description: 'Extra args to be passed to the `_simd` module that is used for testing the NumPy SIMD interface')
option('relaxed-strides-debug', type: 'boolean', value: false,
description: 'Enable relaxed strides debug mode (see `NPY_RELAXED_STRIDES_DEBUG` docs)')
2 changes: 0 additions & 2 deletions numpy/_pytesttester.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def _show_numpy_info():
import numpy as np

print("NumPy version %s" % np.__version__)
relaxed_strides = np.ones((10, 1), order="C").flags.f_contiguous
print("NumPy relaxed strides checking option:", relaxed_strides)
info = np.lib._utils_impl._opt_info()
print("NumPy CPU features: ", (info if info else 'nothing enabled'))

Expand Down
1 change: 0 additions & 1 deletion numpy/core/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
#mesondefine HAVE_CTANHL

#mesondefine NPY_CAN_LINK_SVML
#mesondefine NPY_RELAXED_STRIDES_DEBUG

#mesondefine HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE
#mesondefine HAVE_LDOUBLE_INTEL_EXTENDED_12_BYTES_LE
Expand Down
4 changes: 0 additions & 4 deletions numpy/core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,6 @@ endif
# TODO: document this (search for NPY_NOSMP in C API docs)
cdata.set10('NPY_NO_SMP', get_option('disable-threading'))

# Use bogus stride debug aid to flush out bugs where users use strides of
# dimensions with length 1 to index a full contiguous array.
cdata.set10('NPY_RELAXED_STRIDES_DEBUG', get_option('relaxed-strides-debug'))

# Check whether we can use inttypes (C99) formats
if cc.has_header_symbol('inttypes.h', 'PRIdPTR')
cdata.set10('NPY_USE_C99_FORMATS', true)
Expand Down
6 changes: 2 additions & 4 deletions numpy/core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,8 @@ def isfortran(a):
"""
Check if the array is Fortran contiguous but *not* C contiguous.

This function is obsolete and, because of changes due to relaxed stride
checking, its return value for the same array may differ for versions
of NumPy >= 1.10.0 and previous versions. If you only want to check if an
array is Fortran contiguous use ``a.flags.f_contiguous`` instead.
This function is obsolete. If you only want to check if an array is Fortran
contiguous use ``a.flags.f_contiguous`` instead.

Parameters
----------
Expand Down
17 changes: 2 additions & 15 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -3971,10 +3971,9 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, npy_intp count)
}
((PyArrayObject_fields *)ret)->data = new_data;

if (count < 0 || NPY_RELAXED_STRIDES_DEBUG) {
if (count < 0) {
/*
* If the count was smaller than zero or NPY_RELAXED_STRIDES_DEBUG
* was active, the strides may be all 0 or intentionally mangled
* If the count was smaller than zero, the strides may be all 0
* (even in the later dimensions for `count < 0`!
* Thus, fix all strides here again for C-contiguity.
*/
Expand Down Expand Up @@ -4047,12 +4046,6 @@ _array_fill_strides(npy_intp *strides, npy_intp const *dims, int nd, size_t item
else {
not_cf_contig = 0;
}
#if NPY_RELAXED_STRIDES_DEBUG
/* For testing purpose only */
if (dims[i] == 1) {
strides[i] = NPY_MAX_INTP;
}
#endif /* NPY_RELAXED_STRIDES_DEBUG */
}
if (not_cf_contig) {
*objflags = ((*objflags)|NPY_ARRAY_F_CONTIGUOUS) &
Expand All @@ -4071,12 +4064,6 @@ _array_fill_strides(npy_intp *strides, npy_intp const *dims, int nd, size_t item
else {
not_cf_contig = 0;
}
#if NPY_RELAXED_STRIDES_DEBUG
/* For testing purpose only */
if (dims[i] == 1) {
strides[i] = NPY_MAX_INTP;
}
#endif /* NPY_RELAXED_STRIDES_DEBUG */
}
if (not_cf_contig) {
*objflags = ((*objflags)|NPY_ARRAY_C_CONTIGUOUS) &
Expand Down
7 changes: 1 addition & 6 deletions numpy/core/src/multiarray/textreading/rows.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,7 @@ read_rows(stream *s,
*/
data_array = (PyArrayObject *)PyArray_SimpleNewFromDescr(
ndim, result_shape, out_descr);
#ifdef NPY_RELAXED_STRIDES_DEBUG
/* Incompatible with NPY_RELAXED_STRIDES_DEBUG due to growing */
if (result_shape[0] == 1) {
PyArray_STRIDES(data_array)[0] = row_size;
}
#endif /* NPY_RELAXED_STRIDES_DEBUG */

if (data_array == NULL) {
goto error;
}
Expand Down
25 changes: 1 addition & 24 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3520,8 +3520,6 @@ def test_ravel(self):
# 1-element tidy strides test:
a = np.array([[1]])
a.strides = (123, 432)
# If the following stride is not 8, NPY_RELAXED_STRIDES_DEBUG is
# messing them up on purpose:
if np.ones(1).strides == (8,):
assert_(np.may_share_memory(a.ravel('K'), a))
assert_equal(a.ravel('K').strides, (a.dtype.itemsize,))
Expand Down Expand Up @@ -8032,9 +8030,7 @@ def test_export_record(self):
assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:q:dx:B:e:@H:f:=I:g:L:h:Q:hx:f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
else:
assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:q:dx:B:e:@H:f:=I:g:Q:h:Q:hx:f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
# Cannot test if NPY_RELAXED_STRIDES_DEBUG changes the strides
if not (np.ones(1).strides[0] == np.iinfo(np.intp).max):
assert_equal(y.strides, (sz,))
assert_equal(y.strides, (sz,))
assert_equal(y.itemsize, sz)

def test_export_subarray(self):
Expand Down Expand Up @@ -8143,23 +8139,6 @@ def test_relaxed_strides(self, c=np.ones((1, 10, 10), dtype='i8')):
arr, ['C_CONTIGUOUS'])
assert_(strides[-1] == 8)

@pytest.mark.valgrind_error(reason="leaks buffer info cache temporarily.")
@pytest.mark.skipif(not np.ones((10, 1), order="C").flags.f_contiguous,
reason="Test is unnecessary (but fails) without relaxed strides.")
def test_relaxed_strides_buffer_info_leak(self, arr=np.ones((1, 10))):
"""Test that alternating export of C- and F-order buffers from
an array which is both C- and F-order when relaxed strides is
active works.
This test defines array in the signature to ensure leaking more
references every time the test is run (catching the leak with
pytest-leaks).
"""
for i in range(10):
_, s = _multiarray_tests.get_buffer_info(arr, ['F_CONTIGUOUS'])
assert s == (8, 8)
_, s = _multiarray_tests.get_buffer_info(arr, ['C_CONTIGUOUS'])
assert s == (80, 8)

def test_out_of_order_fields(self):
dt = np.dtype(dict(
formats=['<i4', '<i4'],
Expand Down Expand Up @@ -9788,8 +9767,6 @@ def test_uintalignment_and_alignment():
class TestAlignment:
# adapted from scipy._lib.tests.test__util.test__aligned_zeros
# Checks that unusual memory alignments don't trip up numpy.
# In particular, check RELAXED_STRIDES don't trip alignment assertions in
# NDEBUG mode for size-0 arrays (gh-12503)

def check(self, shape, dtype, order, align):
err_msg = repr((shape, dtype, order, align))
Expand Down
15 changes: 0 additions & 15 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,6 @@ def test_reshape_zero_size(self):
a = np.ones((0, 2))
a.shape = (-1, 2)

# Cannot test if NPY_RELAXED_STRIDES_DEBUG changes the strides.
# With NPY_RELAXED_STRIDES_DEBUG the test becomes superfluous.
@pytest.mark.skipif(np.ones(1).strides[0] == np.iinfo(np.intp).max,
reason="Using relaxed stride debug")
def test_reshape_trailing_ones_strides(self):
# GitHub issue gh-2949, bad strides for trailing ones of new shape
a = np.zeros(12, dtype=np.int32)[::2] # not contiguous
Expand Down Expand Up @@ -904,17 +900,6 @@ def test_copy_detection_corner_case(self):
# Ticket #658
np.indices((0, 3, 4)).T.reshape(-1, 3)

# Cannot test if NPY_RELAXED_STRIDES_DEBUG changes the strides.
# With NPY_RELAXED_STRIDES_DEBUG the test becomes superfluous,
# 0-sized reshape itself is tested elsewhere.
@pytest.mark.skipif(np.ones(1).strides[0] == np.iinfo(np.intp).max,
reason="Using relaxed stride debug")
def test_copy_detection_corner_case2(self):
# Ticket #771: strides are not set correctly when reshaping 0-sized
# arrays
b = np.indices((0, 3, 4)).T.reshape(-1, 3)
assert_equal(b.strides, (3 * b.itemsize, b.itemsize))

def test_object_array_refcounting(self):
# Ticket #633
if not hasattr(sys, 'getrefcount'):
Expand Down
0