class

ReshapeTransform

extendsTransform
ReshapeTransform(in_shape: tuple[int, ...], out_shape: tuple[int, ...])
source

Pure-shape reinterpretation of the event shape y=reshape(x)y = \mathrm{reshape}(x).

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 iin_shapei=iout_shapei\prod_i \mathrm{in\_shape}_i = \prod_i \mathrm{out\_shape}_i.

Raises

ValueError
If prod(in_shape) != prod(out_shape).

Notes

Forward: y=reshape(x,out_shape)\mathbf{y} = \mathrm{reshape}(\mathbf{x}, \mathrm{out\_shape}).

Inverse: x=reshape(y,in_shape)\mathbf{x} = \mathrm{reshape}(\mathbf{y}, \mathrm{in\_shape}).

Log Jacobian determinant:

logdetJ=0\log|\det J| = 0

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, ...])
source

Validate that in_shape and out_shape have the same total size and store them.

Raises

ValueError
If prod(in_shape) != prod(out_shape).
fn

log_abs_det_jacobian

Tensor
log_abs_det_jacobian(x: Tensor, y: Tensor)
source

Zero Jacobian — pure reshape is volume-preserving.