class
CatTransform
extends
TransformCatTransform(transforms: list[Transform], dim: int = 0, lengths: list[int] | None = None)Apply different transforms to contiguous partitions along an axis.
Splits the input along dim into contiguous chunks of size
lengths[i] (one element each if lengths is None),
applies the -th transform to the -th chunk, and
concatenates the results back along the same axis. Differs from
StackTransform in that each partition can have a different
length, not just a single index.
Parameters
transformslist[Transform]One transform per partition.
dimint= 0Concatenation dimension. Default
0.lengthslist[int]= NoneLength of each partition. Default
None: one per transform, so
dim holds len(transforms) elements. dim must hold
sum(lengths) of them, as the reference requires.Raises
ValueErrorIf
transforms is empty, or lengths is not one per transform.lucid._C.engine.InvalidArgumentWhen applied, if
dim does not hold sum(lengths) elements.Notes
Forward (with the -th partition):
Inverse: split, invert, re-concatenate.
Log Jacobian determinant: per-partition Jacobians concatenated back
along dim:
Examples
>>> import lucid
>>> from lucid.distributions.transforms import ExpTransform, AffineTransform, CatTransform
>>> T = CatTransform([ExpTransform(), AffineTransform(0.0, 2.0)],
... dim=0, lengths=[2, 3])
>>> T(lucid.tensor([0.0, 0.0, 1.0, 2.0, 3.0])).shape
(5,)