class
StackTransform
extends
TransformStackTransform(transforms: list[Transform], dim: int = 0)Apply a list of transforms to indexed slices along a stack axis.
The -th transform is applied to the -th slice
obtained by Tensor.unbind along dim, and the results
are stacked back along the same axis. This is the heterogeneous
counterpart of IndependentTransform: different bijections
can be applied to different coordinates of an event vector.
Parameters
transformslist[Transform]One transform per slice. Must be non-empty and the same length
as
x.shape[dim].dimint= 0Dimension along which to slice. Default
0.Raises
ValueErrorIf
transforms is empty, or if the size of dim does not
match len(transforms) at call time.Notes
Forward (with ):
Inverse:
Log Jacobian determinant (per-slice values stacked back along dim):
Useful for "block" flows where each coordinate of the latent vector
has its own bijection — e.g., applying ExpTransform to
positive components and TanhTransform to bounded ones.
Examples
>>> import lucid
>>> from lucid.distributions.transforms import ExpTransform, TanhTransform, StackTransform
>>> T = StackTransform([ExpTransform(), TanhTransform()], dim=-1)
>>> T(lucid.tensor([0.0, 0.0])) # (exp(0), tanh(0)) = (1, 0)
Tensor([1.0, 0.0])