Linear operators API#
Linear operators represent maps between spaces with forward and adjoint actions.
Minimal linear operator (morphism) between two spaces. |
|
Base class for linear operators assembled from component operators. |
|
Dense linear operator defined by an array A with shape: |
|
Sparse linear operator implementing the tensor map A : dom -> cod where conceptually A has shape cod.shape + dom.shape, but stored as a 2D sparse matrix: |
|
Block-diagonal operator between product spaces. |
|
Stack of operators from a single domain into a product codomain. |
|
Sum of component operators from a product domain into a single codomain. |
LinOp#
- class spacecore.linop.LinOp(dom, cod, ctx=None)[source]#
Bases:
ContextBound,Generic[Domain,Codomain]Minimal linear operator (morphism) between two spaces.
This class is intentionally small. It defines no matrix semantics, arithmetic, or storage assumptions.
Its sole purpose is to represent a linear map
A : dom -> codwith access to both forward and adjoint actions.- Parameters:
dom (Domain)
cod (Codomain)
ctx (Context | str | None)
- abstractmethod apply(x)[source]#
Forward application: y = A x
- Contract:
x is an element of self.dom
return value is an element of self.cod
- Parameters:
x (Any)
- Return type:
Any
- abstractmethod rapply(y)[source]#
Adjoint application: x = A^* y
- Contract:
y is an element of self.cod
return value is an element of self.dom
- Parameters:
y (Any)
- Return type:
Any
- property dtype: Any#
- property ops: BackendOps#
ProductLinOp#
- class spacecore.linop.ProductLinOp(dom, cod, parts, ctx=None)[source]#
Bases:
LinOp[Domain,Codomain]Base class for linear operators assembled from component operators.
- abstractmethod apply(x)#
Forward application: y = A x
- Contract:
x is an element of self.dom
return value is an element of self.cod
- Parameters:
x (Any)
- Return type:
Any
- abstractmethod rapply(y)#
Adjoint application: x = A^* y
- Contract:
y is an element of self.cod
return value is an element of self.dom
- Parameters:
y (Any)
- Return type:
Any
- abstractmethod classmethod from_operators(parts)[source]#
- Parameters:
parts (Tuple[LinOp, ...])
- Return type:
- assert_codomain(y)#
- Parameters:
y (Any)
- Return type:
None
- assert_domain(x)#
- Parameters:
x (Any)
- Return type:
None
- property dtype: Any#
- property ops: BackendOps#
DenseLinOp#
- class spacecore.linop.DenseLinOp(A, dom, cod=None, ctx=None)[source]#
Bases:
LinOp[VectorSpace,VectorSpace]Dense linear operator defined by an array A with shape:
A.shape == cod.shape + dom.shape
apply: y = A ⋅ x (contract over dom axes) rapply: x = A^* ⋅ y (contract over cod axes)
- Parameters:
A (DenseArray)
dom (Domain)
cod (Codomain | None)
ctx (Context | str | None)
- apply(x)[source]#
Forward action: y = A ⋅ x with y in cod.shape.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- rapply(y)[source]#
Adjoint action: x = A^* ⋅ y with x in dom.shape.
For complex A, uses conjugate-transpose of the 2D reshaped matrix.
- Parameters:
y (DenseArray)
- Return type:
DenseArray
- assert_codomain(y)#
- Parameters:
y (Any)
- Return type:
None
- assert_domain(x)#
- Parameters:
x (Any)
- Return type:
None
- property dtype: Any#
- property ops: BackendOps#
SparseLinOp#
- class spacecore.linop.SparseLinOp(A, dom, cod, ctx=None)[source]#
Bases:
LinOpSparse linear operator implementing the tensor map A : dom -> cod where conceptually A has shape cod.shape + dom.shape, but stored as a 2D sparse matrix:
A2.shape == (prod(cod.shape), prod(dom.shape))
apply: y = A ⋅ x (contract over dom axes) rapply: x = A^* ⋅ y (contract over cod axes)
- Parameters:
A (SparseArray)
dom (Domain)
cod (Codomain)
ctx (Context | str | None)
- apply(x)[source]#
Forward action: y = A ⋅ x with y in cod.shape.
x must have shape dom.shape (dense).
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- rapply(y)[source]#
Adjoint action: x = A^* ⋅ y with x in dom.shape.
y must have shape cod.shape (dense).
- Parameters:
y (DenseArray)
- Return type:
DenseArray
- assert_codomain(y)#
- Parameters:
y (Any)
- Return type:
None
- assert_domain(x)#
- Parameters:
x (Any)
- Return type:
None
- property dtype: Any#
- property ops: BackendOps#
Product-structured operators#
- class spacecore.linop.BlockDiagonalLinOp(dom, cod, parts, ctx=None)[source]#
Bases:
ProductLinOp[ProductSpace,ProductSpace]Block-diagonal operator between product spaces.
dom = X1 × … × Xk cod = Y1 × … × Yk
ops[i] : Xi -> Yi
- apply(x)[source]#
Forward application: y = A x
- Contract:
x is an element of self.dom
return value is an element of self.cod
- Parameters:
x (Any)
- Return type:
Any
- rapply(y)[source]#
Adjoint application: x = A^* y
- Contract:
y is an element of self.cod
return value is an element of self.dom
- Parameters:
y (Any)
- Return type:
Any
- assert_codomain(y)#
- Parameters:
y (Any)
- Return type:
None
- assert_domain(x)#
- Parameters:
x (Any)
- Return type:
None
- property dtype: Any#
- property ops: BackendOps#
- class spacecore.linop.StackedLinOp(dom, cod, parts, ctx=None)[source]#
Bases:
ProductLinOp[Domain,ProductSpace]Stack of operators from a single domain into a product codomain.
dom = X cod = Y1 × … × Yk
ops[i] : X -> Yiapply(x) = (ops[i](x))_irapply(y) = sum_i ops[i]^*(y_i)- apply(x)[source]#
Forward application: y = A x
- Contract:
x is an element of self.dom
return value is an element of self.cod
- Parameters:
x (Any)
- Return type:
Any
- rapply(y)[source]#
Adjoint application: x = A^* y
- Contract:
y is an element of self.cod
return value is an element of self.dom
- Parameters:
y (Any)
- Return type:
Any
- assert_codomain(y)#
- Parameters:
y (Any)
- Return type:
None
- assert_domain(x)#
- Parameters:
x (Any)
- Return type:
None
- property dtype: Any#
- property ops: BackendOps#
- class spacecore.linop.SumToSingleLinOp(dom, cod, parts, ctx=None)[source]#
Bases:
ProductLinOp[ProductSpace,Codomain]Sum of component operators from a product domain into a single codomain.
dom = X1 × … × Xk cod = Y
ops[i] : Xi -> Yapply(x) = sum_i ops[i](x_i)rapply(y) = (ops[i]^*(y))_i- apply(x)[source]#
Forward application: y = A x
- Contract:
x is an element of self.dom
return value is an element of self.cod
- Parameters:
x (Any)
- Return type:
Any
- rapply(y)[source]#
Adjoint application: x = A^* y
- Contract:
y is an element of self.cod
return value is an element of self.dom
- Parameters:
y (Any)
- Return type:
Any
- assert_codomain(y)#
- Parameters:
y (Any)
- Return type:
None
- assert_domain(x)#
- Parameters:
x (Any)
- Return type:
None
- property dtype: Any#
- property ops: BackendOps#