Skip to content

Commit 9cb5848

Browse files
committed
Rename a variable with numpy array to 'expected' in tests
1 parent 1ec95dd commit 9cb5848

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

tests/test_random_state.py

+60-60
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ def test_distr(self, dtype, usm_type):
5757

5858
# default dtype depends on fp64 support by the device
5959
dtype = get_default_floating() if dtype is None else dtype
60-
desired = numpy.array([[0.428205496031286, -0.55383273779227 ],
61-
[2.027017795643378, 4.318888073163015],
62-
[2.69080893259102, -1.047967253719708]], dtype=dtype)
60+
expected = numpy.array([[0.428205496031286, -0.55383273779227 ],
61+
[2.027017795643378, 4.318888073163015],
62+
[2.69080893259102, -1.047967253719708]], dtype=dtype)
6363

6464
# TODO: discuss with opneMKL: there is a difference between CPU and GPU
6565
# generated samples since 9 digit while precision=15 for float64
6666
# precision = numpy.finfo(dtype=dtype).precision
6767
precision = 8 if dtype == dpnp.float64 else numpy.finfo(dtype=dtype).precision
68-
assert_array_almost_equal(dpnp_data.asnumpy(), desired, decimal=precision)
68+
assert_array_almost_equal(dpnp_data.asnumpy(), expected, decimal=precision)
6969

7070
# check if compute follows data isn't broken
7171
assert_cfd(dpnp_data, sycl_queue, usm_type)
@@ -162,11 +162,11 @@ def test_fallback(self, loc, scale):
162162

163163
# dpnp accepts only scalar as low and/or high, in other cases it will be a fallback to numpy
164164
actual = data.asnumpy()
165-
desired = numpy.random.RandomState(seed).normal(loc=loc, scale=scale, size=size)
165+
expected = numpy.random.RandomState(seed).normal(loc=loc, scale=scale, size=size)
166166

167167
dtype = get_default_floating()
168168
precision = numpy.finfo(dtype=dtype).precision
169-
assert_array_almost_equal(actual, desired, decimal=precision)
169+
assert_array_almost_equal(actual, expected, decimal=precision)
170170

171171
# check if compute follows data isn't broken
172172
assert_cfd(data, sycl_queue)
@@ -200,22 +200,22 @@ def test_distr(self, usm_type):
200200
dtype = get_default_floating()
201201

202202
data = RandomState(seed, sycl_queue=sycl_queue).rand(3, 2, usm_type=usm_type)
203-
desired = numpy.array([[0.7592552667483687, 0.5937560645397753],
204-
[0.257010098779574 , 0.749422621447593 ],
205-
[0.6316644293256104, 0.7411410815548152]], dtype=dtype)
203+
expected = numpy.array([[0.7592552667483687, 0.5937560645397753],
204+
[0.257010098779574 , 0.749422621447593 ],
205+
[0.6316644293256104, 0.7411410815548152]], dtype=dtype)
206206

207207
precision = numpy.finfo(dtype=numpy.float64).precision
208-
assert_array_almost_equal(data.asnumpy(), desired, decimal=precision)
208+
assert_array_almost_equal(data.asnumpy(), expected, decimal=precision)
209209
assert_cfd(data, sycl_queue, usm_type)
210210

211211
# call with the same seed has to draw the same values
212212
data = RandomState(seed, sycl_queue=sycl_queue).rand(3, 2, usm_type=usm_type)
213-
assert_array_almost_equal(data.asnumpy(), desired, decimal=precision)
213+
assert_array_almost_equal(data.asnumpy(), expected, decimal=precision)
214214
assert_cfd(data, sycl_queue, usm_type)
215215

216-
# call with omitted dimensions has to draw the first element from desired
216+
# call with omitted dimensions has to draw the first element from expected
217217
data = RandomState(seed, sycl_queue=sycl_queue).rand(usm_type=usm_type)
218-
assert_array_almost_equal(data.asnumpy(), desired[0, 0], decimal=precision)
218+
assert_array_almost_equal(data.asnumpy(), expected[0, 0], decimal=precision)
219219
assert_cfd(data, sycl_queue, usm_type)
220220

