From 9700c0c2bef5b9031fe02bdcdd12cf7397efcc90 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 31 Aug 2026 09:37:36 -0700 Subject: [PATCH 1/6] Fix unreachable scalar fast-path in uniform --- mkl_random/mklrand.pyx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mkl_random/mklrand.pyx b/mkl_random/mklrand.pyx index edbcd400..19ec98b6 100644 --- a/mkl_random/mklrand.pyx +++ b/mkl_random/mklrand.pyx @@ -2534,14 +2534,14 @@ cdef class _MKLRandomState: if flow >= fhigh: raise ValueError("low >= high") - return vec_cont2_array_sc( - self.internal_state, - irk_uniform_vec, - size, - flow, - fhigh, - self.lock - ) + return vec_cont2_array_sc( + self.internal_state, + irk_uniform_vec, + size, + flow, + fhigh, + self.lock + ) if not np.all(np.isfinite(olow)) or not np.all(np.isfinite(ohigh)): raise OverflowError("Range exceeds valid bounds") From 9506dd251ab3df68feeb070c042bfe754d515107 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 31 Aug 2026 09:37:58 -0700 Subject: [PATCH 2/6] Add test_uniform_return_type --- mkl_random/tests/test_random.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mkl_random/tests/test_random.py b/mkl_random/tests/test_random.py index 4e74d769..40de569a 100644 --- a/mkl_random/tests/test_random.py +++ b/mkl_random/tests/test_random.py @@ -1142,6 +1142,17 @@ def test_uniform_range_bounds(): rnd.uniform(low=fmin, high=fmax / 1e17) +def test_uniform_return_type(): + val = rnd.uniform(0.0, 1.0) + assert np.isscalar(val), f"expected a scalar, got {type(val)}" + assert isinstance(val, float) + assert 0.0 <= val < 1.0 + + arr = rnd.uniform([0.0, 10.0], [1.0, 11.0]) + assert isinstance(arr, np.ndarray) + assert arr.shape == (2,) + + def test_randomdist_vonmises(randomdist): rnd.seed(randomdist.seed, brng=randomdist.brng) actual = rnd.vonmises(mu=1.23, kappa=1.54, size=(3, 2)) From 8e799daebba181a6e974eab5eaed4856020cdc16 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 31 Aug 2026 09:46:02 -0700 Subject: [PATCH 3/6] Add gh-167 to changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eff67b71..b06ceb3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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) * Fixed a constant integer overflow in `irk_rand_uint32_vec` by declaring the `shift` variable as `npy_uint32` instead of `npy_int32`, so `2**31` no longer overflows a signed 32-bit integer (behavior is unchanged as all downstream uses rely on modulo-2^32 arithmetic) [gh-156](https://github.com/IntelPython/mkl_random/pull/156) +* Fixed `uniform` to return a Python `float` for scalar bounds with `size=None` instead of a 0-d array [gh-167](https://github.com/IntelPython/mkl_random/pull/167) + ## [1.4.1] (05/11/2026) From ad8bcc61d703a4f67e00757de0b488655cf1b53a Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 1 Sep 2026 02:24:53 -0700 Subject: [PATCH 4/6] Add scalar return type in uniform docstring --- mkl_random/mklrand.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkl_random/mklrand.pyx b/mkl_random/mklrand.pyx index 19ec98b6..373d16e4 100644 --- a/mkl_random/mklrand.pyx +++ b/mkl_random/mklrand.pyx @@ -2471,7 +2471,7 @@ cdef class _MKLRandomState: Returns ------- - out : ndarray + out : ndarray or scalar Drawn samples, with shape `size`. See Also From 34dfa04a33ac03a2e4d929ef7e31a2caa4ff1e80 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 1 Sep 2026 02:25:49 -0700 Subject: [PATCH 5/6] Update changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b06ceb3c..7319acd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed ### Fixed +* Fixed `uniform` to return a Python `float` for scalar bounds with `size=None` instead of a 0-d array [gh-167](https://github.com/IntelPython/mkl_random/pull/167) ## [1.5.0] (08/12/2026) @@ -24,8 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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) * Fixed a constant integer overflow in `irk_rand_uint32_vec` by declaring the `shift` variable as `npy_uint32` instead of `npy_int32`, so `2**31` no longer overflows a signed 32-bit integer (behavior is unchanged as all downstream uses rely on modulo-2^32 arithmetic) [gh-156](https://github.com/IntelPython/mkl_random/pull/156) -* Fixed `uniform` to return a Python `float` for scalar bounds with `size=None` instead of a 0-d array [gh-167](https://github.com/IntelPython/mkl_random/pull/167) - ## [1.4.1] (05/11/2026) From d8ad010eb03b5ce018a10c95c70a218e3ad1b1c3 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 1 Sep 2026 02:28:56 -0700 Subject: [PATCH 6/6] Extend test_uniform_return_type to cover numpy-scalar --- mkl_random/tests/test_random.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mkl_random/tests/test_random.py b/mkl_random/tests/test_random.py index 40de569a..671dcd56 100644 --- a/mkl_random/tests/test_random.py +++ b/mkl_random/tests/test_random.py @@ -1142,12 +1142,22 @@ def test_uniform_range_bounds(): rnd.uniform(low=fmin, high=fmax / 1e17) -def test_uniform_return_type(): - val = rnd.uniform(0.0, 1.0) +@pytest.mark.parametrize( + "low, high", + [ + (0.0, 1.0), + (np.float64(0.0), np.float64(1.0)), + (np.array(0.0), np.array(1.0)), + ], +) +def test_uniform_return_type(low, high): + val = rnd.uniform(low, high) assert np.isscalar(val), f"expected a scalar, got {type(val)}" assert isinstance(val, float) assert 0.0 <= val < 1.0 + +def test_uniform_array_bounds_return_ndarray(): arr = rnd.uniform([0.0, 10.0], [1.0, 11.0]) assert isinstance(arr, np.ndarray) assert arr.shape == (2,)