boundlab.linearop.ComposedOp#
- class boundlab.linearop.ComposedOp[source]#
Bases:
LinearOpComposition of two LinearOps:
(outer ∘ inner)(x) = outer(inner(x)).Methods
Initialize a LinearOp wrapper.
Return a LinearOp representing the element-wise absolute value of this LinearOp.
Apply the transposed linear function to an input tensor.
Materialize this LinearOp as an explicit Jacobian tensor.
Materialize Jacobian via batched forward/backward application.
Apply the original linear function to an input tensor.
Return an explicit Jacobian tensor when efficiently available.
Add this operator's Jacobian contribution into an existing tensor.
Return a LinearOp that computes the norm over the input dimensions, if supported.
Return a LinearOp that computes the norm over the output dimensions, if supported.
Materialize as EinsumOp and delegate to EinsumOp.purify_with.
Apply the transposed linear function to an input tensor, supporting additional leading dimensions for batching.
Apply the original linear function to an input tensor, supporting additional trailing dimensions for batching.
- __init__(*ops)[source]#
Initialize a LinearOp wrapper.
- Parameters:
input_shape – The expected shape of input tensors.
output_shape – The expected shape of output tensors.
flags – Flags indicating special properties of this LinearOp.
- vforward(x)[source]#
Apply the original linear function to an input tensor, supporting additional trailing dimensions for batching.
- vbackward(grad)[source]#
Apply the transposed linear function to an input tensor, supporting additional leading dimensions for batching.
- jacobian()[source]#
Return an explicit Jacobian tensor when efficiently available.
- Returns:
A tensor with shape
[*output_shape, *input_shape]if the concrete Jacobian can be produced directly. ReturnsNotImplementedfor operators that only support implicit application.
- norm_input(p=1)[source]#
Return a LinearOp that computes the norm over the input dimensions, if supported.
- norm_output(p=1)[source]#
Return a LinearOp that computes the norm over the output dimensions, if supported.
- __add__(other)#
Add this LinearOp to another.
- __call__(x)#
Apply this LinearOp to an expression, returning a Linear.
- __mul__(other)#
Scale this LinearOp by a scalar factor.
- abs()#
Return a LinearOp representing the element-wise absolute value of this LinearOp.
- einsum_op()#
Materialize this LinearOp as an explicit Jacobian tensor.
- Returns:
A tensor with shape
[*output_shape, *input_shape]representing the Jacobian of this LinearOp.- Return type:
Notes
This may be expensive in time and memory and is mainly intended for debugging, validation, or rare paths that require explicit Jacobians.
- force_jacobian()#
Materialize Jacobian via batched forward/backward application.
This fallback constructs an identity basis and applies either
vforward()orvbackward()depending on whether the input or output side is smaller.- Returns:
A dense Jacobian tensor with shape
[*output_shape, *input_shape].
Notes
This may be expensive in time and memory and is mainly intended for debugging, validation, or rare paths that require explicit Jacobians.
- jacobian_scatter(src)#
Add this operator’s Jacobian contribution into an existing tensor.
- Parameters:
src (torch.Tensor) – A tensor with Jacobian layout
[*output_shape, *input_shape]that acts as the accumulation buffer.- Returns:
A tensor with the same shape as
srccontainingsrc + jacobian(self).- Return type:
Notes
Subclasses may override this to implement structured/sparse updates without materializing the full Jacobian first.
- input_shape: torch.Size#
Expected input tensor shape.
- output_shape: torch.Size#
Computed output tensor shape.