221221
# rand() is an alias on random_sample(), map arguments
@@ -276,10 +276,10 @@ def test_distr(self, dtype, usm_type):
276276
size=(3, 2),
277277
dtype=dtype,
278278
usm_type=usm_type)
279-
desired = numpy.array([[4, 1],
280-
[5, 3],
281-
[5, 7]], dtype=numpy.int32)
282-
assert_array_equal(data.asnumpy(), desired)
279+
expected = numpy.array([[4, 1],
280+
[5, 3],
281+
[5, 7]], dtype=numpy.int32)
282+
assert_array_equal(data.asnumpy(), expected)
283283
assert_cfd(data, sycl_queue, usm_type)
284284

285285
# call with the same seed has to draw the same values
@@ -288,15 +288,15 @@ def test_distr(self, dtype, usm_type):
288288
size=(3, 2),
289289
dtype=dtype,
290290
usm_type=usm_type)
291-
assert_array_equal(data.asnumpy(), desired)
291+
assert_array_equal(data.asnumpy(), expected)
292292
assert_cfd(data, sycl_queue, usm_type)
293293

294-
# call with omitted dimensions has to draw the first element from desired
294+
# call with omitted dimensions has to draw the first element from expected
295295
data = RandomState(seed, sycl_queue=sycl_queue).randint(low=low,
296296
high=high,
297297
dtype=dtype,
298298
usm_type=usm_type)
299-
assert_array_equal(data.asnumpy(), desired[0, 0])
299+
assert_array_equal(data.asnumpy(), expected[0, 0])
300300
assert_cfd(data, sycl_queue, usm_type)
301301

302302
# rand() is an alias on random_sample(), map arguments
@@ -311,15 +311,15 @@ def test_distr(self, dtype, usm_type):
311311

312312
def test_float_bounds(self):
313313
actual = RandomState(365852).randint(low=0.6, high=6.789102534, size=(7,)).asnumpy()
314-
desired = numpy.array([4, 4, 3, 3, 1, 0, 3], dtype=numpy.int32)
315-
assert_array_equal(actual, desired)
314+
expected = numpy.array([4, 4, 3, 3, 1, 0, 3], dtype=numpy.int32)
315+
assert_array_equal(actual, expected)
316316

317317

318318
def test_negative_bounds(self):
319319
actual = RandomState(5143).randint(low=-15.74, high=-3, size=(2, 7)).asnumpy()
320-
desired = numpy.array([[-9, -12, -4, -12, -5, -13, -9],
321-
[-4, -6, -13, -9, -9, -6, -15]], dtype=numpy.int32)
322-
assert_array_equal(actual, desired)
320+
expected = numpy.array([[-9, -12, -4, -12, -5, -13, -9],
321+
[-4, -6, -13, -9, -9, -6, -15]], dtype=numpy.int32)
322+
assert_array_equal(actual, expected)
323323

324324

325325
def test_negative_interval(self):
@@ -417,8 +417,8 @@ def test_bounds_fallback(self, low, high):
417417

418418
# dpnp accepts only scalar as low and/or high, in other cases it will be a fallback to numpy
419419
actual = RandomState(seed).randint(low=low, high=high, size=size).asnumpy()
420-
desired = numpy.random.RandomState(seed).randint(low=low, high=high, size=size)
421-
assert_equal(actual, desired)
420+
expected = numpy.random.RandomState(seed).randint(low=low, high=high, size=size)
421+
assert_equal(actual, expected)
422422

423423

424424
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@@ -436,8 +436,8 @@ def test_dtype_fallback(self, dtype):
436436

437437
# dtype must be int or dpnp.int32, in other cases it will be a fallback to numpy
438438
actual = RandomState(seed).randint(low=low, high=high, size=size, dtype=dtype).asnumpy()
439-
desired = numpy.random.RandomState(seed).randint(low=low, high=high, size=size, dtype=dtype)
440-
assert_equal(actual, desired)
439+
expected = numpy.random.RandomState(seed).randint(low=low, high=high, size=size, dtype=dtype)
440+
assert_equal(actual, expected)
441441
assert_raises(TypeError, RandomState().randint, dtype=dtype)
442442

443443

@@ -459,23 +459,23 @@ def test_distr(self, usm_type):
459459
dtype = get_default_floating()
460460

