Skip to content

Commit dc1b8f2

Browse files
Add TestSvdvals to test_linalg.py
1 parent 02e511a commit dc1b8f2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/test_linalg.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,50 @@ def test_svd_errors(self):
29932993
assert_raises(inp.linalg.LinAlgError, inp.linalg.svd, a_dp_ndim_1)
29942994

29952995

2996+
# numpy.linalg.svdvals() is available since numpy >= 2.0
2997+
@testing.with_requires("numpy>=2.0")
2998+
class TestSvdvals:
2999+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
3000+
@pytest.mark.parametrize(
3001+
"shape",
3002+
[(3, 5), (4, 2), (2, 3, 3), (3, 5, 2)],
3003+
ids=["(3,5)", "(4,2)", "(2,3,3)", "(3,5,2)"],
3004+
)
3005+
def test_svdvals(self, dtype, shape):
3006+
a = numpy.arange(numpy.prod(shape), dtype=dtype).reshape(shape)
3007+
dp_a = inp.array(a)
3008+
3009+
expected = numpy.linalg.svdvals(a)
3010+
result = inp.linalg.svdvals(dp_a)
3011+
3012+
assert_dtype_allclose(result, expected)
3013+
3014+
@pytest.mark.parametrize(
3015+
"shape",
3016+
[(0, 0), (1, 0, 0), (0, 2, 2)],
3017+
ids=["(0,0)", "(1,0,0)", "(0,2,2)"],
3018+
)
3019+
def test_svdvals_empty(self, shape):
3020+
a = generate_random_numpy_array(shape, inp.default_float_type())
3021+
dp_a = inp.array(a)
3022+
3023+
expected = numpy.linalg.svdvals(a)
3024+
result = inp.linalg.svdvals(dp_a)
3025+
3026+
assert_dtype_allclose(result, expected)
3027+
3028+
def test_svdvals_errors(self):
3029+
a_dp = inp.array([[1, 2], [3, 4]], dtype="float32")
3030+
3031+
# unsupported type
3032+
a_np = inp.asnumpy(a_dp)
3033+
assert_raises(TypeError, inp.linalg.svdvals, a_np)
3034+
3035+
# a.ndim < 2
3036+
a_dp_ndim_1 = a_dp.flatten()
3037+
assert_raises(inp.linalg.LinAlgError, inp.linalg.svdvals, a_dp_ndim_1)
3038+
3039+
29963040
class TestPinv:
29973041
def get_tol(self, dtype):
29983042
tol = 1e-06

0 commit comments

Comments
 (0)