/usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__
NameSizeModeActions
bernoulli.cpython-36.pyc44450644editdlrm
beta.cpython-36.pyc36820644editdlrm
binomial.cpython-36.pyc47610644editdlrm
categorical.cpython-36.pyc58130644editdlrm
cauchy.cpython-36.pyc33100644editdlrm
chi2.cpython-36.pyc14190644editdlrm
constraints.cpython-36.pyc222170644editdlrm
constraint_registry.cpython-36.pyc98950644editdlrm
continuous_bernoulli.cpython-36.pyc80770644editdlrm
dirichlet.cpython-36.pyc40850644editdlrm
distribution.cpython-36.pyc118220644editdlrm
exponential.cpython-36.pyc33630644editdlrm
exp_family.cpython-36.pyc28760644editdlrm
fishersnedecor.cpython-36.pyc32120644editdlrm
gamma.cpython-36.pyc34550644editdlrm
geometric.cpython-36.pyc41830644editdlrm
gumbel.cpython-36.pyc28640644editdlrm
half_cauchy.cpython-36.pyc29300644editdlrm
half_normal.cpython-36.pyc28210644editdlrm
independent.cpython-36.pyc45060644editdlrm
kl.cpython-36.pyc258440644editdlrm
kumaraswamy.cpython-36.pyc30400644editdlrm
laplace.cpython-36.pyc34420644editdlrm
lkj_cholesky.cpython-36.pyc45750644editdlrm
logistic_normal.cpython-36.pyc23200644editdlrm
log_normal.cpython-36.pyc24380644editdlrm
lowrank_multivariate_normal.cpython-36.pyc80740644editdlrm
mixture_same_family.cpython-36.pyc70730644editdlrm
multinomial.cpython-36.pyc50200644editdlrm
multivariate_normal.cpython-36.pyc85340644editdlrm
negative_binomial.cpython-36.pyc41490644editdlrm
normal.cpython-36.pyc41380644editdlrm
one_hot_categorical.cpython-36.pyc51730644editdlrm
pareto.cpython-36.pyc25160644editdlrm
poisson.cpython-36.pyc26820644editdlrm
relaxed_bernoulli.cpython-36.pyc55950644editdlrm
relaxed_categorical.cpython-36.pyc55630644editdlrm
studentT.cpython-36.pyc34830644editdlrm
transformed_distribution.cpython-36.pyc73350644editdlrm
transforms.cpython-36.pyc429810644editdlrm
uniform.cpython-36.pyc35800644editdlrm
utils.cpython-36.pyc68020644editdlrm
von_mises.cpython-36.pyc50790644editdlrm
weibull.cpython-36.pyc27370644editdlrm
__init__.cpython-36.pyc59810644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__/transforms.cpython-36.pyc (42981B)
3 Eg@sddlZddlZddlZddlZddlZddlmZddlZddlj j Z ddl m Z ddlmZmZmZmZmZddlmZddlmZddd d d d d ddddddddddgZGdddeZGdddeZGdd d eZegZGdd d eZGdddeZGdd d eZGdddeZd d!Z Gd"ddeZ!Gd#ddeZ"Gd$ddeZ#Gd%ddeZ$Gd&d d eZ%Gd'ddeZ&Gd(ddeZ'Gd)ddeZ(Gd*d d eZ)Gd+ddeZ*dS),N)List) constraints)_sum_rightmost broadcast_all lazy_propertytril_matrix_to_vecvec_to_tril_matrix)pad)softplus AbsTransformAffineTransform CatTransformComposeTransformCorrCholeskyTransform ExpTransformIndependentTransformLowerCholeskyTransformPowerTransformReshapeTransformSigmoidTransform TanhTransformSoftmaxTransformStackTransformStickBreakingTransform Transformidentity_transformcseZdZUdZdZejejd#fdd Z e ddZ e dd Z e d d Z d$d dZddZddZddZddZddZddZddZddZdd Zd!d"ZZS)%ra Abstract class for invertable transformations with computable log det jacobians. They are primarily used in :class:`torch.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 :meth:`_call` or :meth:`_inverse`. Derived classes that set `bijective=True` should also implement :meth:`log_abs_det_jacobian`. Args: 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. Attributes: domain (:class:`~torch.distributions.constraints.Constraint`): The constraint representing valid inputs to this transform. codomain (:class:`~torch.distributions.constraints.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 ``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 or Tensor): For bijective univariate transforms, this should be +1 or -1 depending on whether transform is monotone increasing or decreasing. Frcs@||_d|_|dkrn|dkr&d|_ntdtt|jdS)Nrzcache_size must be 0 or 1)NN) _cache_size_inv _cached_x_y ValueErrorsuperr__init__)self cache_size) __class__J/usr/local/lib64/python3.6/site-packages/torch/distributions/transforms.pyr"VszTransform.__init__cCs$|jj|jjkr|jjStddS)Nz:Please use either .domain.event_dim or .codomain.event_dim)domain event_dimcodomainr )r#r&r&r'r)aszTransform.event_dimcCs6d}|jdk r|j}|dkr2t|}tj||_|S)z{ Returns the inverse :class:`Transform` of this transform. This should satisfy ``t.inv.inv is t``. N)r_InverseTransformweakrefref)r#invr&r&r'r.gs  z Transform.invcCstdS)z Returns the sign of the determinant of the Jacobian, if applicable. In general this only makes sense for bijective transforms. N)NotImplementedError)r#r&r&r'signuszTransform.signrcCsB|j|kr|St|jtjkr,t||dStdjt|dS)N)r$z {}.with_cache is not implemented)rtyper"rr/format)r#r$r&r&r' with_cache}s  zTransform.with_cachecCs||kS)Nr&)r#otherr&r&r'__eq__szTransform.__eq__cCs |j| S)N)r5)r#r4r&r&r'__ne__szTransform.__ne__cCsB|jdkr|j|S|j\}}||kr*|S|j|}||f|_|S)z2 Computes the transform `x => y`. r)r_callr)r#xx_oldy_oldyr&r&r'__call__s     zTransform.__call__cCsB|jdkr|j|S|j\}}||kr*|S|j|}||f|_|S)z1 Inverts the transform `y => x`. r)r_inverser)r#r;r9r:r8r&r&r' _inv_calls     zTransform._inv_callcCstdS)zD Abstract method to compute forward transformation. N)r/)r#r8r&r&r'r7szTransform._callcCstdS)zD Abstract method to compute inverse transformation. N)r/)r#r;r&r&r'r=szTransform._inversecCstdS)zU Computes the log det jacobian `log |dy/dx|` given input and output. N)r/)r#r8r;r&r&r'log_abs_det_jacobianszTransform.log_abs_det_jacobiancCs |jjdS)Nz())r%__name__)r#r&r&r'__repr__szTransform.__repr__cCs|S)z{ Infers the shape of the forward computation, given the input shape. Defaults to preserving shape. r&)r#shaper&r&r' forward_shapeszTransform.forward_shapecCs|S)z} Infers the shapes of the inverse computation, given the output shape. Defaults to preserving shape. r&)r#rBr&r&r' inverse_shapeszTransform.inverse_shape)r)r)r@ __module__ __qualname____doc__ bijectiver Constraintr(r*r"propertyr)r.r0r3r5r6r<r>r7r=r?rArCrD __classcell__r&r&)r%r'r&s& +      cseZdZdZedfdd ZejddddZejddd d Z e d d Z e d dZ e ddZ d ddZddZddZddZddZddZddZZS)!r+z| Inverts a single :class:`Transform`. This class is private; please instead use the ``Transform.inv`` property. ) transformcstt|j|jd||_dS)N)r$)r!r+r"rr)r#rL)r%r&r'r"sz_InverseTransform.__init__F) is_discretecCs|jdk st|jjS)N)rAssertionErrorr*)r#r&r&r'r(sz_InverseTransform.domaincCs|jdk st|jjS)N)rrNr()r#r&r&r'r*sz_InverseTransform.codomaincCs|jdk st|jjS)N)rrNrH)r#r&r&r'rHsz_InverseTransform.bijectivecCs|jdk st|jjS)N)rrNr0)r#r&r&r'r0sz_InverseTransform.signcCs|jS)N)r)r#r&r&r'r.sz_InverseTransform.invrcCs|jdk st|jj|jS)N)rrNr.r3)r#r$r&r&r'r3sz_InverseTransform.with_cachecCs(t|tsdS|jdk st|j|jkS)NF) isinstancer+rrN)r#r4r&r&r'r5s z_InverseTransform.__eq__cCs|jjdt|jdS)N())r%r@reprr)r#r&r&r'rAsz_InverseTransform.__repr__cCs|jdk st|jj|S)N)rrNr>)r#r8r&r&r'r<sz_InverseTransform.__call__cCs|jdk st|jj|| S)N)rrNr?)r#r8r;r&r&r'r?sz&_InverseTransform.log_abs_det_jacobiancCs |jj|S)N)rrD)r#rBr&r&r'rCsz_InverseTransform.forward_shapecCs |jj|S)N)rrC)r#rBr&r&r'rDsz_InverseTransform.inverse_shape)r)r@rErFrGrr"rdependent_propertyr(r*rJrHr0r.r3r5rAr<r?rCrDrKr&r&)r%r'r+s    r+cseZdZdZd!eedfdd ZddZej dd d d Z ej dd d d Z e ddZ e ddZeddZd"ddZddZddZddZddZdd ZZS)#rab Composes multiple transforms in a chain. The transforms being composed are responsible for caching. Args: parts (list of :class:`Transform`): A list of transforms to compose. 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. r)partscs2rfdd|D}tt|jd||_dS)Ncsg|]}|jqSr&)r3).0part)r$r&r' sz-ComposeTransform.__init__..)r$)r!rr"rT)r#rTr$)r%)r$r'r"szComposeTransform.__init__cCst|tsdS|j|jkS)NF)rOrrT)r#r4r&r&r'r5s zComposeTransform.__eq__F)rMcCs|js tjS|jdj}|jdjj}x4t|jD]&}||jj|jj7}t||jj}q2W||jksjt||jkrtj |||j}|S)Nrr) rTrrealr(r*r)reversedmaxrN independent)r#r(r)rVr&r&r'r(s  zComposeTransform.domaincCs|js tjS|jdj}|jdjj}x0|jD]&}||jj|jj7}t||jj}q.W||jksft||jkrtj|||j}|S)NrrrX) rTrrYr*r(r)r[rNr\)r#r*r)rVr&r&r'r**s   zComposeTransform.codomaincCstdd|jDS)Ncss|] }|jVqdS)N)rH)rUpr&r&r' ;sz-ComposeTransform.bijective..)allrT)r#r&r&r'rH9szComposeTransform.bijectivecCs"d}x|jD]}||j}q W|S)Nr)rTr0)r#r0r]r&r&r'r0=s zComposeTransform.signcCsRd}|jdk r|j}|dkrNtddt|jD}tj||_tj||_|S)NcSsg|] }|jqSr&)r.)rUr]r&r&r'rWJsz(ComposeTransform.inv..)rrrZrTr,r-)r#r.r&r&r'r.Ds   zComposeTransform.invrcCs|j|kr|St|j|dS)N)r$)rrrT)r#r$r&r&r'r3Os zComposeTransform.with_cachecCsx|jD] }||}qW|S)N)rT)r#r8rVr&r&r'r<Ts  zComposeTransform.__call__cCs|jstj|S|g}x(|jddD]}|j||dq&W|j|g}|jj}x`t|j|dd|ddD]>\}}}|jt|j||||jj||j j|jj7}qvWt j t j |S)NrrXrXrX)rTtorchZ zeros_likeappendr(r)ziprr?r* functoolsreduceoperatoradd)r#r8r;xsrVZtermsr)r&r&r'r?Ys  *z%ComposeTransform.log_abs_det_jacobiancCsx|jD]}|j|}qW|S)N)rTrC)r#rBrVr&r&r'rCks zComposeTransform.forward_shapecCs"xt|jD]}|j|}q W|S)N)rZrTrD)r#rBrVr&r&r'rDpszComposeTransform.inverse_shapecCs2|jjd}|djdd|jD7}|d7}|S)Nz( z, cSsg|] }|jqSr&)rA)rUr]r&r&r'rWwsz-ComposeTransform.__repr__..z ))r%r@joinrT)r#Z fmt_stringr&r&r'rAus zComposeTransform.__repr__)r)r)r@rErFrGrrr"r5rrSr(r*rrHr0rJr.r3r<r?rCrDrArKr&r&)r%r'rs    cseZdZdZdfdd ZdddZejdd d d Zejdd d d Z e ddZ e ddZ ddZ ddZddZddZddZddZZS) ra Wrapper around another transform to treat ``reinterpreted_batch_ndims``-many extra of the right most dimensions as dependent. This has no effect on the forward or backward transforms, but does sum out ``reinterpreted_batch_ndims``-many of the rightmost dimensions in :meth:`log_abs_det_jacobian`. Args: base_transform (:class:`Transform`): A base transform. reinterpreted_batch_ndims (int): The number of extra rightmost dimensions to treat as dependent. rcs$tj|d|j||_||_dS)N)r$)r!r"r3base_transformreinterpreted_batch_ndims)r#rirjr$)r%r&r'r"s zIndependentTransform.__init__rcCs |j|kr|St|j|j|dS)N)r$)rrrirj)r#r$r&r&r'r3s  zIndependentTransform.with_cacheF)rMcCstj|jj|jS)N)rr\rir(rj)r#r&r&r'r(s zIndependentTransform.domaincCstj|jj|jS)N)rr\rir*rj)r#r&r&r'r*s zIndependentTransform.codomaincCs|jjS)N)rirH)r#r&r&r'rHszIndependentTransform.bijectivecCs|jjS)N)rir0)r#r&r&r'r0szIndependentTransform.signcCs"|j|jjkrtd|j|S)NzToo few dimensions on input)dimr(r)r ri)r#r8r&r&r'r7szIndependentTransform._callcCs$|j|jjkrtd|jj|S)NzToo few dimensions on input)rkr*r)r rir.)r#r;r&r&r'r=szIndependentTransform._inversecCs|jj||}t||j}|S)N)rir?rrj)r#r8r;resultr&r&r'r?s z)IndependentTransform.log_abs_det_jacobiancCs"|jjdt|jd|jdS)NrPz, rQ)r%r@rRrirj)r#r&r&r'rAszIndependentTransform.__repr__cCs |jj|S)N)rirC)r#rBr&r&r'rCsz"IndependentTransform.forward_shapecCs |jj|S)N)rirD)r#rBr&r&r'rDsz"IndependentTransform.inverse_shape)r)r)r@rErFrGr"r3rrSr(r*rJrHr0r7r=r?rArCrDrKr&r&)r%r'rs    csteZdZdZdZdfdd ZejddZejdd Z dd d Z d dZ ddZ ddZ ddZddZZS)raM Unit Jacobian transform to reshape the rightmost part of a tensor. Note that ``in_shape`` and ``out_shape`` must have the same number of elements, just as for :meth:`torch.Tensor.reshape`. Arguments: in_shape (torch.Size): The input event shape. out_shape (torch.Size): The output event shape. TrcsFtj||_tj||_|jj|jjkr4tdtj|ddS)Nz6in_shape, out_shape have different numbers of elements)r$)r`Sizein_shape out_shapeZnumelr r!r")r#rnror$)r%r&r'r"s   zReshapeTransform.__init__cCstjtjt|jS)N)rr\rYlenrn)r#r&r&r'r(szReshapeTransform.domaincCstjtjt|jS)N)rr\rYrpro)r#r&r&r'r*szReshapeTransform.codomainrcCs |j|kr|St|j|j|dS)N)r$)rrrnro)r#r$r&r&r'r3s zReshapeTransform.with_cachecCs,|jd|jt|j}|j||jS)N)rBrkrprnreshapero)r#r8 batch_shaper&r&r'r7szReshapeTransform._callcCs,|jd|jt|j}|j||jS)N)rBrkrprorqrn)r#r;rrr&r&r'r=szReshapeTransform._inversecCs&|jd|jt|j}|j|S)N)rBrkrprnZ new_zeros)r#r8r;rrr&r&r'r?sz%ReshapeTransform.log_abs_det_jacobiancCsjt|t|jkrtdt|t|j}||d|jkrXtdj||d|j|d||jS)NzToo few dimensions on inputz&Shape mismatch: expected {} but got {})rprnr r2ro)r#rBcutr&r&r'rCs zReshapeTransform.forward_shapecCsjt|t|jkrtdt|t|j}||d|jkrXtdj||d|j|d||jS)NzToo few dimensions on inputz&Shape mismatch: expected {} but got {})rpror r2rn)r#rBrsr&r&r'rDs zReshapeTransform.inverse_shape)r)r)r@rErFrGrHr"rrSr(r*r3r7r=r?rCrDrKr&r&)r%r'rs  c@sDeZdZdZejZejZdZ d Z ddZ ddZ dd Z d d Zd S)rz8 Transform via the mapping :math:`y = \exp(x)`. TrcCs t|tS)N)rOr)r#r4r&r&r'r5 szExpTransform.__eq__cCs|jS)N)exp)r#r8r&r&r'r7 szExpTransform._callcCs|jS)N)log)r#r;r&r&r'r=szExpTransform._inversecCs|S)Nr&)r#r8r;r&r&r'r?sz!ExpTransform.log_abs_det_jacobianNr)r@rErFrGrrYr(positiver*rHr0r5r7r=r?r&r&r&r'rscspeZdZdZejZejZdZdZ dfdd Z dddZ d d Z d d Z d dZddZddZddZZS)rzD Transform via the mapping :math:`y = x^{\text{exponent}}`. Trrcs"tt|j|dt|\|_dS)N)r$)r!rr"rexponent)r#rwr$)r%r&r'r" szPowerTransform.__init__cCs|j|kr|St|j|dS)N)r$)rrrw)r#r$r&r&r'r3$s zPowerTransform.with_cachecCs$t|tsdS|jj|jjjS)NF)rOrrweqr_item)r#r4r&r&r'r5)s zPowerTransform.__eq__cCs |j|jS)N)powrw)r#r8r&r&r'r7.szPowerTransform._callcCs|jd|jS)Nr)rzrw)r#r;r&r&r'r=1szPowerTransform._inversecCs|j||jjS)N)rwabsru)r#r8r;r&r&r'r?4sz#PowerTransform.log_abs_det_jacobiancCstj|t|jdfS)NrB)r`broadcast_shapesgetattrrw)r#rBr&r&r'rC7szPowerTransform.forward_shapecCstj|t|jdfS)NrB)r`r|r}rw)r#rBr&r&r'rD:szPowerTransform.inverse_shaper)r)r)r@rErFrGrrvr(r*rHr0r"r3r5r7r=r?rCrDrKr&r&)r%r'rs cCs*tj|j}tjtj||jd|jdS)Ng?)minr[)r`finfodtypeclampZsigmoidtinyeps)r8rr&r&r'_clipped_sigmoid>s rc@sDeZdZdZejZejZdZ d Z ddZ ddZ dd Z d d Zd S)rzg Transform via the mapping :math:`y = \frac{1}{1 + \exp(-x)}` and :math:`x = \text{logit}(y)`. TrcCs t|tS)N)rOr)r#r4r&r&r'r5LszSigmoidTransform.__eq__cCst|S)N)r)r#r8r&r&r'r7OszSigmoidTransform._callcCs4tj|j}|j|jd|jd}|j| jS)Ng?)r~r[)r`rrrrrrulog1p)r#r;rr&r&r'r=Rs zSigmoidTransform._inversecCstj|  tj|S)N)Fr )r#r8r;r&r&r'r?Wsz%SigmoidTransform.log_abs_det_jacobianNr)r@rErFrGrrYr(Z unit_intervalr*rHr0r5r7r=r?r&r&r&r'rCsc@sJeZdZdZejZejddZdZ dZ ddZ ddZ d d Z d d Zd S)ra~ Transform via the mapping :math:`y = \tanh(x)`. It is equivalent to ``` ComposeTransform([AffineTransform(0., 2.), SigmoidTransform(), AffineTransform(-1., 2.)]) ``` However this might not be numerically stable, thus it is recommended to use `TanhTransform` instead. Note that one should use `cache_size=1` when it comes to `NaN/Inf` values. g?TrcCs t|tS)N)rOr)r#r4r&r&r'r5nszTanhTransform.__eq__cCs|jS)N)tanh)r#r8r&r&r'r7qszTanhTransform._callcCs tj|S)N)r`atanh)r#r;r&r&r'r=tszTanhTransform._inversecCsdtjd|td|S)Ng@g)mathrur )r#r8r;r&r&r'r?ysz"TanhTransform.log_abs_det_jacobianNgr)r@rErFrGrrYr(intervalr*rHr0r5r7r=r?r&r&r&r'r[s  c@s4eZdZdZejZejZddZ ddZ ddZ dS) r z4 Transform via the mapping :math:`y = |x|`. cCs t|tS)N)rOr )r#r4r&r&r'r5szAbsTransform.__eq__cCs|jS)N)r{)r#r8r&r&r'r7szAbsTransform._callcCs|S)Nr&)r#r;r&r&r'r=szAbsTransform._inverseN) r@rErFrGrrYr(rvr*r5r7r=r&r&r&r'r s cseZdZdZdZdfdd ZeddZej dd d d Z ej dd d d Z d ddZ ddZ eddZddZddZddZddZddZZS)!r a Transform via the pointwise affine mapping :math:`y = \text{loc} + \text{scale} \times x`. Args: loc (Tensor or float): Location parameter. scale (Tensor or float): Scale parameter. event_dim (int): Optional size of `event_shape`. This should be zero for univariate random variables, 1 for distributions over vectors, 2 for distributions over matrices, etc. Trcs(tt|j|d||_||_||_dS)N)r$)r!r r"locscale _event_dim)r#rrr)r$)r%r&r'r"szAffineTransform.__init__cCs|jS)N)r)r#r&r&r'r)szAffineTransform.event_dimF)rMcCs |jdkrtjStjtj|jS)Nr)r)rrYr\)r#r&r&r'r(s zAffineTransform.domaincCs |jdkrtjStjtj|jS)Nr)r)rrYr\)r#r&r&r'r*s zAffineTransform.codomainrcCs$|j|kr|St|j|j|j|dS)N)r$)rr rrr))r#r$r&r&r'r3s zAffineTransform.with_cachecCst|tsdSt|jtjr.csg|]}|jqSr&)r3)rUr)r$r&r'rWsz)CatTransform.__init__..)r$r) r_rNr!r r"list transformsrplengthsrk)r#tseqrkrr$)r%)r$r'r"s  zCatTransform.__init__cCstdd|jDS)Ncss|] }|jVqdS)N)r))rUrr&r&r'r^sz)CatTransform.event_dim..)r[r)r#r&r&r'r)szCatTransform.event_dimcCs t|jS)N)rr)r#r&r&r'lengthszCatTransform.lengthrcCs"|j|kr|St|j|j|j|S)N)rr rrkr)r#r$r&r&r'r3s zCatTransform.with_cachecCs|j |jko|jkns(t|j|j|jks>tg}d}x@t|j|jD].\}}|j|j||}|j||||}qVWt j ||jdS)Nr)rk) rkrNrrrbrrnarrowrar`cat)r#r8yslicesstarttransrxslicer&r&r'r7s( zCatTransform._callcCs|j |jko|jkns(t|j|j|jks>tg}d}xBt|j|jD]0\}}|j|j||}|j|j |||}qVWt j ||jdS)Nr)rk) rkrNrrrbrrrrar.r`r)r#r;xslicesrrryslicer&r&r'r=s( zCatTransform._inversec CsF|j |jko|jkns(t|j|j|jks>t|j |jko\|jknsft|j|j|jks|tg}d}xvt|j|jD]d\}}|j|j||}|j|j||}|j||} |j |j krt | |j |j } |j | ||}qW|j} | dkr| |j} | |j } | dkr:t j || dSt|SdS)Nr)rk)rkrNrrrbrrrr?r)rrar`rr) r#r8r; logdetjacsrrrrrZ logdetjacrkr&r&r'r?s*((        z!CatTransform.log_abs_det_jacobiancCstdd|jDS)Ncss|] }|jVqdS)N)rH)rUrr&r&r'r^ sz)CatTransform.bijective..)r_r)r#r&r&r'rHszCatTransform.bijectivecCstjdd|jD|j|jS)NcSsg|] }|jqSr&)r()rUrr&r&r'rW sz'CatTransform.domain..)rrrrkr)r#r&r&r'r( szCatTransform.domaincCstjdd|jD|j|jS)NcSsg|] }|jqSr&)r*)rUrr&r&r'rWsz)CatTransform.codomain..)rrrrkr)r#r&r&r'r*szCatTransform.codomain)rNr)r)r@rErFrrrrr"rr)rr3r7r=r?rJrHrrSr(r*rKr&r&)r%r'r s        csteZdZdZdfdd ZdddZdd Zd d Zd d ZddZ e ddZ e j ddZe j ddZZS)raV Transform functor that applies a sequence of transforms `tseq` component-wise to each submatrix at `dim` in a way compatible with :func:`torch.stack`. Example:: x = torch.stack([torch.range(1, 10), torch.range(1, 10)], dim=1) t = StackTransform([ExpTransform(), identity_transform], dim=1) y = t(x) rcsRtdd|Dstr,fdd|D}tt|jdt||_||_dS)Ncss|]}t|tVqdS)N)rOr)rUrr&r&r'r^"sz*StackTransform.__init__..csg|]}|jqSr&)r3)rUr)r$r&r'rW$sz+StackTransform.__init__..)r$)r_rNr!rr"rrrk)r#rrkr$)r%)r$r'r"!s  zStackTransform.__init__rcCs|j|kr|St|j|j|S)N)rrrrk)r#r$r&r&r'r3)s zStackTransform.with_cachecs fddtjjDS)Ncsg|]}jj|qSr&)selectrk)rUi)r#rr&r'rW/sz)StackTransform._slice..)rangerrk)r#rr&)r#rr'_slice.szStackTransform._slicecCs|j |jko|jkns(t|j|jt|jksBtg}x,t|j||jD]\}}|j||qZWtj ||jdS)N)rk) rkrNrrprrbrrar`stack)r#r8rrrr&r&r'r71s (zStackTransform._callcCs|j |jko|jkns(t|j|jt|jksBtg}x.t|j||jD]\}}|j|j|qZWt j ||jdS)N)rk) rkrNrrprrbrrar.r`r)r#r;rrrr&r&r'r=9s (zStackTransform._inversec Cs|j |jko|jkns(t|j|jt|jksBt|j |jko`|jknsjt|j|jt|jkstg}|j|}|j|}x.t|||jD]\}}}|j|j||qWt j ||jdS)N)rk) rkrNrrprrrbrar?r`r) r#r8r;rrrrrrr&r&r'r?As((  z#StackTransform.log_abs_det_jacobiancCstdd|jDS)Ncss|] }|jVqdS)N)rH)rUrr&r&r'r^Osz+StackTransform.bijective..)r_r)r#r&r&r'rHMszStackTransform.bijectivecCstjdd|jD|jS)NcSsg|] }|jqSr&)r()rUrr&r&r'rWSsz)StackTransform.domain..)rrrrk)r#r&r&r'r(QszStackTransform.domaincCstjdd|jD|jS)NcSsg|] }|jqSr&)r*)rUrr&r&r'rWWsz+StackTransform.codomain..)rrrrk)r#r&r&r'r*UszStackTransform.codomain)rr)r)r@rErFrGr"r3rr7r=r?rJrHrrSr(r*rKr&r&)r%r'rs   )+rcrrrer,typingrr`Ztorch.nn.functionalnnZ functionalrZtorch.distributionsrZtorch.distributions.utilsrrrrrr r __all__objectrr+rrrrrrrrrr r rrrrr rr&r&r&r's`     $=vD>'$`R#7e