fixing: Determinant function raises TypeError on simple matrix #542
This commit is contained in:
@@ -539,6 +539,8 @@ class LinearAlgebraMethods:
|
||||
try:
|
||||
# do not overwrite A
|
||||
A = ctx.matrix(A).copy()
|
||||
if any(all(ctx.almosteq(0, x) for x in A[:, c]) for c in range(A.cols)):
|
||||
return 0 * A[0, 0]
|
||||
# use LU factorization to calculate determinant
|
||||
try:
|
||||
R, p = ctx.LU_decomp(A)
|
||||
|
||||
@@ -69,6 +69,9 @@ A10 = matrix([[1.0 + 1.0j, 2.0, 2.0],
|
||||
[4.0, 5.0, 6.0],
|
||||
[7.0, 8.0, 9.0]])
|
||||
b10 = [1.0, 1.0 + 1.0j, 1.0]
|
||||
A11 = matrix([[4, 0, -2],
|
||||
[2, 0, -4],
|
||||
[2, 0, 5.5]])
|
||||
|
||||
|
||||
def test_LU_decomp():
|
||||
@@ -193,6 +196,8 @@ def test_det():
|
||||
assert det(A5) == 1
|
||||
assert round(det(A6)) == 78356463
|
||||
assert det(zeros(3)) == 0
|
||||
assert det(A11) == 0
|
||||
|
||||
|
||||
def test_cond():
|
||||
A = matrix([[1.2969, 0.8648], [0.2161, 0.1441]])
|
||||
|
||||
Reference in New Issue
Block a user