23
23
csingle , cdouble , inexact , complexfloating , newaxis , ravel , all , Inf , dot ,
24
24
add , multiply , sqrt , maximum , fastCopyAndTranspose , sum , isfinite , size ,
25
25
finfo , errstate , geterrobj , longdouble , rollaxis , amin , amax , product , abs ,
26
- broadcast , atleast_2d , intp , asanyarray
26
+ broadcast , atleast_2d , intp , asanyarray , isscalar
27
27
)
28
28
from numpy .lib import triu , asfarray
29
29
from numpy .linalg import lapack_lite , _umath_linalg
@@ -382,7 +382,7 @@ def solve(a, b):
382
382
extobj = get_linalg_error_extobj (_raise_linalgerror_singular )
383
383
r = gufunc (a , b , signature = signature , extobj = extobj )
384
384
385
- return wrap (r .astype (result_t ))
385
+ return wrap (r .astype (result_t , copy = False ))
386
386
387
387
388
388
def tensorinv (a , ind = 2 ):
@@ -522,7 +522,7 @@ def inv(a):
522
522
signature = 'D->D' if isComplexType (t ) else 'd->d'
523
523
extobj = get_linalg_error_extobj (_raise_linalgerror_singular )
524
524
ainv = _umath_linalg .inv (a , signature = signature , extobj = extobj )
525
- return wrap (ainv .astype (result_t ))
525
+ return wrap (ainv .astype (result_t , copy = False ))
526
526
527
527
528
528
# Cholesky decomposition
@@ -606,7 +606,8 @@ def cholesky(a):
606
606
_assertNdSquareness (a )
607
607
t , result_t = _commonType (a )
608
608
signature = 'D->D' if isComplexType (t ) else 'd->d'
609
- return wrap (gufunc (a , signature = signature , extobj = extobj ).astype (result_t ))
609
+ r = gufunc (a , signature = signature , extobj = extobj )
610
+ return wrap (r .astype (result_t , copy = False ))
610
611
611
612
# QR decompostion
612
613
@@ -781,7 +782,7 @@ def qr(a, mode='reduced'):
781
782
782
783
if mode == 'economic' :
783
784
if t != result_t :
784
- a = a .astype (result_t )
785
+ a = a .astype (result_t , copy = False )
785
786
return wrap (a .T )
786
787
787
788
# generate q from a
@@ -908,7 +909,7 @@ def eigvals(a):
908
909
else :
909
910
result_t = _complexType (result_t )
910
911
911
- return w .astype (result_t )
912
+ return w .astype (result_t , copy = False )
912
913
913
914
def eigvalsh (a , UPLO = 'L' ):
914
915
"""
@@ -978,7 +979,7 @@ def eigvalsh(a, UPLO='L'):
978
979
t , result_t = _commonType (a )
979
980
signature = 'D->d' if isComplexType (t ) else 'd->d'
980
981
w = gufunc (a , signature = signature , extobj = extobj )
981
- return w .astype (_realType (result_t ))
982
+ return w .astype (_realType (result_t ), copy = False )
982
983
983
984
def _convertarray (a ):
984
985
t , result_t = _commonType (a )
@@ -1124,8 +1125,8 @@ def eig(a):
1124
1125
else :
1125
1126
result_t = _complexType (result_t )
1126
1127
1127
- vt = vt .astype (result_t )
1128
- return w .astype (result_t ), wrap (vt )
1128
+ vt = vt .astype (result_t , copy = False )
1129
+ return w .astype (result_t , copy = False ), wrap (vt )
1129
1130
1130
1131
1131
1132
def eigh (a , UPLO = 'L' ):
@@ -1232,8 +1233,8 @@ def eigh(a, UPLO='L'):
1232
1233
1233
1234
signature = 'D->dD' if isComplexType (t ) else 'd->dd'
1234
1235
w , vt = gufunc (a , signature = signature , extobj = extobj )
1235
- w = w .astype (_realType (result_t ))
1236
- vt = vt .astype (result_t )
1236
+ w = w .astype (_realType (result_t ), copy = False )
1237
+ vt = vt .astype (result_t , copy = False )
1237
1238
return w , wrap (vt )
1238
1239
1239
1240
@@ -1344,9 +1345,9 @@ def svd(a, full_matrices=1, compute_uv=1):
1344
1345
1345
1346
signature = 'D->DdD' if isComplexType (t ) else 'd->ddd'
1346
1347
u , s , vt = gufunc (a , signature = signature , extobj = extobj )
1347
- u = u .astype (result_t )
1348
- s = s .astype (_realType (result_t ))
1349
- vt = vt .astype (result_t )
1348
+ u = u .astype (result_t , copy = False )
1349
+ s = s .astype (_realType (result_t ), copy = False )
1350
+ vt = vt .astype (result_t , copy = False )
1350
1351
return wrap (u ), s , wrap (vt )
1351
1352
else :
1352
1353
if m < n :
@@ -1356,7 +1357,7 @@ def svd(a, full_matrices=1, compute_uv=1):
1356
1357
1357
1358
signature = 'D->d' if isComplexType (t ) else 'd->d'
1358
1359
s = gufunc (a , signature = signature , extobj = extobj )
1359
- s = s .astype (_realType (result_t ))
1360
+ s = s .astype (_realType (result_t ), copy = False )
1360
1361
return s
1361
1362
1362
1363
def cond (x , p = None ):
@@ -1695,7 +1696,15 @@ def slogdet(a):
1695
1696
real_t = _realType (result_t )
1696
1697
signature = 'D->Dd' if isComplexType (t ) else 'd->dd'
1697
1698
sign , logdet = _umath_linalg .slogdet (a , signature = signature )
1698
- return sign .astype (result_t ), logdet .astype (real_t )
1699
+ if isscalar (sign ):
1700
+ sign = sign .astype (result_t )
1701
+ else :
1702
+ sign = sign .astype (result_t , copy = False )
1703
+ if isscalar (logdet ):
1704
+ logdet = logdet .astype (real_t )
1705
+ else :
1706
+ logdet = logdet .astype (real_t , copy = False )
1707
+ return sign , logdet
1699
1708
1700
1709
def det (a ):
1701
1710
"""
@@ -1749,7 +1758,12 @@ def det(a):
1749
1758
_assertNdSquareness (a )
1750
1759
t , result_t = _commonType (a )
1751
1760
signature = 'D->D' if isComplexType (t ) else 'd->d'
1752
- return _umath_linalg .det (a , signature = signature ).astype (result_t )
1761
+ r = _umath_linalg .det (a , signature = signature )
1762
+ if isscalar (r ):
1763
+ r = r .astype (result_t )
1764
+ else :
1765
+ r = r .astype (result_t , copy = False )
1766
+ return r
1753
1767
1754
1768
# Linear Least Squares
1755
1769
@@ -1905,12 +1919,12 @@ def lstsq(a, b, rcond=-1):
1905
1919
if results ['rank' ] == n and m > n :
1906
1920
if isComplexType (t ):
1907
1921
resids = sum (abs (transpose (bstar )[n :,:])** 2 , axis = 0 ).astype (
1908
- result_real_t )
1922
+ result_real_t , copy = False )
1909
1923
else :
1910
1924
resids = sum ((transpose (bstar )[n :,:])** 2 , axis = 0 ).astype (
1911
- result_real_t )
1925
+ result_real_t , copy = False )
1912
1926
1913
- st = s [:min (n , m )].copy (). astype (result_real_t )
1927
+ st = s [:min (n , m )].astype (result_real_t , copy = True )
1914
1928
return wrap (x ), wrap (resids ), results ['rank' ], st
1915
1929
1916
1930
0 commit comments