461461
data = RandomState(seed, sycl_queue=sycl_queue).randn(3, 2, usm_type=usm_type)
462-
desired = numpy.array([[-0.862485623762009, 1.169492612490272],
462+
expected = numpy.array([[-0.862485623762009, 1.169492612490272],
463463
[-0.405876118480338, 0.939006537666719],
464464
[-0.615075625641019, 0.555260469834381]], dtype=dtype)
465465

466466
# TODO: discuss with opneMKL: there is a difference between CPU and GPU
467467
# generated samples since 9 digit while precision=15 for float64
468468
# precision = numpy.finfo(dtype=numpy.float64).precision
469469
precision = numpy.finfo(dtype=numpy.float32).precision
470-
assert_array_almost_equal(data.asnumpy(), desired, decimal=precision)
470+
assert_array_almost_equal(data.asnumpy(), expected, decimal=precision)
471471

472472
# call with the same seed has to draw the same values
473473
data = RandomState(seed, sycl_queue=sycl_queue).randn(3, 2, usm_type=usm_type)
474-
assert_array_almost_equal(data.asnumpy(), desired, decimal=precision)
474+
assert_array_almost_equal(data.asnumpy(), expected, decimal=precision)
475475

476-
# call with omitted dimensions has to draw the first element from desired
476+
# call with omitted dimensions has to draw the first element from expected
477477
actual = dpnp.asnumpy(RandomState(seed).randn(usm_type=usm_type))
478-
assert_array_almost_equal(actual, desired[0, 0], decimal=precision)
478+
assert_array_almost_equal(actual, expected[0, 0], decimal=precision)
479479

480480
# randn() is an alias on standard_normal(), map arguments
481481
with mock.patch('dpnp.random.RandomState.standard_normal') as m:
@@ -610,24 +610,24 @@ def test_distr(self, usm_type):
610610
dtype = get_default_floating()
611611

612612
data = RandomState(seed, sycl_queue=sycl_queue).standard_normal(size=(4, 2), usm_type=usm_type)
613-
desired = numpy.array([[0.112455902594571, -0.249919829443642],
614-
[0.702423540827815, 1.548132130318456],
615-
[0.947364919775284, -0.432257289195464],
616-
[0.736848611436872, 1.557284323302839]], dtype=dtype)
613+
expected = numpy.array([[0.112455902594571, -0.249919829443642],
614+
[0.702423540827815, 1.548132130318456],
615+
[0.947364919775284, -0.432257289195464],
616+
[0.736848611436872, 1.557284323302839]], dtype=dtype)
617617

618618
# TODO: discuss with opneMKL: there is a difference between CPU and GPU
619619
# generated samples since 9 digit while precision=15 for float64
620620
# precision = numpy.finfo(dtype=numpy.float64).precision
621621
precision = numpy.finfo(dtype=numpy.float32).precision
622-
assert_array_almost_equal(data.asnumpy(), desired, decimal=precision)
622+
assert_array_almost_equal(data.asnumpy(), expected, decimal=precision)
623623

624624
# call with the same seed has to draw the same values
625625
data = RandomState(seed, sycl_queue=sycl_queue).standard_normal(size=(4, 2), usm_type=usm_type)
626-
assert_array_almost_equal(data.asnumpy(), desired, decimal=precision)
626+
assert_array_almost_equal(data.asnumpy(), expected, decimal=precision)
627627

628-
# call with omitted dimensions has to draw the first element from desired
628+
# call with omitted dimensions has to draw the first element from expected
629629
actual = dpnp.asnumpy(RandomState(seed).standard_normal(usm_type=usm_type))
630-
assert_array_almost_equal(actual, desired[0, 0], decimal=precision)
630+
assert_array_almost_equal(actual, expected[0, 0], decimal=precision)
631631

632632
# random_sample() is an alias on uniform(), map arguments
633633
with mock.patch('dpnp.random.RandomState.normal') as m:
@@ -670,17 +670,17 @@ def test_distr(self, usm_type):
670670
dtype = get_default_floating()
671671

672672
data = RandomState(seed, sycl_queue=sycl_queue).random_sample(size=(4, 2), usm_type=usm_type)
673-
desired = numpy.array([[0.1887628440745175, 0.2763057765550911],
674-
[0.3973943444434553, 0.2975987731479108],
675-
[0.4144027342554182, 0.2636592474300414],
676-
[0.6129623607266694, 0.2596735346596688]], dtype=dtype)
673+
expected = numpy.array([[0.1887628440745175, 0.2763057765550911],
674+
[0.3973943444434553, 0.2975987731479108],
675+
[0.4144027342554182, 0.2636592474300414],
676+
[0.6129623607266694, 0.2596735346596688]], dtype=dtype)
677677

678678
precision = numpy.finfo(dtype=dtype).precision
679-
assert_array_almost_equal(data.asnumpy(), desired, decimal=precision)
679+
assert_array_almost_equal(data.asnumpy(), expected, decimal=precision)
680680

681-
# call with omitted dimensions has to draw the first element from desired
681+
# call with omitted dimensions has to draw the first element from expected
682682
data = RandomState(seed, sycl_queue=sycl_queue).random_sample(usm_type=usm_type)
683-
assert_array_almost_equal(data.asnumpy(), desired[0, 0], decimal=precision)
683+
assert_array_almost_equal(data.asnumpy(), expected[0, 0], decimal=precision)
684684

685685
# random_sample() is an alias on uniform(), map arguments
686686
with mock.patch('dpnp.random.RandomState.uniform') as m:
@@ -747,15 +747,15 @@ def test_distr(self, bounds, dtype, usm_type):
747747
# default dtype depends on fp64 support by the device
748748
dtype = get_default_floating() if dtype is None else dtype
749749
if dtype != dpnp.int32:
750-
desired = numpy.array([[4.023770128630567, 8.87456423597643 ],
751-
[2.888630247435067, 4.823004481580574],
752-
[2.030351535445079, 4.533497077834326]])
753-
assert_array_almost_equal(actual, desired, decimal=numpy.finfo(dtype=dtype).precision)
750+
expected = numpy.array([[4.023770128630567, 8.87456423597643 ],
751+
[2.888630247435067, 4.823004481580574],
752+
[2.030351535445079, 4.533497077834326]])
753+
assert_array_almost_equal(actual, expected, decimal=numpy.finfo(dtype=dtype).precision)
754754
else:
755-
desired = numpy.array([[3, 8],
755+
expected = numpy.array([[3, 8],
756756
[2, 4],
757757
[1, 4]])
758-
assert_array_equal(actual, desired)
758+
assert_array_equal(actual, expected)
759759

760760
# check if compute follows data isn't broken
761761
assert_cfd(dpnp_data, sycl_queue, usm_type)
@@ -784,12 +784,12 @@ def test_low_high_equal(self, dtype, usm_type):
784784

785785
# default dtype depends on fp64 support by the device
786786
dtype = get_default_floating() if dtype is None else dtype
787-
desired = numpy.full(shape=shape, fill_value=low, dtype=dtype)
787+
expected = numpy.full(shape=shape, fill_value=low, dtype=dtype)
788788

789789
if dtype == dpnp.int32:
790-
assert_array_equal(actual, desired)
790+
assert_array_equal(actual, expected)
791791
else:
792-
assert_array_almost_equal(actual, desired, decimal=numpy.finfo(dtype=dtype).precision)
792+
assert_array_almost_equal(actual, expected, decimal=numpy.finfo(dtype=dtype).precision)
793793

794794

795795
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@@ -824,11 +824,11 @@ def test_fallback(self, low, high):
824824

825825
# dpnp accepts only scalar as low and/or high, in other cases it will be a fallback to numpy
826826
actual = data.asnumpy()
827-
desired = numpy.random.RandomState(seed).uniform(low=low, high=high, size=size)
827+
expected = numpy.random.RandomState(seed).uniform(low=low, high=high, size=size)
828828

829829
dtype = get_default_floating()
830830
precision = numpy.finfo(dtype=dtype).precision
831-
assert_array_almost_equal(actual, desired, decimal=precision)
831+
assert_array_almost_equal(actual, expected, decimal=precision)
832832

833833
# check if compute follows data isn't broken
834834
assert_cfd(data, sycl_queue)

0 commit comments

Comments
 (0)