Skip to content

Commit 354ea03

Browse files
committed
update lower and upper range
1 parent 3f4a69e commit 354ea03

File tree

3 files changed

+95
-178
lines changed

3 files changed

+95
-178
lines changed

dpnp/tests/helper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_all_dtypes(
162162

163163

164164
def generate_random_numpy_array(
165-
shape, dtype=None, hermitian=False, seed_value=None, low=-1, high=1
165+
shape, dtype=None, hermitian=False, seed_value=None, low=-10, high=10
166166
):
167167
"""
168168
Generate a random numpy array with the specified shape and dtype.
@@ -184,12 +184,12 @@ def generate_random_numpy_array(
184184
seed_value : int, optional
185185
The seed value to initialize the random number generator.
186186
Default : ``None``
187-
low : scalar, optional
187+
low : {int, float}, optional
188188
Lower boundary of the generated samples from a uniform distribution.
189-
Default : ``-1``.
190-
high : scalar, optional
189+
Default : ``-10``.
190+
high : {int, float}, optional
191191
Upper boundary of the generated samples from a uniform distribution.
192-
Default : ``1``.
192+
Default : ``10``.
193193
194194
Returns
195195
-------

dpnp/tests/test_linalg.py

Lines changed: 35 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ class TestCholesky:
150150
[[[7, 2], [2, 7]], [[8, 3], [3, 8]]],
151151
],
152152
],
153-
ids=[
154-
"2D_array",
155-
"3D_array",
156-
"4D_array",
157-
],
153+
ids=["2D_array", "3D_array", "4D_array"],
158154
)
159155
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
160156
def test_cholesky(self, array, dtype):
@@ -174,11 +170,7 @@ def test_cholesky(self, array, dtype):
174170
[[[7, 2], [2, 7]], [[8, 3], [3, 8]]],
175171
],
176172
],
177-
ids=[
178-
"2D_array",
179-
"3D_array",
180-
"4D_array",
181-
],
173+
ids=["2D_array", "3D_array", "4D_array"],
182174
)
183175
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
184176
def test_cholesky_upper(self, array, dtype):
@@ -221,11 +213,7 @@ def test_cholesky_upper(self, array, dtype):
221213
[[[7, 2], [2, 7]], [[8, 3], [3, 8]]],
222214
],
223215
],
224-
ids=[
225-
"2D_array",
226-
"3D_array",
227-
"4D_array",
228-
],
216+
ids=["2D_array", "3D_array", "4D_array"],
229217
)
230218
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
231219
def test_cholesky_upper_numpy(self, array, dtype):
@@ -260,16 +248,8 @@ def test_cholesky_strides(self):
260248

261249
@pytest.mark.parametrize(
262250
"shape",
263-
[
264-
(0, 0),
265-
(3, 0, 0),
266-
(0, 2, 2),
267-
],
268-
ids=[
269-
"(0, 0)",
270-
"(3, 0, 0)",
271-
"(0, 2, 2)",
272-
],
251+
[(0, 0), (3, 0, 0), (0, 2, 2)],
252+
ids=["(0, 0)", "(3, 0, 0)", "(0, 2, 2)"],
273253
)
274254
def test_cholesky_empty(self, shape):
275255
a = numpy.empty(shape)
@@ -322,7 +302,7 @@ def test_cond_empty(self, shape, p):
322302
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
323303
)
324304
def test_cond(self, dtype, shape, p):
325-
a = generate_random_numpy_array(shape, dtype, low=-5, high=5)
305+
a = generate_random_numpy_array(shape, dtype)
326306
ia = dpnp.array(a)
327307

328308
result = dpnp.linalg.cond(ia, p=p)
@@ -342,7 +322,7 @@ def test_cond_bool(self, p):
342322

343323
@pytest.mark.parametrize("p", [-dpnp.inf, -1, 1, dpnp.inf, "fro"])
344324
def test_cond_nan_input(self, p):
345-
a = generate_random_numpy_array((3, 3), low=-10, high=10)
325+
a = generate_random_numpy_array((3, 3))
346326
a[1, 1] = numpy.nan
347327
ia = dpnp.array(a)
348328

@@ -354,7 +334,7 @@ def test_cond_nan_input(self, p):
354334
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
355335
)
356336
def test_cond_nan(self, p):
357-
a = generate_random_numpy_array((2, 2, 2, 2), low=-5, high=5)
337+
a = generate_random_numpy_array((2, 2, 2, 2))
358338
a[0, 0] = 0
359339
a[1, 1] = 0
360340
ia = dpnp.array(a)
@@ -405,11 +385,7 @@ class TestDet:
405385
[[[1, 3], [3, 1]], [[0, 1], [1, 3]]],
406386
],
407387
],
408-
ids=[
409-
"2D_array",
410-
"3D_array",
411-
"4D_array",
412-
],
388+
ids=["2D_array", "3D_array", "4D_array"],
413389
)
414390
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
415391
def test_det(self, array, dtype):
@@ -523,35 +499,21 @@ def assert_eigen_decomposition(self, a, w, v, rtol=1e-5, atol=1e-5):
523499
a[i].dot(v[i]), w[i] * v[i], rtol=rtol, atol=atol
524500
)
525501

526-
@pytest.mark.parametrize(
527-
"func",
528-
[
529-
"eig",
530-
"eigvals",
531-
"eigh",
532-
"eigvalsh",
533-
],
534-
)
502+
@pytest.mark.parametrize("func", ["eig", "eigvals", "eigh", "eigvalsh"])
535503
@pytest.mark.parametrize(
536504
"shape",
537505
[(2, 2), (2, 3, 3), (2, 2, 3, 3)],
538-
ids=["(2,2)", "(2,3,3)", "(2,2,3,3)"],
506+
ids=["(2, 2)", "(2, 3, 3)", "(2, 2, 3, 3)"],
539507
)
540508
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
541-
@pytest.mark.parametrize(
542-
"order",
543-
[
544-
"C",
545-
"F",
546-
],
547-
)
509+
@pytest.mark.parametrize("order", ["C", "F"])
548510
def test_eigenvalues(self, func, shape, dtype, order):
549511
# Set a `hermitian` flag for generate_random_numpy_array() to
550512
# get a symmetric array for eigh() and eigvalsh() or
551513
# non-symmetric for eig() and eigvals()
552514
is_hermitian = func in ("eigh, eigvalsh")
553515
a = generate_random_numpy_array(
554-
shape, dtype, hermitian=is_hermitian, seed_value=81
516+
shape, dtype, hermitian=is_hermitian, seed_value=81, low=-2, high=2
555517
)
556518
a_order = numpy.array(a, order=order)
557519
a_dp = dpnp.array(a, order=order)
@@ -574,13 +536,7 @@ def test_eigenvalues(self, func, shape, dtype, order):
574536
assert_dtype_allclose(w_dp, w)
575537

576538
# eigh() and eigvalsh() are tested in cupy tests
577-
@pytest.mark.parametrize(
578-
"func",
579-
[
580-
"eig",
581-
"eigvals",
582-
],
583-
)
539+
@pytest.mark.parametrize("func", ["eig", "eigvals"])
584540
@pytest.mark.parametrize(
585541
"shape",
586542
[(0, 0), (2, 0, 0), (0, 3, 3)],
@@ -603,15 +559,7 @@ def test_eigenvalue_empty(self, func, shape, dtype):
603559

604560
assert_dtype_allclose(w_dp, w)
605561

606-
@pytest.mark.parametrize(
607-
"func",
608-
[
609-
"eig",
610-
"eigvals",
611-
"eigh",
612-
"eigvalsh",
613-
],
614-
)
562+
@pytest.mark.parametrize("func", ["eig", "eigvals", "eigh", "eigvalsh"])
615563
def test_eigenvalue_errors(self, func):
616564
a_dp = dpnp.array([[1, 3], [3, 2]], dtype="float32")
617565

@@ -1737,11 +1685,7 @@ class TestInv:
17371685
[[[1, 3], [3, 1]], [[0, 1], [1, 3]]],
17381686
],
17391687
],
1740-
ids=[
1741-
"2D_array",
1742-
"3D_array",
1743-
"4D_array",
1744-
],
1688+
ids=["2D_array", "3D_array", "4D_array"],
17451689
)
17461690
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
17471691
def test_inv(self, array, dtype):
@@ -1776,16 +1720,8 @@ def test_inv_strides(self):
17761720

17771721
@pytest.mark.parametrize(
17781722
"shape",
1779-
[
1780-
(0, 0),
1781-
(3, 0, 0),
1782-
(0, 2, 2),
1783-
],
1784-
ids=[
1785-
"(0, 0)",
1786-
"(3, 0, 0)",
1787-
"(0, 2, 2)",
1788-
],
1723+
[(0, 0), (3, 0, 0), (0, 2, 2)],
1724+
ids=["(0, 0)", "(3, 0, 0)", "(0, 2, 2)"],
17891725
)
17901726
def test_inv_empty(self, shape):
17911727
a = numpy.empty(shape)
@@ -1882,8 +1818,8 @@ def test_lstsq(self, a_shape, b_shape, dtype):
18821818
@pytest.mark.parametrize("a_dtype", get_all_dtypes())
18831819
@pytest.mark.parametrize("b_dtype", get_all_dtypes())
18841820
def test_lstsq_diff_type(self, a_dtype, b_dtype):
1885-
a_np = generate_random_numpy_array((2, 2), a_dtype, low=-5, high=5)
1886-
b_np = generate_random_numpy_array(2, b_dtype, low=-5, high=5)
1821+
a_np = generate_random_numpy_array((2, 2), a_dtype)
1822+
b_np = generate_random_numpy_array(2, b_dtype)
18871823
a_dp = dpnp.array(a_np)
18881824
b_dp = dpnp.array(b_np)
18891825

@@ -2030,11 +1966,7 @@ def test_matrix_rank_hermitian(self, data, dtype):
20301966
(numpy.array(0.99e-6), numpy.array(1.01e-6)),
20311967
(numpy.array([0.99e-6]), numpy.array([1.01e-6])),
20321968
],
2033-
ids=[
2034-
"float",
2035-
"0-D array",
2036-
"1-D array",
2037-
],
1969+
ids=["float", "0-D array", "1-D array"],
20381970
)
20391971
def test_matrix_rank_tolerance(self, high_tol, low_tol):
20401972
a = numpy.eye(4)
@@ -2209,7 +2141,7 @@ def test_norm_0D(self, ord, axis):
22092141
@pytest.mark.parametrize("axis", [0, None])
22102142
@pytest.mark.parametrize("keepdims", [True, False])
22112143
def test_norm_1D(self, dtype, ord, axis, keepdims):
2212-
a = generate_random_numpy_array(10, dtype, low=-5, high=5)
2144+
a = generate_random_numpy_array(10, dtype)
22132145
ia = dpnp.array(a)
22142146

22152147
result = dpnp.linalg.norm(ia, ord=ord, axis=axis, keepdims=keepdims)
@@ -2226,7 +2158,7 @@ def test_norm_1D(self, dtype, ord, axis, keepdims):
22262158
)
22272159
@pytest.mark.parametrize("keepdims", [True, False])
22282160
def test_norm_2D(self, dtype, ord, axis, keepdims):
2229-
a = generate_random_numpy_array((3, 5), dtype, low=-5, high=5)
2161+
a = generate_random_numpy_array((3, 5), dtype)
22302162
ia = dpnp.array(a)
22312163
if (axis in [-1, 0, 1] and ord in ["nuc", "fro"]) or (
22322164
(isinstance(axis, tuple) or axis is None) and ord == 3
@@ -2253,7 +2185,7 @@ def test_norm_2D(self, dtype, ord, axis, keepdims):
22532185
)
22542186
@pytest.mark.parametrize("keepdims", [True, False])
22552187
def test_norm_ND(self, dtype, ord, axis, keepdims):
2256-
a = generate_random_numpy_array((2, 3, 4, 5), dtype, low=-5, high=5)
2188+
a = generate_random_numpy_array((2, 3, 4, 5), dtype)
22572189
ia = dpnp.array(a)
22582190
if (axis in [-1, 0, 1] and ord in ["nuc", "fro"]) or (
22592191
isinstance(axis, tuple) and ord == 3
@@ -2284,7 +2216,7 @@ def test_norm_ND(self, dtype, ord, axis, keepdims):
22842216
)
22852217
@pytest.mark.parametrize("keepdims", [True, False])
22862218
def test_norm_usm_ndarray(self, dtype, ord, axis, keepdims):
2287-
a = generate_random_numpy_array((2, 3, 4, 5), dtype, low=-5, high=5)
2219+
a = generate_random_numpy_array((2, 3, 4, 5), dtype)
22882220
ia = dpt.asarray(a)
22892221
if (axis in [-1, 0, 1] and ord in ["nuc", "fro"]) or (
22902222
isinstance(axis, tuple) and ord == 3
@@ -2361,7 +2293,7 @@ def test_norm_strided_ND(self, axis, stride):
23612293
)
23622294
@pytest.mark.parametrize("keepdims", [True, False])
23632295
def test_matrix_norm(self, ord, keepdims):
2364-
a = generate_random_numpy_array((3, 5), low=-5, high=5)
2296+
a = generate_random_numpy_array((3, 5))
23652297
ia = dpnp.array(a)
23662298

23672299
result = dpnp.linalg.matrix_norm(ia, ord=ord, keepdims=keepdims)
@@ -2387,7 +2319,7 @@ def test_vector_norm_0D(self, ord):
23872319
@pytest.mark.parametrize("axis", [0, None])
23882320
@pytest.mark.parametrize("keepdims", [True, False])
23892321
def test_vector_norm_1D(self, ord, axis, keepdims):
2390-
a = generate_random_numpy_array(10, low=-5, high=5)
2322+
a = generate_random_numpy_array(10)
23912323
ia = dpnp.array(a)
23922324

23932325
result = dpnp.linalg.vector_norm(
@@ -2588,8 +2520,8 @@ def test_solve_nrhs_greater_n(self, dtype):
25882520
@pytest.mark.parametrize("a_dtype", get_all_dtypes(no_bool=True))
25892521
@pytest.mark.parametrize("b_dtype", get_all_dtypes(no_bool=True))
25902522
def test_solve_diff_type(self, a_dtype, b_dtype):
2591-
a_np = generate_random_numpy_array((2, 2), a_dtype, low=-5, high=5)
2592-
b_np = generate_random_numpy_array(2, b_dtype, low=-5, high=5)
2523+
a_np = generate_random_numpy_array((2, 2), a_dtype)
2524+
b_np = generate_random_numpy_array(2, b_dtype)
25932525
a_dp = dpnp.array(a_np)
25942526
b_dp = dpnp.array(b_np)
25952527

@@ -2877,9 +2809,7 @@ def test_svd(self, dtype, shape):
28772809
@pytest.mark.parametrize("dtype", get_float_complex_dtypes())
28782810
@pytest.mark.parametrize("compute_vt", [True, False])
28792811
@pytest.mark.parametrize(
2880-
"shape",
2881-
[(2, 2), (16, 16)],
2882-
ids=["(2, 2)", "(16, 16)"],
2812+
"shape", [(2, 2), (16, 16)], ids=["(2, 2)", "(16, 16)"]
28832813
)
28842814
def test_svd_hermitian(self, dtype, compute_vt, shape):
28852815
# Set seed_value=81 to prevent
@@ -3025,15 +2955,13 @@ def test_pinv(self, dtype, shape):
30252955

30262956
@pytest.mark.parametrize("dtype", get_float_complex_dtypes())
30272957
@pytest.mark.parametrize(
3028-
"shape",
3029-
[(2, 2), (16, 16)],
3030-
ids=["(2, 2)", "(16, 16)"],
2958+
"shape", [(2, 2), (16, 16)], ids=["(2, 2)", "(16, 16)"]
30312959
)
30322960
def test_pinv_hermitian(self, dtype, shape):
30332961
# Set seed_value=70 to prevent
30342962
# random generation of the input singular matrix
30352963
a = generate_random_numpy_array(
3036-
shape, dtype, hermitian=True, seed_value=70
2964+
shape, dtype, hermitian=True, seed_value=70, low=-2, high=2
30372965
)
30382966
a_dp = dpnp.array(a)
30392967

@@ -3133,14 +3061,8 @@ class TestTensorinv:
31333061
@pytest.mark.parametrize("dtype", get_all_dtypes())
31343062
@pytest.mark.parametrize(
31353063
"shape, ind",
3136-
[
3137-
((4, 6, 8, 3), 2),
3138-
((24, 8, 3), 1),
3139-
],
3140-
ids=[
3141-
"(4, 6, 8, 3)",
3142-
"(24, 8, 3)",
3143-
],
3064+
[((4, 6, 8, 3), 2), ((24, 8, 3), 1)],
3065+
ids=["(4, 6, 8, 3)", "(24, 8, 3)"],
31443066
)
31453067
def test_tensorinv(self, dtype, shape, ind):
31463068
a = numpy.eye(24, dtype=dtype).reshape(shape)
@@ -3173,11 +3095,7 @@ class TestTensorsolve:
31733095
@pytest.mark.parametrize(
31743096
"axes",
31753097
[None, (1,), (2,)],
3176-
ids=[
3177-
"None",
3178-
"(1,)",
3179-
"(2,)",
3180-
],
3098+
ids=["None", "(1,)", "(2,)"],
31813099
)
31823100
def test_tensorsolve_axes(self, dtype, axes):
31833101
a = numpy.eye(12).reshape(12, 3, 4).astype(dtype)

0 commit comments

Comments
 (0)