Fix the sparse matrix in balancing ROM
A is a sparse matrix in csr_matrix(sparse) format, can not be directly passed into functions used in scipy _solver.py
Sparse matrices do not work well with Scipy (Version 1.7.3) in the following code, so A is transformed into a dense matrix here first.
@@ -96,6 +96,9 @@ def balreal_direct_py(A, B, C, DLTI=True, Schur=False, full_outputs=False):
if Schur:
# decompose A
Atri, U = scalg.schur(A)
+ # A is a sparse matrix in csr_matrix(sparse) format, can not be directly passed into functions used in scipy _solver.py
+ # Sparse matrices do not work well with Scipy (Version 1.7.3) in the following code, so A is transformed into a dense matrix here first.
+ A = A.todense()
# solve Lyapunov
BBtri = np.dot(U.T, np.dot(B, np.dot(B.T, U)))
CCtri = np.dot(U.T, np.dot(C.T, np.dot(C, U)))
@@ -105,6 +108,9 @@ def balreal_direct_py(A, B, C, DLTI=True, Schur=False, full_outputs=False):
Wc = np.dot(U, np.dot(Wctri, U.T))
Wo = np.dot(U, np.dot(Wotri, U.T))
else:
+ # A is a sparse matrix in csr_matrix(sparse) format, can not be directly passed into functions used in scipy _solver.py
+ # Sparse matrices do not work well with Scipy (Version 1.7.3) in the following code, so A is transformed into a dense matrix here first.
+ A = A.todense()
Wc = sollyap(A, np.dot(B, B.T))
Wo = sollyap(A.T, np.dot(C.T, C))
