latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
Transform
- class tensorplay.distributions.Transform(cache_size: int = 0)[source]
Abstract class for invertible transformations with computable log det jacobians. They are primarily used in
tensorplay.distributions.TransformedDistribution.Caching is useful for transforms whose inverses are either expensive or numerically unstable. Note that care must be taken with memoized values since the autograd graph may be reversed. For example while the following works with or without caching:
y = t(x) t.log_abs_det_jacobian(x, y).backward() # x will receive gradients.However the following will error when caching due to dependency reversal:
y = t(x) z = t.inv(y) grad(z.sum(), [y]) # error because z is xDerived classes should implement one or both of
_call()or_inverse(). Derived classes that set bijective=True should also implementlog_abs_det_jacobian().- Parameters:
cache_size (int) – Size of cache. If zero, no caching is done. If one, the latest single value is cached. Only 0 and 1 are supported.
- Variables:
domain (
Constraint) – The constraint representing valid inputs to this transform.codomain (
Constraint) – The constraint representing valid outputs to this transform which are inputs to the inverse transform.bijective (bool) – Whether this transform is bijective. A transform
tis bijective ifft.inv(t(x)) == xandt(t.inv(y)) == yfor everyxin the domain andyin the codomain. Transforms that are not bijective should at least maintain the weaker pseudoinverse propertiest(t.inv(t(x)) == t(x)andt.inv(t(t.inv(y))) == t.inv(y).sign (int or Tensor) – For bijective univariate transforms, this should be +1 or -1 depending on whether transform is monotone increasing or decreasing.
- forward_shape(shape)[source]
Infers the shape of the forward computation, given the input shape. Defaults to preserving shape.
- property inv: Transform
Returns the inverse
Transformof this transform. This should satisfyt.inv.inv is t.
- inverse_shape(shape)[source]
Infers the shapes of the inverse computation, given the output shape. Defaults to preserving shape.
- log_abs_det_jacobian(x, y)[source]
Computes the log det jacobian log |dy/dx| given input and output.
- property sign: int
Returns the sign of the determinant of the Jacobian, if applicable. In general this only makes sense for bijective transforms.
Help improve this page
Found an error, an unclear step, or a missing example?

