Skip to content

dpnp.random.random issue with argument types #2564

@abagusetty

Description

@abagusetty

When arguments are passed as native numpy datatypes(i.e., np.int64, etc) to dpnp.random results in the following error. This works fine with cupy & numpy

Error:

Traceback (most recent call last):
  File "/home/abagusetty/gpu4pyscf-testing/gpu4pyscf/test_dpnp_random.py", line 12, in <module>
    tmp=[dpnp.random.random(size).astype(dtype) for size in sizes]
  File "/home/abagusetty/gpu4pyscf-testing/gpu4pyscf/test_dpnp_random.py", line 12, in <listcomp>
    tmp=[dpnp.random.random(size).astype(dtype) for size in sizes]
  File "/home/abagusetty/gpu4pyscf-testing/dpnp/dpnp/random/dpnp_iface_random.py", line 1352, in random
    return random_sample(
  File "/home/abagusetty/gpu4pyscf-testing/dpnp/dpnp/random/dpnp_iface_random.py", line 1472, in random_sample
    return rs.random_sample(size=size, usm_type=usm_type)
  File "/home/abagusetty/gpu4pyscf-testing/dpnp/dpnp/random/dpnp_random_state.py", line 513, in random_sample
    return self.uniform(
  File "/home/abagusetty/gpu4pyscf-testing/dpnp/dpnp/random/dpnp_random_state.py", line 641, in uniform
    return self._random_state.uniform(
  File "dpnp/random/dpnp_algo_random.pyx", line 364, in dpnp.random.dpnp_algo_random._Engine.uniform
  File "dpnp/random/dpnp_algo_random.pyx", line 372, in dpnp.random.dpnp_algo_random._Engine.uniform
  File "<stringsource>", line 58, in vector.from_py.__pyx_convert_vector_from_py___pyx_t_4dpnp_9dpnp_algo_shape_elem_type
TypeError: an integer is required

Reproducer:

import numpy as np
import dpnp

M = np.int64(31)
N = np.int64(31)
K = 63  # plain Python int
dtype = dpnp.float64

sizes = [(M, K), (M, N), (K, N)]

tmp=[dpnp.random.random(size).astype(dtype) for size in sizes]
print(tmp)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions