pylops.FunctionOperator#

class pylops.FunctionOperator(f, *args, **kwargs)[source]#

Function Operator.

Simple wrapper to functions for forward f and adjoint f_c multiplication.

Functions \(f\) and \(f_c\) are such that \(f:\mathbb{F}^m \to \mathbb{F}_c^n\) and \(f_c:\mathbb{F}_c^n \to \mathbb{F}^m\) where \(\mathbb{F}\) and \(\mathbb{F}_c\) are the underlying fields (e.g., \(\mathbb{R}\) for real or \(\mathbb{C}\) for complex)

FunctionOperator can be called in the following ways: FunctionOperator(f, n), FunctionOperator(f, n, m), FunctionOperator(f, fc, n), and FunctionOperator(f, fc, n, m).

The first two methods can only be used for forward modelling and will return NotImplementedError if the adjoint is called. The first and third method assume the matrix (or matrices) to be square. All methods can be called with the dtype keyword argument.

Parameters
fcallable

Function for forward multiplication.

fccallable, optional

Function for adjoint multiplication.

nint, optional

Number of rows (length of data vector).

mint, optional

Number of columns (length of model vector).

dtypestr, optional

Type of elements in input array.

namestr, optional

New in version 2.0.0.

Name of operator (to be used by pylops.utils.describe.describe)

Examples

>>> from pylops.basicoperators import FunctionOperator
>>> def forward(v):
...     return np.array([2*v[0], 3*v[1]])
...
>>> A = FunctionOperator(forward, 2)
>>> A
<2x2 FunctionOperator with dtype=float64>
>>> A.matvec(np.ones(2))
array([2.,  3.])
>>> A @ np.ones(2)
array([2.,  3.])
Attributes
shapetuple

Operator shape \([n \times m]\)

explicitbool

Operator contains a matrix that can be solved explicitly (True) or not (False)

Methods

__init__(f, *args, **kwargs)

adjoint()

apply_columns(cols)

Apply subset of columns of operator

cond([uselobpcg])

Condition number of linear operator.

conj()

Complex conjugate operator

div(y[, niter, densesolver])

Solve the linear problem \(\mathbf{y}=\mathbf{A}\mathbf{x}\).

dot(x)

Matrix-matrix or matrix-vector multiplication.

eigs([neigs, symmetric, niter, uselobpcg])

Most significant eigenvalues of linear operator.

matmat(X)

Matrix-matrix multiplication.

matvec(x)

Matrix-vector multiplication.

reset_count()

Reset counters

rmatmat(X)

Matrix-matrix multiplication.

rmatvec(x)

Adjoint matrix-vector multiplication.

todense([backend])

Return dense matrix.

toimag([forw, adj])

Imag operator

toreal([forw, adj])

Real operator

tosparse()

Return sparse matrix.

trace([neval, method, backend])

Trace of linear operator.

transpose()