GeFEM Spmat object
Create a new sparse matrix in getfem++ format. These sparse matrix can be stored as CSC (compressed column sparse), which is the format used by Matlab, or they can be stored as WSC (internal format to getfem). The CSC matrices are not writable (it would be very inefficient), but they are optimized for multiplication with vectors, and memory usage. The WSC are writable, they are very fast with respect to random read/write operation. However their memory overhead is higher than CSC matrices, and they are a little bit slower for matrix-vector multiplications.
By default, all newly created matrices are build as WSC matrices. This can be changed later with Spmat.to_csc(...), or may be changed automatically by getfem (for example gf_linsolve() converts the matrices to CSC).
The matrices may store REAL or COMPLEX values.
General constructor for Spmat objects
SM = Spmat('empty', int m [, int n]) Create a new empty (i.e. full of zeros) sparse matrix, of dimensions m x n. If n is omitted, the matrix dimension is m x m.
SM = Spmat('copy', mat K [, list I [, list J]]) Duplicate a matrix K (which might be a SpMat). If index I and/or J are given, the matrix will be a submatrix of K. For example:
m = Spmat('copy', Spmat('empty',50,50), range(40), [6, 7, 8, 3, 10])
will return a 40x5 matrix.
SM = Spmat('identity', int n) Create a n x n identity matrix.
SM = Spmat('mult', Spmat A, Spmat B) Create a sparse matrix as the product of the sparse matrices A and B. It requires that A and B be both real or both complex, you may have to use Spmat.to_complex()
SM = Spmat('add', Spmat A, Spmat B) Create a sparse matrix as the sum of the sparse matrices A and B. Adding a real matrix with a complex matrix is possible.
SM = Spmat('diag', mat D [, ivec E [, int n [,int m]]]) Create a diagonal matrix. If E is given, D might be a matrix and each column of E will contain the sub-diagonal number that will be filled with the corresponding column of D.
SM = Spmat('load','hb'|'harwell-boeing'|'mm'|'matrix-market', string filename) Read a sparse matrix from an Harwell-Boeing or a Matrix-Market file .
Add V to the sub-matrix ‘M(I,J)’.
V might be a sparse matrix or a full matrix.
Copy V into the sub-matrix ‘M(I,J)’.
V might be a sparse matrix or a full matrix.
Output a (unique) string representation of the Spmat.
This can be used to perform comparisons between two different Spmat objects. This function is to be completed.
Synopsis: Spmat.clear(self[, list I[, list J]])
Erase the non-zero entries of the matrix.
The optional arguments I and J may be specified to clear a sub-matrix instead of the entire matrix.
Conjugate each element of the matrix.
Return the two usual index arrays of CSC storage.
If M is not stored as a CSC matrix, it is converted into CSC.
Return the array of values of all non-zero entries of M.
If M is not stored as a CSC matrix, it is converted into CSC.
returns the matrix determinant calculated using MUMPS.
Return the diagonal of M as a vector.
If E is used, return the sub-diagonals whose ranks are given in E.
Solve the dirichlet conditions M.U=R.
A solution U0 which has a minimum L2-norm is returned, with a sparse matrix N containing an orthogonal basis of the kernel of the (assembled) constraints matrix M (hence, the PDE linear system should be solved on this subspace): the initial problem
K.U = B with constraints M.U = R
is replaced by
(N’.K.N).UU = N’.B with U = N.UU + U0
displays a short summary for a Spmat object.
Synopsis: Sm = Spmat.full(self[, list I[, list J]])
Return a full (sub-)matrix.
The optional arguments I and J, are the sub-intervals for the rows and columns that are to be extracted.
Return 1 if the matrix contains complex values.
Product of the sparse matrix M with a vector V.
For matrix-matrix multiplications, see Spmat(‘mult’).
Return the number of non-null values stored in the sparse matrix.
Export the sparse matrix.
the format of the file may be ‘hb’ for Harwell-Boeing, or ‘mm’ for Matrix-Market.
Multiplies the matrix by a scalar value v.
Change the diagonal (or sub-diagonals) of the matrix.
If E is given, D might be a matrix and each column of E will contain the sub-diagonal number that will be filled with the corresponding column of D.
Return a vector where ni and nj are the dimensions of the matrix.
Return the storage type currently used for the matrix.
The storage is returned as a string, either ‘CSC’ or ‘WSC’.
Product of M transposed (conjugated if M is complex) with the vector V.
Store complex numbers.
Convert the matrix to CSC storage.
CSC storage is recommended for matrix-vector multiplications.
Convert the matrix to WSC storage.
Read and write operation are quite fast with WSC storage.
Transpose and conjugate the matrix.
Transpose the matrix.