Iterative solution of sparse systems of linear equations with (M, N) matrix of the right size

I would like to solve a system of sparse linear equations: A x = b , where A is an array (M x M), b is an array (M x N) and x is and (M x N).

I solve this in three ways using:

  • scipy.linalg.solve(A.toarray(), b.toarray()),
  • scipy.sparse.linalg.spsolve(A, b),
  • scipy.sparse.linalg.splu(A).solve(b.toarray()) # returns a dense array

I want to solve the problem using iterative methods scipy.sparse.linalg:

  • scipy.sparse.linalg.cg,
  • scipy.sparse.linalg.bicg,
  • ...

However, the methods support only the right side b with the form (M,) or (M, 1). Any ideas on how to extend these methods to an array (M x N) b ?

+4
2

, , ( Cholesky LU), . , .

, , , API cg, bicg ..

scipy.sparse.linalg.spsolve, , . - - , :

from scipy.sparse.linalg import bicg

def bicg_solve(M, B):
    X, info = zip(*(bicg(M, b) for b in B.T))
    return np.transpose(X), info

:

import numpy as np
from scipy.sparse import csc_matrix

# create some matrices
M = csc_matrix(np.random.rand(5, 5))
B = np.random.rand(5, 4)

X, info = bicg_solve(M, B)
print(X.shape)
# (5, 4)

API, , - .

+6

( ), , (LU-, LDLt- ..), - . . , - , , , . . , :

http://members.ozemail.com.au/~comecau/CMA_Sparse.htm

, ( - ).

0

Source: https://habr.com/ru/post/1614563/


All Articles