Skip to content

Commit 02e511a

Browse files
Add implementation of dpnp.linalg.svdvals
1 parent 48515c8 commit 02e511a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

dpnp/linalg/dpnp_iface_linalg.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"qr",
8484
"solve",
8585
"svd",
86+
"svdvals",
8687
"slogdet",
8788
"tensorinv",
8889
"tensorsolve",
@@ -1315,6 +1316,62 @@ def svd(a, full_matrices=True, compute_uv=True, hermitian=False):
13151316
return dpnp_svd(a, full_matrices, compute_uv, hermitian)
13161317

13171318

1319+
def svdvals(x, /):
1320+
"""
1321+
Returns the singular values of a matrix (or a stack of matrices) ``x``.
1322+
1323+
When ``x`` is a stack of matrices, the function will compute
1324+
the singular values for each matrix in the stack.
1325+
1326+
Calling ``dpnp.linalg.svdvals(x)`` to get singular values is the same as
1327+
``dpnp.linalg.svd(x, compute_uv=False, hermitian=False)``.
1328+
1329+
For full documentation refer to :obj:`numpy.linalg.svdvals`.
1330+
1331+
Parameters
1332+
----------
1333+
x : (..., M, N) {dpnp.ndarray, usm_ndarray}
1334+
Input array with ``x.ndim >= 2`` and whose last two dimensions
1335+
form matrices on which to perform singular value decomposition.
1336+
1337+
Returns
1338+
-------
1339+
out : (..., K) dpnp.ndarray
1340+
Vector(s) of singular values of length K, where K = min(M, N).
1341+
1342+
1343+
See Also
1344+
--------
1345+
:obj:`dpnp.linalg.svd` : Compute the singular value decomposition.
1346+
1347+
1348+
Examples
1349+
--------
1350+
>>> import dpnp as np
1351+
>>> a = np.array([[3, 0], [0, 4]])
1352+
>>> np.linalg.svdvals(a)
1353+
array([4., 3.])
1354+
1355+
This is equivalent to calling:
1356+
1357+
>>> np.linalg.svd(a, compute_uv=False, hermitian=False)
1358+
array([4., 3.])
1359+
1360+
Stack of matrices:
1361+
1362+
>>> b = np.array([[[6, 0], [0, 8]], [[9, 0], [0, 12]]])
1363+
>>> np.linalg.svdvals(b)
1364+
array([[ 8., 6.],
1365+
[12., 9.]])
1366+
1367+
"""
1368+
1369+
dpnp.check_supported_arrays_type(x)
1370+
assert_stacked_2d(x)
1371+
1372+
return dpnp_svd(x, full_matrices=True, compute_uv=False, hermitian=False)
1373+
1374+
13181375
def slogdet(a):
13191376
"""
13201377
Compute the sign and (natural) logarithm of the determinant of an array.

0 commit comments

Comments
 (0)