pylops_gpu.LinearOperator¶
-
class
pylops_gpu.
LinearOperator
(shape, dtype, Op=None, explicit=False, device='cpu', togpu=(False, False), tocpu=(False, False))[source]¶ Common interface for performing matrix-vector products.
This class is an overload of the
pylops.LinearOperator
class. It adds functionalities for operators on GPUs; specifically, it allows users specifying when to move model and data from the host to the device and viceversa.Compared to its equivalent PyLops class
pylops.LinearOperator
, it requires input model and data to betorch.Tensor
objects.Note
End users of PyLops should not use this class directly but simply use operators that are already implemented. This class is meant for developers and it has to be used as the parent class of any new operator developed within PyLops-gpu. Find more details regarding implementation of new operators at Implementing new operators.
Parameters: - shape :
tuple
Operator shape
- dtype :
torch.dtype
, optional Type of elements in input array.
- Op :
pylops.LinearOperator
Operator to wrap in
LinearOperator
(ifNone
, self must implement_matvec_
and_rmatvec_
)- explicit :
bool
Operator contains a matrix that can be solved explicitly (
True
) or not (False
)- device :
str
, optional Device to be used
- togpu :
tuple
, optional Move model and data from cpu to gpu prior to applying
matvec
andrmatvec
, respectively (only whendevice='gpu'
)- tocpu :
tuple
, optional Move data and model from gpu to cpu after applying
matvec
andrmatvec
, respectively (only whendevice='gpu'
)
Methods
__init__
(shape, dtype[, Op, explicit, …])Initialize this LinearOperator. adjoint
()Hermitian adjoint. apply_columns
(cols)Apply subset of columns of operator cond
([uselobpcg])Condition number of linear operator. conj
()Complex conjugate operator div
(y[, niter, tol])Solve the linear problem \(\mathbf{y}=\mathbf{A}\mathbf{x}\). dot
(x)Matrix-vector multiplication. eigs
([neigs, symmetric, niter, uselobpcg])Most significant eigenvalues of linear operator. matmat
(X[, kfirst])Matrix-matrix multiplication. matvec
(x)Matrix-vector multiplication. rmatmat
(X[, kfirst])Adjoint 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. transpose
()Transpose this linear operator. -
matvec
(x)[source]¶ Matrix-vector multiplication.
Performs the operation
y = A * x
where A is an \(N \times M\) linear operator andx
is a 1-d array.Parameters: - x :
torch.Tensor
An array with shape (M,)
Returns: - y :
torch.Tensor
An array with shape (N,)
- x :
-
rmatvec
(x)[source]¶ Adjoint matrix-vector multiplication.
Performs the operation
y = A^H * x
where A is an \(N imes M\) linear operator andx
is a 1-d array.Parameters: - x :
torch.Tensor
An array with shape (N,)
Returns: - y :
torch.Tensor
An array with shape (M,)
- x :
-
matmat
(X, kfirst=False)[source]¶ Matrix-matrix multiplication.
Performs the operation
Y = A * X
where A is an \(N imes M\) linear operator andX
is a 2-d array of size \(K imes M\) (kfirst=True
) or \(M imes K\) (kfirst=False
).Parameters: - x :
torch.Tensor
An array with shape (M, K) or (K, M)
- kfirst :
bool
, optional Dimension
K
along which the matrix multiplication is performed is in the first dimension (True
) or in the second dimension (False
)
Returns: - y :
torch.Tensor
An array with shape (N, K) or (K, N)
- x :
-
rmatmat
(X, kfirst=False)[source]¶ Adjoint matrix-matrix multiplication.
Performs the operation
Y = A^H * X
where A is an \(N imes M\) linear operator andX
is a 2-d array of size \(K imes N\) (kfirst=True
) or \(N imes K\) (kfirst=False
).Parameters: - x :
torch.Tensor
An array with shape (N, K) or (K, N)
- kfirst :
bool
, optional Dimension
K
along which the matrix multiplication is performed is in the first dimension (True
) or in the second dimension (False
)
Returns: - y :
torch.Tensor
An array with shape (M, K) or (K, M)
- x :
-
dot
(x)[source]¶ Matrix-vector multiplication.
Parameters: - x :
torch.Tensor
orpytorch_complex_tensor.ComplexTensor
1-d or 2-d array, representing a vector or matrix.
Returns: - Ax :
torch.Tensor
orpytorch_complex_tensor.ComplexTensor
1-d or 2-d array (depending on the shape of x) that represents the result of applying this linear operator on x.
- x :
-
adjoint
()[source]¶ Hermitian adjoint.
Returns the Hermitian adjoint. Can be abbreviated self.H instead of self.adjoint().
-
H
¶ Hermitian adjoint.
Returns the Hermitian adjoint. Can be abbreviated self.H instead of self.adjoint().
-
div
(y, niter=100, tol=0.0001)[source]¶ Solve the linear problem \(\mathbf{y}=\mathbf{A}\mathbf{x}\).
Overloading of operator
/
to improve expressivity of Pylops_gpu when solving inverse problems.Parameters: - y :
torch.Tensor
Data
- niter :
int
, optional Number of iterations (to be used only when
explicit=False
)- tol :
int
Residual norm tolerance
Returns: - xest :
np.ndarray
Estimated model
- y :
- shape :