@@ -197,7 +197,11 @@ def _assert_stacked_2d(*arrays):
197
197
198
198
def _assert_stacked_square (* arrays ):
199
199
for a in arrays :
200
- m , n = a .shape [- 2 :]
200
+ try :
201
+ m , n = a .shape [- 2 :]
202
+ except ValueError :
203
+ raise LinAlgError ('%d-dimensional array given. Array must be '
204
+ 'at least two-dimensional' % a .ndim )
201
205
if m != n :
202
206
raise LinAlgError ('Last 2 dimensions of the array must be square' )
203
207
@@ -392,7 +396,6 @@ def solve(a, b):
392
396
393
397
"""
394
398
a , _ = _makearray (a )
395
- _assert_stacked_2d (a )
396
399
_assert_stacked_square (a )
397
400
b , wrap = _makearray (b )
398
401
t , result_t = _commonType (a , b )
@@ -599,7 +602,6 @@ def inv(a):
599
602
600
603
"""
601
604
a , wrap = _makearray (a )
602
- _assert_stacked_2d (a )
603
605
_assert_stacked_square (a )
604
606
t , result_t = _commonType (a )
605
607
@@ -681,7 +683,6 @@ def matrix_power(a, n):
681
683
682
684
"""
683
685
a = asanyarray (a )
684
- _assert_stacked_2d (a )
685
686
_assert_stacked_square (a )
686
687
687
688
try :
@@ -830,7 +831,6 @@ def cholesky(a, /, *, upper=False):
830
831
"""
831
832
gufunc = _umath_linalg .cholesky_up if upper else _umath_linalg .cholesky_lo
832
833
a , wrap = _makearray (a )
833
- _assert_stacked_2d (a )
834
834
_assert_stacked_square (a )
835
835
t , result_t = _commonType (a )
836
836
signature = 'D->D' if isComplexType (t ) else 'd->d'
@@ -1201,7 +1201,6 @@ def eigvals(a):
1201
1201
1202
1202
"""
1203
1203
a , wrap = _makearray (a )
1204
- _assert_stacked_2d (a )
1205
1204
_assert_stacked_square (a )
1206
1205
_assert_finite (a )
1207
1206
t , result_t = _commonType (a )
@@ -1310,7 +1309,6 @@ def eigvalsh(a, UPLO='L'):
1310
1309
gufunc = _umath_linalg .eigvalsh_up
1311
1310
1312
1311
a , wrap = _makearray (a )
1313
- _assert_stacked_2d (a )
1314
1312
_assert_stacked_square (a )
1315
1313
t , result_t = _commonType (a )
1316
1314
signature = 'D->d' if isComplexType (t ) else 'd->d'
@@ -1320,11 +1318,6 @@ def eigvalsh(a, UPLO='L'):
1320
1318
w = gufunc (a , signature = signature )
1321
1319
return w .astype (_realType (result_t ), copy = False )
1322
1320
1323
- def _convertarray (a ):
1324
- t , result_t = _commonType (a )
1325
- a = a .astype (t ).T .copy ()
1326
- return a , t , result_t
1327
-
1328
1321
1329
1322
# Eigenvectors
1330
1323
@@ -1461,7 +1454,6 @@ def eig(a):
1461
1454
1462
1455
"""
1463
1456
a , wrap = _makearray (a )
1464
- _assert_stacked_2d (a )
1465
1457
_assert_stacked_square (a )
1466
1458
_assert_finite (a )
1467
1459
t , result_t = _commonType (a )
@@ -1612,7 +1604,6 @@ def eigh(a, UPLO='L'):
1612
1604
raise ValueError ("UPLO argument must be 'L' or 'U'" )
1613
1605
1614
1606
a , wrap = _makearray (a )
1615
- _assert_stacked_2d (a )
1616
1607
_assert_stacked_square (a )
1617
1608
t , result_t = _commonType (a )
1618
1609
@@ -1978,7 +1969,6 @@ def cond(x, p=None):
1978
1969
else :
1979
1970
# Call inv(x) ignoring errors. The result array will
1980
1971
# contain nans in the entries where inversion failed.
1981
- _assert_stacked_2d (x )
1982
1972
_assert_stacked_square (x )
1983
1973
t , result_t = _commonType (x )
1984
1974
signature = 'D->D' if isComplexType (t ) else 'd->d'
@@ -2318,7 +2308,6 @@ def slogdet(a):
2318
2308
2319
2309
"""
2320
2310
a = asarray (a )
2321
- _assert_stacked_2d (a )
2322
2311
_assert_stacked_square (a )
2323
2312
t , result_t = _commonType (a )
2324
2313
real_t = _realType (result_t )
@@ -2377,7 +2366,6 @@ def det(a):
2377
2366
2378
2367
"""
2379
2368
a = asarray (a )
2380
- _assert_stacked_2d (a )
2381
2369
_assert_stacked_square (a )
2382
2370
t , result_t = _commonType (a )
2383
2371
signature = 'D->D' if isComplexType (t ) else 'd->d'
0 commit comments