class
ReshapeTransform
extends
TransformReshapeTransform(in_shape: tuple[int, ...], out_shape: tuple[int, ...])Pure-shape reinterpretation of the event shape .
Maps the trailing event tail of a tensor from in_shape to
out_shape. This is a volume-preserving bijection — the
underlying storage is unchanged, only the interpretation of which
axes constitute the event differs. The product of dimensions must
match.
Parameters
in_shapetuple[int, ...]Event shape of the input tail.
out_shapetuple[int, ...]Event shape of the output tail. Must satisfy
.
Raises
ValueErrorIf
prod(in_shape) != prod(out_shape).Notes
Forward: .
Inverse: .
Log Jacobian determinant:
everywhere — a reshape preserves Lebesgue measure exactly. Useful for stitching together transforms that expect different event layouts (e.g. flatten a matrix event for a Cholesky-style transform, then reshape back).
Examples
>>> import lucid
>>> from lucid.distributions.transforms import ReshapeTransform
>>> T = ReshapeTransform(in_shape=(2, 3), out_shape=(6,))
>>> T(lucid.zeros(2, 3)).shape
(6,)Methods (2)
dunder
__init__
→None__init__(in_shape: tuple[int, ...], out_shape: tuple[int, ...])Validate that in_shape and out_shape have the same total size and store them.
Raises
ValueErrorIf
prod(in_shape) != prod(out_shape).fn
log_abs_det_jacobian
→Tensorlog_abs_det_jacobian(x: Tensor, y: Tensor)Zero Jacobian — pure reshape is volume-preserving.