nifty8.operators.matrix_product_operator module#

class MatrixProductOperator(domain, matrix, spaces=None, flatten=False)[source]#

Bases: EndomorphicOperator

Endomorphic matrix multiplication with input field.

This operator supports scipy.sparse matrices and numpy arrays as the matrix to be applied.

For numpy array matrices, can apply the matrix over a subspace of the input.

If the input arrays have more than one dimension, for scipy.sparse matrices the flatten keyword argument must be set to true. This means that the input field will be flattened before applying the matrix and reshaped to its original shape afterwards.

Matrices are tested regarding their compatibility with the called for application method.

Flattening and subspace application are mutually exclusive.

Parameters:
  • domain (Domain or DomainTuple) – Domain of the operator. If DomainTuple it is assumed to have only one entry.

  • matrix (scipy.sparse.spmatrix or numpy.ndarray) – Quadratic matrix of shape (domain.shape, domain.shape) (if not flatten) that supports matrix.transpose(). If it is not a numpy array, needs to be applicable to the val array of input fields by matrix.dot().

  • spaces (int or tuple of int, optional) – The subdomain(s) of “domain” which the operator acts on. If None, it acts on all elements. Only possible for numpy array matrices. If len(domain) > 1 and flatten=False, this parameter is mandatory.

  • flatten (boolean, optional) – Whether the input value array should be flattened before applying the matrix and reshaped to its original shape afterwards. Needed for scipy.sparse matrices if len(domain) > 1.

__init__(domain, matrix, spaces=None, flatten=False)[source]#
apply(x, mode)[source]#

Applies the Operator to a given x, in a specified mode.

Parameters:
  • x (nifty8.field.Field) – The input Field, defined on the Operator’s domain or target, depending on mode.

  • mode (int) –

    • TIMES: normal application

    • ADJOINT_TIMES: adjoint application

    • INVERSE_TIMES: inverse application

    • ADJOINT_INVERSE_TIMES or INVERSE_ADJOINT_TIMES: adjoint inverse application

Returns:

The processed Field defined on the Operator’s target or domain, depending on mode.

Return type:

nifty8.field.Field