Linear operators API#

Linear operators represent maps between spaces with forward and adjoint actions.

spacecore.linop.LinOp

Minimal linear operator (morphism) between two spaces.

spacecore.linop.ProductLinOp

Base class for linear operators assembled from component operators.

spacecore.linop.DenseLinOp

Dense linear operator defined by an array A with shape:

spacecore.linop.SparseLinOp

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:

spacecore.linop.BlockDiagonalLinOp

Block-diagonal operator between product spaces.

spacecore.linop.StackedLinOp

Stack of operators from a single domain into a product codomain.

spacecore.linop.SumToSingleLinOp

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 -> cod with 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

assert_domain(x)[source]#
Parameters:

x (Any)

Return type:

None

assert_codomain(y)[source]#
Parameters:

y (Any)

Return type:

None

convert(new_ctx=None)#
Parameters:

new_ctx (Context | BackendFamily | str | None)

Return type:

Self

property ctx: Context#
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.

Parameters:
  • dom (Domain)

  • cod (Codomain)

  • parts (Tuple[LinOp, ...])

  • ctx (Context | str | None)

parts: Tuple[LinOp, ...]#
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:

ProductLinOp

assert_codomain(y)#
Parameters:

y (Any)

Return type:

None

assert_domain(x)#
Parameters:

x (Any)

Return type:

None

convert(new_ctx=None)#
Parameters:

new_ctx (Context | BackendFamily | str | None)

Return type:

Self

property ctx: Context#
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

convert(new_ctx=None)#
Parameters:

new_ctx (Context | BackendFamily | str | None)

Return type:

Self

property ctx: Context#
property dtype: Any#
property ops: BackendOps#

SparseLinOp#

class spacecore.linop.SparseLinOp(A, dom, cod, ctx=None)[source]#

Bases: LinOp

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:

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

convert(new_ctx=None)#
Parameters:

new_ctx (Context | BackendFamily | str | None)

Return type:

Self

property ctx: Context#
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

Parameters:
  • dom (Domain)

  • cod (Codomain)

  • parts (Tuple[LinOp, ...])

  • ctx (Context | str | None)

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

classmethod from_operators(parts)[source]#
Parameters:

parts (Tuple[LinOp, ...])

Return type:

BlockDiagonalLinOp

assert_codomain(y)#
Parameters:

y (Any)

Return type:

None

assert_domain(x)#
Parameters:

x (Any)

Return type:

None

convert(new_ctx=None)#
Parameters:

new_ctx (Context | BackendFamily | str | None)

Return type:

Self

property ctx: Context#
property dtype: Any#
property ops: BackendOps#
parts: Tuple[LinOp, ...]#
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 -> Yi apply(x)  = (ops[i](x))_i rapply(y) = sum_i ops[i]^*(y_i)

Parameters:
  • dom (Domain)

  • cod (Codomain)

  • parts (Tuple[LinOp, ...])

  • ctx (Context | str | None)

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

classmethod from_operators(parts)[source]#
Parameters:

parts (Tuple[LinOp, ...])

Return type:

StackedLinOp

assert_codomain(y)#
Parameters:

y (Any)

Return type:

None

assert_domain(x)#
Parameters:

x (Any)

Return type:

None

convert(new_ctx=None)#
Parameters:

new_ctx (Context | BackendFamily | str | None)

Return type:

Self

property ctx: Context#
property dtype: Any#
property ops: BackendOps#
parts: Tuple[LinOp, ...]#
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 -> Y apply(x)  = sum_i ops[i](x_i) rapply(y) = (ops[i]^*(y))_i

Parameters:
  • dom (Domain)

  • cod (Codomain)

  • parts (Tuple[LinOp, ...])

  • ctx (Context | str | None)

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

classmethod from_operators(parts)[source]#
Parameters:

parts (Tuple[LinOp, ...])

Return type:

SumToSingleLinOp

assert_codomain(y)#
Parameters:

y (Any)

Return type:

None

assert_domain(x)#
Parameters:

x (Any)

Return type:

None

convert(new_ctx=None)#
Parameters:

new_ctx (Context | BackendFamily | str | None)

Return type:

Self

property ctx: Context#
property dtype: Any#
property ops: BackendOps#
parts: Tuple[LinOp, ...]#