99
99
]
100
100
101
101
102
- def cholesky (a , upper = False ):
102
+ def cholesky (a , / , * , upper = False ):
103
103
"""
104
104
Cholesky decomposition.
105
105
@@ -1062,7 +1062,7 @@ def matrix_power(a, n):
1062
1062
return dpnp_matrix_power (a , n )
1063
1063
1064
1064
1065
- def matrix_rank (A , tol = None , hermitian = False ):
1065
+ def matrix_rank (A , tol = None , hermitian = False , * , rtol = None ):
1066
1066
"""
1067
1067
Return matrix rank of array using SVD method.
1068
1068
@@ -1074,20 +1074,26 @@ def matrix_rank(A, tol=None, hermitian=False):
1074
1074
A : {(M,), (..., M, N)} {dpnp.ndarray, usm_ndarray}
1075
1075
Input vector or stack of matrices.
1076
1076
tol : (...) {float, dpnp.ndarray, usm_ndarray}, optional
1077
- Threshold below which SVD values are considered zero. If `tol` is
1078
- ``None``, and ``S`` is an array with singular values for `M`, and
1079
- ``eps`` is the epsilon value for datatype of ``S``, then `tol ` is
1080
- set to ``S.max() * max(M.shape) * eps` `.
1077
+ Threshold below which SVD values are considered zero. Only `tol` or
1078
+ `rtol` can be set at a time. If none of them are provided, defaults
1079
+ to ``S.max() * max(M, N) * eps`` where `S ` is an array with singular
1080
+ values for `A`, and `eps` is the epsilon value for datatype of `S `.
1081
1081
Default: ``None``.
1082
1082
hermitian : bool, optional
1083
1083
If ``True``, `A` is assumed to be Hermitian (symmetric if real-valued),
1084
1084
enabling a more efficient method for finding singular values.
1085
1085
Default: ``False``.
1086
+ rtol : (...) {float, dpnp.ndarray, usm_ndarray}, optional
1087
+ Parameter for the relative tolerance component. Only `tol` or `rtol`
1088
+ can be set at a time. If none of them are provided, defaults to
1089
+ ``max(M, N) * eps`` where `eps` is the epsilon value for datatype
1090
+ of `S` (an array with singular values for `A`).
1091
+ Default: ``None``.
1086
1092
1087
1093
Returns
1088
1094
-------
1089
1095
rank : (...) dpnp.ndarray
1090
- Rank of A .
1096
+ Rank of `A` .
1091
1097
1092
1098
See Also
1093
1099
--------
@@ -1114,8 +1120,12 @@ def matrix_rank(A, tol=None, hermitian=False):
1114
1120
dpnp .check_supported_arrays_type (
1115
1121
tol , scalar_type = True , all_scalars = True
1116
1122
)
1123
+ if rtol is not None :
1124
+ dpnp .check_supported_arrays_type (
1125
+ rtol , scalar_type = True , all_scalars = True
1126
+ )
1117
1127
1118
- return dpnp_matrix_rank (A , tol = tol , hermitian = hermitian )
1128
+ return dpnp_matrix_rank (A , tol = tol , hermitian = hermitian , rtol = rtol )
1119
1129
1120
1130
1121
1131
def matrix_transpose (x , / ):
@@ -1456,7 +1466,7 @@ def outer(x1, x2, /):
1456
1466
return dpnp .outer (x1 , x2 )
1457
1467
1458
1468
1459
- def pinv (a , rcond = 1e-15 , hermitian = False ):
1469
+ def pinv (a , rcond = None , hermitian = False , * , rtol = None ):
1460
1470
"""
1461
1471
Compute the (Moore-Penrose) pseudo-inverse of a matrix.
1462
1472
@@ -1469,20 +1479,27 @@ def pinv(a, rcond=1e-15, hermitian=False):
1469
1479
----------
1470
1480
a : (..., M, N) {dpnp.ndarray, usm_ndarray}
1471
1481
Matrix or stack of matrices to be pseudo-inverted.
1472
- rcond : {float, dpnp.ndarray, usm_ndarray}, optional
1482
+ rcond : (...) {float, dpnp.ndarray, usm_ndarray}, optional
1473
1483
Cutoff for small singular values.
1474
1484
Singular values less than or equal to ``rcond * largest_singular_value``
1475
1485
are set to zero. Broadcasts against the stack of matrices.
1476
- Default: ``1e-15``.
1486
+ Only `rcond` or `rtol` can be set at a time. If none of them are
1487
+ provided, defaults to ``max(M, N) * dpnp.finfo(a.dtype).eps``.
1488
+ Default: ``None``.
1477
1489
hermitian : bool, optional
1478
1490
If ``True``, a is assumed to be Hermitian (symmetric if real-valued),
1479
1491
enabling a more efficient method for finding singular values.
1480
1492
Default: ``False``.
1493
+ rtol : (...) {float, dpnp.ndarray, usm_ndarray}, optional
1494
+ Same as `rcond`, but it's an Array API compatible parameter name.
1495
+ Only `rcond` or `rtol` can be set at a time. If none of them are
1496
+ provided, defaults to ``max(M, N) * dpnp.finfo(a.dtype).eps``.
1497
+ Default: ``None``.
1481
1498
1482
1499
Returns
1483
1500
-------
1484
1501
out : (..., N, M) dpnp.ndarray
1485
- The pseudo-inverse of a .
1502
+ The pseudo-inverse of `a` .
1486
1503
1487
1504
Examples
1488
1505
--------
@@ -1493,17 +1510,24 @@ def pinv(a, rcond=1e-15, hermitian=False):
1493
1510
>>> a = np.random.randn(9, 6)
1494
1511
>>> B = np.linalg.pinv(a)
1495
1512
>>> np.allclose(a, np.dot(a, np.dot(B, a)))
1496
- array([ True] )
1513
+ array(True)
1497
1514
>>> np.allclose(B, np.dot(B, np.dot(a, B)))
1498
- array([ True] )
1515
+ array(True)
1499
1516
1500
1517
"""
1501
1518
1502
1519
dpnp .check_supported_arrays_type (a )
1503
- dpnp .check_supported_arrays_type (rcond , scalar_type = True , all_scalars = True )
1520
+ if rcond is not None :
1521
+ dpnp .check_supported_arrays_type (
1522
+ rcond , scalar_type = True , all_scalars = True
1523
+ )
1524
+ if rtol is not None :
1525
+ dpnp .check_supported_arrays_type (
1526
+ rtol , scalar_type = True , all_scalars = True
1527
+ )
1504
1528
assert_stacked_2d (a )
1505
1529
1506
- return dpnp_pinv (a , rcond = rcond , hermitian = hermitian )
1530
+ return dpnp_pinv (a , rcond = rcond , hermitian = hermitian , rtol = rtol )
1507
1531
1508
1532
1509
1533
def qr (a , mode = "reduced" ):
0 commit comments