pg_utils.pg_model.expansion.SystemMatrix
- class pg_utils.pg_model.expansion.SystemMatrix(*args, **kwargs)[source]
Bases:
object
System matrix
This is a wrapper for a matrix of symbolic expression (inner products) whose numerical values will be evaluated numerically. This is one of the final outcomes of the symbolic computation.
- Variables:
_row_names (List[str]) – list of names corresponding to each row (block)
_row_idx (dict) – dict that maps row name to their index
_col_names (List[str]) – list of names corresponding to each col (block)
_col_idx (dict) – dict that maps col names to their index
_matrix (array-like) – a nested list representing the matrix
- __init__(*args, **kwargs) None [source]
Initialization
There are currently two modes of initialization.
If the first argument is a
base.LabeledCollection
instance, it will be interpreted as a collection of expressions; the second argument is then interpreted as the collection of coefficients. The signaure is SystemMatrix(expressions, coefficients). TheSystemMatrix
will be constructed by invoking theSystemMatrix.build_matrix
methodOtherwise, the arguments will be interpreted as the row names, column names and matrix of expressions, respectively. The signature is SystemMatrix(row_names, col_names, matrix)
Methods
__init__
(*args, **kwargs)Initialization
apply
(fun[, inplace, metadata])Apply function to elements iteratively.
Give the sparsity pattern of the symbolic matrix
build_matrix
(exprs, coeffs)Build system matrix from a collection of expressions
deserialize
(matrix_obj)Construct system matrix from object
load_json
(fp)Load from json file
load_serialized_element
(element)save_json
(fp)Save to json file
Serialize object
serialize_element
(element)Serialize an element
- apply(fun: Callable, inplace: bool = False, metadata: bool = False) SystemMatrix [source]
Apply function to elements iteratively.
- block_sparsity()[source]
Give the sparsity pattern of the symbolic matrix
- Returns:
sparsity matrix. If an element of the SystemMatrix is zero or None, then it will be marked as False in the output; otherwise it will be marked as True.
- Return type:
numpy.ndarray
- static build_matrix(exprs: LabeledCollection, coeffs: LabeledCollection) List [source]
Build system matrix from a collection of expressions
- Parameters:
exprs (base.LabeledCollection) – collection of expressions each element is a sympy.Expr instance
coeffs (base.LabeledCollection) – collection of coefficients each element is a sympy.Symbol instance
Warning
Whatever term in exprs that does not contain a coefficient included in the coeffs collection will be discarded in the process!
- static deserialize(matrix_obj: List[List]) SystemMatrix [source]
Construct system matrix from object
- static load_json(fp: TextIO) SystemMatrix [source]
Load from json file