Skip to content
Merged
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
4 changes: 4 additions & 0 deletions dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def sycl_context(self):
def device(self):
return self._array_obj.device

@property
def usm_type(self):
return self._array_obj.usm_type

def __abs__(self):
return dpnp.abs(self)

Expand Down
26 changes: 16 additions & 10 deletions tests/test_random_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
)


def assert_cfd(data, exp_sycl_queue, exp_usm_type=None):
assert exp_sycl_queue == data.sycl_queue
if exp_usm_type:
assert exp_usm_type == data.usm_type


class TestNormal:
@pytest.mark.parametrize("dtype",
[dpnp.float32, dpnp.float64, None],
Expand Down Expand Up @@ -47,7 +53,7 @@ def test_distr(self, dtype, usm_type):
assert_array_almost_equal(dpnp.asnumpy(data), desired, decimal=precision)

# check if compute follows data isn't broken
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue, usm_type)


@pytest.mark.parametrize("dtype",
Expand Down Expand Up @@ -138,7 +144,7 @@ def test_fallback(self, loc, scale):
assert_array_almost_equal(actual, desired, decimal=precision)

# check if compute follows data isn't broken
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue)


@pytest.mark.parametrize("dtype",
Expand Down Expand Up @@ -174,17 +180,17 @@ def test_distr(self, usm_type):

precision = numpy.finfo(dtype=numpy.float64).precision
assert_array_almost_equal(dpnp.asnumpy(data), desired, decimal=precision)
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue, usm_type)

# call with the same seed has to draw the same values
data = RandomState(seed, sycl_queue=sycl_queue).rand(3, 2, usm_type=usm_type)
assert_array_almost_equal(dpnp.asnumpy(data), desired, decimal=precision)
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue, usm_type)

# call with omitted dimensions has to draw the first element from desired
data = RandomState(seed, sycl_queue=sycl_queue).rand(usm_type=usm_type)
assert_array_almost_equal(dpnp.asnumpy(data), desired[0, 0], decimal=precision)
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue, usm_type)

# rand() is an alias on random_sample(), map arguments
with mock.patch('dpnp.random.RandomState.random_sample') as m:
Expand Down Expand Up @@ -245,7 +251,7 @@ def test_distr(self, dtype, usm_type):
[5, 3],
[5, 7]], dtype=numpy.int32)
assert_array_equal(dpnp.asnumpy(data), desired)
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue, usm_type)

# call with the same seed has to draw the same values
data = RandomState(seed, sycl_queue=sycl_queue).randint(low=low,
Expand All @@ -254,15 +260,15 @@ def test_distr(self, dtype, usm_type):
dtype=dtype,
usm_type=usm_type)
assert_array_equal(dpnp.asnumpy(data), desired)
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue, usm_type)

# call with omitted dimensions has to draw the first element from desired
data = RandomState(seed, sycl_queue=sycl_queue).randint(low=low,
high=high,
dtype=dtype,
usm_type=usm_type)
assert_array_equal(dpnp.asnumpy(data), desired[0, 0])
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue, usm_type)

# rand() is an alias on random_sample(), map arguments
with mock.patch('dpnp.random.RandomState.uniform') as m:
Expand Down Expand Up @@ -701,7 +707,7 @@ def test_distr(self, bounds, dtype, usm_type):
assert_array_equal(dpnp.asnumpy(data), desired)

# check if compute follows data isn't broken
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue, usm_type)


@pytest.mark.parametrize("dtype",
Expand Down Expand Up @@ -766,7 +772,7 @@ def test_fallback(self, low, high):
assert_array_almost_equal(actual, desired, decimal=precision)

# check if compute follows data isn't broken
assert sycl_queue == data.sycl_queue
assert_cfd(data, sycl_queue)


@pytest.mark.parametrize("dtype",
Expand Down
6 changes: 2 additions & 4 deletions tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ def test_uniform(usm_type, size):
high = 2.0
res = dpnp.random.uniform(low, high, size=size, usm_type=usm_type)

res_usm_type = res.get_array().usm_type
assert usm_type == res_usm_type
assert usm_type == res.usm_type


@pytest.mark.parametrize("usm_type",
Expand All @@ -295,8 +294,7 @@ def test_rs_uniform(usm_type, seed):
rs = dpnp.random.RandomState(seed, sycl_queue=sycl_queue)
res = rs.uniform(low, high, usm_type=usm_type)

res_usm_type = res.get_array().usm_type
assert usm_type == res_usm_type
assert usm_type == res.usm_type

res_sycl_queue = res.get_array().sycl_queue
assert_sycl_queue_equal(res_sycl_queue, sycl_queue)
Expand Down