@@ -1256,11 +1256,16 @@ def pinv(a, cond=None, rcond=None, return_rank=False, check_finite=True):
1256
1256
a : (M, N) array_like
1257
1257
Matrix to be pseudo-inverted.
1258
1258
cond, rcond : float, optional
1259
- Cutoff for 'small' singular values in the least-squares solver.
1260
- Singular values smaller than ``rcond * largest_singular_value``
1261
- are considered zero.
1262
- If None, it is set to ``np.finfo(a.dtype).eps``.
1263
- If `a` is an array of integers, it is set to ``np.finfo('float64').eps``.
1259
+ Cutoff factor for 'small' singular values. In `lstsq`,
1260
+ singular values less than ``cond*largest_singular_value`` will be
1261
+ considered as zero. If both are omitted, the default value
1262
+ ``max(M, N) * eps`` is passed to `lstsq` where ``eps`` is the
1263
+ corresponding machine precision value of the datatype of ``a``.
1264
+
1265
+ .. versionchanged:: 1.3.0
1266
+ Previously the default cutoff value was just `eps` without the
1267
+ factor ``max(M, N)``.
1268
+
1264
1269
return_rank : bool, optional
1265
1270
if True, return the effective rank of the matrix
1266
1271
check_finite : bool, optional
@@ -1293,9 +1298,13 @@ def pinv(a, cond=None, rcond=None, return_rank=False, check_finite=True):
1293
1298
"""
1294
1299
a = _asarray_validated (a , check_finite = check_finite )
1295
1300
b = np .identity (a .shape [0 ], dtype = a .dtype )
1301
+
1296
1302
if rcond is not None :
1297
1303
cond = rcond
1298
1304
1305
+ if cond is None :
1306
+ cond = max (a .shape ) * np .spacing (a .real .dtype .type (1 ))
1307
+
1299
1308
x , resids , rank , s = lstsq (a , b , cond = cond , check_finite = False )
1300
1309
1301
1310
if return_rank :
@@ -1317,12 +1326,15 @@ def pinv2(a, cond=None, rcond=None, return_rank=False, check_finite=True):
1317
1326
a : (M, N) array_like
1318
1327
Matrix to be pseudo-inverted.
1319
1328
cond, rcond : float or None
1320
- Cutoff for 'small' singular values.
1321
- Singular values smaller than ``rcond*largest_singular_value``
1322
- are considered zero.
1323
- If None and the dtype of `a` is ``np.float32``, it is set to
1324
- ``np.finfo('float32').eps * 1e3``.
1325
- Otherwise, it is set to ``np.finfo('float64').eps * 1e6``.
1329
+ Cutoff for 'small' singular values; singular values smaller than this
1330
+ value are considered as zero. If both are omitted, the default value
1331
+ ``max(M,N)*largest_singular_value*eps`` is used where ``eps`` is the
1332
+ machine precision value of the datatype of ``a``.
1333
+
1334
+ .. versionchanged:: 1.3.0
1335
+ Previously the default cutoff value was just ``eps*f`` where ``f``
1336
+ was ``1e3`` for single precision and ``1e6`` for double precision.
1337
+
1326
1338
return_rank : bool, optional
1327
1339
If True, return the effective rank of the matrix.
1328
1340
check_finite : bool, optional
@@ -1360,10 +1372,9 @@ def pinv2(a, cond=None, rcond=None, return_rank=False, check_finite=True):
1360
1372
cond = rcond
1361
1373
if cond in [None , - 1 ]:
1362
1374
t = u .dtype .char .lower ()
1363
- factor = {'f' : 1E3 , 'd' : 1E6 }
1364
- cond = factor [t ] * np .finfo (t ).eps
1375
+ cond = np .max (s ) * max (a .shape ) * np .finfo (t ).eps
1365
1376
1366
- rank = np .sum (s > cond * np . max ( s ) )
1377
+ rank = np .sum (s > cond )
1367
1378
1368
1379
u = u [:, :rank ]
1369
1380
u /= s [:rank ]
@@ -1389,12 +1400,15 @@ def pinvh(a, cond=None, rcond=None, lower=True, return_rank=False,
1389
1400
a : (N, N) array_like
1390
1401
Real symmetric or complex hermetian matrix to be pseudo-inverted
1391
1402
cond, rcond : float or None
1392
- Cutoff for 'small' singular values.
1393
- Singular values smaller than ``rcond*largest_singular_value``
1394
- are considered zero.
1395
- If None and the dtype of `a` is ``np.float32``, it is set to
1396
- ``np.finfo('float32').eps * 1e3``.
1397
- Otherwise, it is set to ``np.finfo('float64').eps * 1e6``.
1403
+ Cutoff for 'small' singular values; singular values smaller than this
1404
+ value are considered as zero. If both are omitted, the default
1405
+ ``max(M,N)*largest_eigenvalue*eps`` is used where ``eps`` is the
1406
+ machine precision value of the datatype of
6D40
``a``.
1407
+
1408
+ .. versionchanged:: 1.3.0
1409
+ Previously the default cutoff value was just ``eps*f`` where ``f``
1410
+ was ``1e3`` for single precision and ``1e6`` for double precision.
1411
+
1398
1412
lower : bool, optional
1399
1413
Whether the pertinent array data is taken from the lower or upper
1400
1414
triangle of `a`. (Default: lower)
@@ -1436,11 +1450,10 @@ def pinvh(a, cond=None, rcond=None, lower=True, return_rank=False,
1436
1450
cond = rcond
1437
1451
if cond in [None , - 1 ]:
1438
1452
t = u .dtype .char .lower ()
1439
- factor = {'f' : 1E3 , 'd' : 1E6 }
1440
- cond = factor [t ] * np .finfo (t ).eps
1453
+ cond = np .max (np .abs (s )) * max (a .shape ) * np .finfo (t ).eps
1441
1454
1442
1455
# For Hermitian matrices, singular values equal abs(eigenvalues)
1443
- above_cutoff = (abs (s ) > cond * np . max ( abs ( s )) )
1456
+ above_cutoff = (abs (s ) > cond )
1444
1457
psigma_diag = 1.0 / s [above_cutoff ]
1445
1458
u = u [:, above_cutoff ]
1446
1459
0 commit comments