Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed `dpnp.unique` with 1d input array and `axis=0`, `equal_nan=True` keywords passed where the produced result doesn't collapse the NaNs [#2530](https://github.com/IntelPython/dpnp/pull/2530)
* Resolved issue when `dpnp.ndarray` constructor is called with `dpnp.ndarray.data` as `buffer` keyword [#2533](https://github.com/IntelPython/dpnp/pull/2533)
* Fixed `dpnp.linalg.cond` to always return a real dtype [#2547](https://github.com/IntelPython/dpnp/pull/2547)
* Resolved the issue in `dpnp.random` functions to allow any value of `size` where each element is castable to `Py_ssize_t` type [#2578](https://github.com/IntelPython/dpnp/pull/2578)

### Security

Expand Down
9 changes: 8 additions & 1 deletion dpnp/dpnp_utils/dpnp_algo_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,14 @@ cpdef inline tuple _object_to_tuple(object obj):
return ()

if cpython.PySequence_Check(obj):
return tuple(obj)
nd = len(obj)
shape = []

for i in range(0, nd):
# Assumes each item is castable to Py_ssize_t,
# otherwise TypeError will be raised
shape.append(<Py_ssize_t> obj[i])
return tuple(shape)

if dpnp.isscalar(obj):
return (obj, )
Expand Down
10 changes: 10 additions & 0 deletions dpnp/tests/test_random_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,3 +1115,13 @@ def test_invalid_dtype(self, dtype):
def test_invalid_usm_type(self, usm_type):
# dtype must be float32 or float64
assert_raises(ValueError, RandomState().uniform, usm_type=usm_type)

def test_size_castable_to_integer(self):
M = numpy.int64(31)
N = numpy.int64(31)
K = 63 # plain Python int

sizes = [(M, K), (M, N), (K, N)]
for size in sizes:
result = RandomState().uniform(size=size)
assert result.shape == size
Loading