# Transform Source: https://www.tensorplay.cn/docs/generated/tensorplay.distributions.Transform.html ```python class tensorplay.distributions.Transform(cache_size: int = 0) ``` Abstract class for invertible transformations with computable log det jacobians. They are primarily used in [tensorplay.distributions.TransformedDistribution](/docs/generated/tensorplay.distributions.TransformedDistribution.html#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 x ``` Derived classes should implement one or both of _call() or _inverse(). Derived classes that set bijective=True should also implement [log_abs_det_jacobian()](#tensorplay.distributions.Transform.log_abs_det_jacobian). Parameters: cache_size ([int](https://docs.python.org/3/builtins/functions.html#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](https://docs.python.org/3/builtins/functions.html#bool)) – Whether this transform is bijective. A transform t is bijective iff t.inv(t(x)) == x and t(t.inv(y)) == y for every x in the domain and y in the codomain. Transforms that are not bijective should at least maintain the weaker pseudoinverse properties t(t.inv(t(x)) == t(x) and t.inv(t(t.inv(y))) == t.inv(y). - sign ([int](https://docs.python.org/3/builtins/functions.html#int) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – For bijective univariate transforms, this should be +1 or -1 depending on whether transform is monotone increasing or decreasing. ```python forward_shape(shape) ``` Infers the shape of the forward computation, given the input shape. Defaults to preserving shape. ```python property inv: Transform ``` Returns the inverse [Transform](#tensorplay.distributions.Transform) of this transform. This should satisfy t.inv.inv is t. ```python inverse_shape(shape) ``` Infers the shapes of the inverse computation, given the output shape. Defaults to preserving shape. ```python log_abs_det_jacobian(x, y) ``` Computes the log det jacobian log |dy/dx| given input and output. ```python property sign: int ``` Returns the sign of the determinant of the Jacobian, if applicable. In general this only makes sense for bijective transforms.