Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Removed `numpy-base` dependency and `USE_NUMPY_BASE` environment variable from conda recipe [gh-124](https://github.com/IntelPython/mkl_random/pull/124)

### Fixed
* Fixed compatibility with NumPy 2.5 by replacing the deprecated in-place array `shape` assignment with `reshape`, and by replacing the deprecated `numpy.testing.suppress_warnings` usage in tests with `pytest.warns` [gh-137](https://github.com/IntelPython/mkl_random/pull/137)

## [1.4.1] (05/11/2026)

Expand Down
26 changes: 15 additions & 11 deletions mkl_random/mklrand.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ cdef object vec_cont1_array(
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
for i from 0 <= i < multi_nd:
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
multi_ndim = len(multi_shape)
arr_obj = arr_obj.transpose(
tuple(range(multi_ndim, arr_obj.ndim))
Expand Down Expand Up @@ -688,7 +688,7 @@ cdef object vec_cont2_array(
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
for i from 0 <= i < multi_nd:
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
multi_ndim = len(multi_shape)
arr_obj = arr_obj.transpose(
tuple(range(multi_ndim, arr_obj.ndim))
Expand Down Expand Up @@ -800,7 +800,7 @@ cdef object vec_cont3_array(
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
for i from 0 <= i < multi_nd:
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
multi_ndim = len(multi_shape)
arr_obj = arr_obj.transpose(
tuple(range(multi_ndim, arr_obj.ndim))
Expand Down Expand Up @@ -920,7 +920,7 @@ cdef object vec_discnp_array(
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
for i from 0 <= i < multi_nd:
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
multi_ndim = len(multi_shape)
arr_obj = arr_obj.transpose(
tuple(range(multi_ndim, arr_obj.ndim))
Expand Down Expand Up @@ -1019,7 +1019,7 @@ cdef object vec_discdd_array(
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
for i from 0 <= i < multi_nd:
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
multi_ndim = len(multi_shape)
arr_obj = arr_obj.transpose(
tuple(range(multi_ndim, arr_obj.ndim))
Expand Down Expand Up @@ -1137,7 +1137,7 @@ cdef object vec_discnmN_array(
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
for i from 0 <= i < multi_nd:
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
multi_ndim = len(multi_shape)
arr_obj = arr_obj.transpose(
tuple(range(multi_ndim, arr_obj.ndim))
Expand Down Expand Up @@ -1243,7 +1243,9 @@ cdef object vec_discd_array(
func(state, n, array_data + n*i, oa_data[0])
cnp.PyArray_MultiIter_NEXTi(multi, 1)
arr_obj = <object>array
arr_obj.shape = ((<object>oa).shape + arr_obj.shape)[:arr_obj.ndim]
arr_obj = arr_obj.reshape(
((<object>oa).shape + arr_obj.shape)[:arr_obj.ndim]
)
arr_obj = arr_obj.transpose(
tuple(range(oa.ndim, arr_obj.ndim))
+ tuple(range(0, oa.ndim))
Expand Down Expand Up @@ -1302,7 +1304,9 @@ cdef object vec_long_discd_array(
func(state, n, array_data + n*i, oa_data[0])
cnp.PyArray_MultiIter_NEXTi(multi, 1)
arr_obj = <object>array
arr_obj.shape = ((<object> oa).shape + arr_obj.shape)[:arr_obj.ndim]
arr_obj = arr_obj.reshape(
((<object> oa).shape + arr_obj.shape)[:arr_obj.ndim]
)
arr_obj = arr_obj.transpose(
tuple(range(oa.ndim, arr_obj.ndim))
+ tuple(range(0, oa.ndim))
Expand Down Expand Up @@ -1355,9 +1359,9 @@ cdef object vec_Poisson_array(
func2(state, n, array_data + n*i, oa_data[0])
cnp.PyArray_MultiIter_NEXTi(multi, 1)
arr_obj = <object>array
arr_obj.shape = (
arr_obj = arr_obj.reshape((
(<object>olambda).shape + arr_obj.shape
)[:arr_obj.ndim]
)[:arr_obj.ndim])
arr_obj = arr_obj.transpose(
tuple(range(olambda.ndim, arr_obj.ndim))
+ tuple(range(0, olambda.ndim))
Expand Down Expand Up @@ -6222,7 +6226,7 @@ cdef class _MKLRandomState:

x = np.dot(x, np.sqrt(s)[:, None] * v)
x += mean
x.shape = tuple(final_shape)
x = x.reshape(tuple(final_shape))
return x

def multinomial(self, int n, object pvals, size=None):
Expand Down
9 changes: 2 additions & 7 deletions mkl_random/tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
assert_equal,
assert_no_warnings,
assert_raises,
suppress_warnings,
)

import mkl_random as rnd
Expand Down Expand Up @@ -386,10 +385,8 @@ def test_randomdist_randint(randomdist):

def test_randomdist_random_integers(randomdist):
rnd.seed(randomdist.seed, brng=randomdist.brng)
with suppress_warnings() as sup:
w = sup.record(DeprecationWarning)
with pytest.warns(DeprecationWarning):
actual = rnd.random_integers(-99, 99, size=(3, 2))
assert len(w) == 1

desired = np.array([[96, -96], [-64, 42], [4, 97]])
np.testing.assert_array_equal(actual, desired)
Expand All @@ -401,10 +398,8 @@ def test_random_integers_max_int():
# into a C long. Previous implementations of this
# method have thrown an OverflowError when attempting
# to generate this integer.
with suppress_warnings() as sup:
w = sup.record(DeprecationWarning)
with pytest.warns(DeprecationWarning):
actual = rnd.random_integers(np.iinfo("l").max, np.iinfo("l").max)
assert len(w) == 1
desired = np.iinfo("l").max
np.testing.assert_equal(actual, desired)

Expand Down
Loading