Skip to content
class

ReshapeTransform

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

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:

log⁡∣det⁡J∣=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,)

Used by 1

Constructors

1
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

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

Properties

2
prop

codomain

→Constraint
codomain: Constraint

independent(real, len(out_shape)).

prop

domain

→Constraint
domain: Constraint

independent(real, len(in_shape)).

Instance methods

3
fn

forward_shape

→tuple[int, ...]
forward_shape(shape: tuple[int, ...])

Replace the trailing in_shape dimensions with out_shape.

fn

inverse_shape

→tuple[int, ...]
inverse_shape(shape: tuple[int, ...])

Replace the trailing out_shape dimensions with in_shape.

fn

log_abs_det_jacobian

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

Zero Jacobian — pure reshape is volume-preserving.