diff --git a/CHANGELOG.md b/CHANGELOG.md index eff67b71..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) diff --git a/mkl_random/mklrand.pyx b/mkl_random/mklrand.pyx index edbcd400..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 @@ -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") diff --git a/mkl_random/tests/test_random.py b/mkl_random/tests/test_random.py index 4e74d769..671dcd56 100644 --- a/mkl_random/tests/test_random.py +++ b/mkl_random/tests/test_random.py @@ -1142,6 +1142,27 @@ def test_uniform_range_bounds(): rnd.uniform(low=fmin, high=fmax / 1e17) +@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,) + + def test_randomdist_vonmises(randomdist): rnd.seed(randomdist.seed, brng=randomdist.brng) actual = rnd.vonmises(mu=1.23, kappa=1.54, size=(3, 2))