+
    &j                     |   ^ RI t ^ RIt^ RIt^ RIt^ RIHt ^ RIt^ RIHu H	t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHtHtHtHtHt ^ RIHtHt ^ RIHt . R2Ot ! R R4      t ! R R]4      t ! R R]4      t]! . 4      t ! R  R]4      t ! R! R]4      t  ! R" R]4      t! ! R# R]4      t"R$ t# ! R% R]4      t$ ! R& R]4      t% ! R' R]4      t& ! R( R	]4      t' ! R) R
]4      t( ! R* R]4      t) ! R+ R]4      t* ! R, R]4      t+ ! R- R]4      t, ! R. R]4      t- ! R/ R]4      t. ! R0 R]4      t/ ! R1 R]4      t0R# )3    N)Sequence)Tensor)constraints)Distribution)_sum_rightmostbroadcast_alllazy_propertytril_matrix_to_vecvec_to_tril_matrix)padsoftplus)_NumberAbsTransformAffineTransformCatTransformComposeTransformCorrCholeskyTransformCumulativeDistributionTransformExpTransformIndependentTransformLowerCholeskyTransformPositiveDefiniteTransformPowerTransformReshapeTransformSigmoidTransformSoftplusTransformTanhTransformSoftmaxTransformStackTransformStickBreakingTransform	Transformc                      a a ] tR t^0t oRtRtRV3R lV 3R llltR t]V3R lR l4       t	]V3R lR	 l4       t
]V3R
 lR l4       tRR ltR tR tR tR tR tR tR tR tR tR tV3R ltRtVtV ;t# )r!   ac  
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.
Fc                $   < V ^8  d   QhRS[ RR/# )   
cache_sizereturnNint)format__classdict__s   "v/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/distributions/transforms.py__annotate__Transform.__annotate__a   s     	 	3 	t 	    c                   < Wn         R V n        V^ 8X  d   MV^8X  d	   RV n        M\        R4      h\        SV `  4        R # )Nzcache_size must be 0 or 1)NN)_cache_size_inv_cached_x_y
ValueErrorsuper__init__)selfr%   	__class__s   &&r+   r5   Transform.__init__a   s@    %=A	?1_)D899r.   c                D    V P                   P                  4       pR VR&   V# )Nr1   )__dict__copy)r6   states   & r+   __getstate__Transform.__getstate__l   s"    ""$fr.   c                    < V ^8  d   QhRS[ /# r$   r&   r'   )r)   r*   s   "r+   r,   r-   r   s     W W3 Wr.   c                    V P                   P                  V P                  P                  8X  d   V P                   P                  # \        R 4      h)z:Please use either .domain.event_dim or .codomain.event_dim)domain	event_dimcodomainr3   r6   s   &r+   rC   Transform.event_dimq   s:    ;;  DMM$;$;;;;(((UVVr.   c                   < V ^8  d   QhRR/# )r$   r&   r!    )r)   r*   s   "r+   r,   r-   x   s      [ r.   c                    RpV P                   e   V P                  4       pVf'   \        V 4      p\        P                  ! V4      V n         V# )zc
Returns the inverse :class:`Transform` of this transform.
This should satisfy ``t.inv.inv is t``.
N)r1   _InverseTransformweakrefref)r6   invs   & r+   rM   Transform.invw   sB     99 ))+C;#D)CC(DI
r.   c                    < V ^8  d   QhRS[ /# r@   r'   )r)   r*   s   "r+   r,   r-      s     " "c "r.   c                    \         h)z
Returns the sign of the determinant of the Jacobian, if applicable.
In general this only makes sense for bijective transforms.
NotImplementedErrorrE   s   &r+   signTransform.sign   s
     "!r.   c                    V P                   V8X  d   V # \        V 4      P                  \        P                  J d   \        V 4      ! VR 7      # \	        \        V 4       R24      h)r%   z.with_cache is not implemented)r0   typer5   r!   rR   r6   r%   s   &&r+   
with_cacheTransform.with_cache   sS    z)K:)"4"44:44!T$ZL0N"OPPr.   c                    WJ # NrH   r6   others   &&r+   __eq__Transform.__eq__   s
    }r.   c                .    V P                  V4      '       * # r\   )r_   r]   s   &&r+   __ne__Transform.__ne__   s    ;;u%%%r.   c                    V P                   ^ 8X  d   V P                  V4      # V P                  w  r#WJ d   V# V P                  V4      pW3V n        V# )z"
Computes the transform `x => y`.
)r0   _callr2   )r6   xx_oldy_oldys   &&   r+   __call__Transform.__call__   sS     q ::a= '':LJJqM4r.   c                    V P                   ^ 8X  d   V P                  V4      # V P                  w  r#WJ d   V# V P                  V4      pWA3V n        V# )z!
Inverts the transform `y => x`.
)r0   _inverser2   )r6   ri   rg   rh   rf   s   &&   r+   	_inv_callTransform._inv_call   sU     q ==##'':LMM!4r.   c                    \         h)z4
Abstract method to compute forward transformation.
rQ   r6   rf   s   &&r+   re   Transform._call   
     "!r.   c                    \         h)z4
Abstract method to compute inverse transformation.
rQ   r6   ri   s   &&r+   rm   Transform._inverse   rs   r.   c                    \         h)zE
Computes the log det jacobian `log |dy/dx|` given input and output.
rQ   r6   rf   ri   s   &&&r+   log_abs_det_jacobianTransform.log_abs_det_jacobian   rs   r.   c                <    V P                   P                  R ,           # )z())r7   __name__rE   s   &r+   __repr__Transform.__repr__   s    ~~&&--r.   c                    V# )zc
Infers the shape of the forward computation, given the input shape.
Defaults to preserving shape.
rH   r6   shapes   &&r+   forward_shapeTransform.forward_shape   	    
 r.   c                    V# )ze
Infers the shapes of the inverse computation, given the output shape.
Defaults to preserving shape.
rH   r   s   &&r+   inverse_shapeTransform.inverse_shape   r   r.   c                Z   < V ^8  d   Qh/ S[ P                  ;R&   S[ P                  ;R&   # )r$   rB   rD   r   
Constraint)r)   r*   s   "r+   r,   r-   0   s/     \ """] ^ $$$_ r.   )r0   r2   r1   r      )r|   
__module____qualname____firstlineno____doc__	bijectiver5   r=   propertyrC   rM   rS   rY   r_   rb   rj   rn   re   rm   ry   r}   r   r   __annotate_func____static_attributes____classdictcell____classcell__r7   r*   s   @@r+   r!   r!   0   s     *X I	 	
 W W
   " "Q&""".C  r.   c                   (  a a ] tR t^t oRtV3R lV 3R llt]P                  ! RR7      R 4       t]P                  ! RR7      R 4       t	]
V3R lR	 l4       t]
V3R
 lR l4       t]
V3R lR l4       tRR ltR tR tR tR tR tR tRtVtV ;t# )rJ   zp
Inverts a single :class:`Transform`.
This class is private; please instead use the ``Transform.inv`` property.
c                $   < V ^8  d   QhRS[ RR/# )r$   	transformr&   Nr!   )r)   r*   s   "r+   r,   _InverseTransform.__annotate__   s     ) )) ) )r.   c                H   < \         SV `  VP                  R 7       Wn        R# rV   N)r4   r5   r0   r1   )r6   r   r7   s   &&r+   r5   _InverseTransform.__init__   s    I$9$9:(	r.   Fis_discretec                `    V P                   f   \        R4      hV P                   P                  # N_inv must not be None)r1   AssertionErrorrD   rE   s   &r+   rB   _InverseTransform.domain   s*     99 !899yy!!!r.   c                `    V P                   f   \        R4      hV P                   P                  # r   )r1   r   rB   rE   s   &r+   rD   _InverseTransform.codomain   s*     99 !899yyr.   c                    < V ^8  d   QhRS[ /# r@   bool)r)   r*   s   "r+   r,   r      s     # #4 #r.   c                `    V P                   f   \        R4      hV P                   P                  # r   )r1   r   r   rE   s   &r+   r   _InverseTransform.bijective   s(    99 !899yy"""r.   c                    < V ^8  d   QhRS[ /# r@   r'   )r)   r*   s   "r+   r,   r      s      c r.   c                `    V P                   f   \        R4      hV P                   P                  # r   )r1   r   rS   rE   s   &r+   rS   _InverseTransform.sign   s&    99 !899yy~~r.   c                    < V ^8  d   QhRS[ /# r@   r   )r)   r*   s   "r+   r,   r      s      Y r.   c                    V P                   # r\   r1   rE   s   &r+   rM   _InverseTransform.inv   s    yyr.   c                ~    V P                   f   \        R4      hV P                  P                  V4      P                  # r   )r1   r   rM   rY   rX   s   &&r+   rY   _InverseTransform.with_cache  s3    99 !899xx"":.222r.   c                    \        V\        4      '       g   R # V P                  f   \        R4      hV P                  VP                  8H  # )Fr   )
isinstancerJ   r1   r   r]   s   &&r+   r_   _InverseTransform.__eq__  s<    %!23399 !899yyEJJ&&r.   c                `    V P                   P                   R \        V P                  4       R2# )())r7   r|   reprr1   rE   s   &r+   r}   _InverseTransform.__repr__  s)    ..))*!DO+<A>>r.   c                j    V P                   f   \        R4      hV P                   P                  V4      # r   )r1   r   rn   rq   s   &&r+   rj   _InverseTransform.__call__  s-    99 !899yy""1%%r.   c                l    V P                   f   \        R4      hV P                   P                  W!4      ) # r   )r1   r   ry   rx   s   &&&r+   ry   &_InverseTransform.log_abs_det_jacobian  s0    99 !899		..q444r.   c                8    V P                   P                  V4      # r\   )r1   r   r   s   &&r+   r   _InverseTransform.forward_shape      yy&&u--r.   c                8    V P                   P                  V4      # r\   )r1   r   r   s   &&r+   r   _InverseTransform.inverse_shape  r   r.   r   r   )r|   r   r   r   r   r5   r   dependent_propertyrB   rD   r   r   rS   rM   rY   r_   r}   rj   ry   r   r   r   r   r   r   s   @@r+   rJ   rJ      s     
) ) ##6" 7"
 ##6  7 
 # #
  
  3
'?&
5
.. .r.   rJ   c                   ,  a a ] tR tRt oRtRV3R lV 3R llltR t]P                  ! RR7      R 4       t	]P                  ! RR7      R	 4       t
]V3R
 lR l4       t]V3R lR l4       t]V3R lR l4       tRR ltR tR tR tR tR tRtVtV ;t# )r   i!  aF  
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.
c                :   < V ^8  d   QhRS[ S[,          RS[RR/# )r$   partsr%   r&   N)listr!   r(   )r)   r*   s   "r+   r,   ComposeTransform.__annotate__,  s&      d9o 3 t r.   c                   < V'       d    V Uu. uF  q3P                  V4      NK  	  pp\        SV `	  VR 7       Wn        R# u upi r   )rY   r4   r5   r   )r6   r   r%   partr7   s   &&& r+   r5   ComposeTransform.__init__,  s<    =BCUT__Z0UECJ/
 Ds   Ac                d    \        V\        4      '       g   R # V P                  VP                  8H  # F)r   r   r   r]   s   &&r+   r_   ComposeTransform.__eq__2  s&    %!122zzU[[((r.   Fr   c                z   V P                   '       g   \        P                  # V P                   ^ ,          P                  pV P                   R,          P                  P
                  p\        V P                   4       FY  pW#P                  P
                  VP                  P
                  ,
          ,          p\        W#P                  P
                  4      pK[  	  W!P
                  8  d   \        RV RVP
                   24      hW!P
                  8  d(   \        P                  ! WVP
                  ,
          4      pV# )r   
event_dim z must be >= domain.event_dim )
r   r   realrB   rD   rC   reversedmaxr   independent)r6   rB   rC   r   s   &   r+   rB   ComposeTransform.domain7  s     zzz###A%%JJrN++55	TZZ(D..1H1HHHII{{'<'<=I ) ''' YK'DVEUEUDVW  ''' ,,VAQAQ5QRFr.   c                h   V P                   '       g   \        P                  # V P                   R,          P                  pV P                   ^ ,          P                  P
                  pV P                    FY  pW#P                  P
                  VP                  P
                  ,
          ,          p\        W#P                  P
                  4      pK[  	  W!P
                  8  d   \        RV RVP
                   24      hW!P
                  8  d(   \        P                  ! WVP
                  ,
          4      pV# )r   r   z must be >= codomain.event_dim r   )	r   r   r   rD   rB   rC   r   r   r   )r6   rD   rC   r   s   &   r+   rD   ComposeTransform.codomainJ  s     zzz###::b>**JJqM((22	JJD004;;3H3HHHII}}'>'>?I  ))) YK'FxGYGYFZ[  )))"..xXEWEW9WXHr.   c                    < V ^8  d   QhRS[ /# r@   r   )r)   r*   s   "r+   r,   r   ^  s     4 44 4r.   c                    \         ;QJ d&    R  V P                   4       F  '       d   K   R# 	  R# ! R  V P                   4       4      # )c              3   8   "   T F  qP                   x  K  	  R # 5ir\   r   ).0ps   & r+   	<genexpr>-ComposeTransform.bijective.<locals>.<genexpr>_  s     3
1;;
   FT)allr   rE   s   &r+   r   ComposeTransform.bijective]  s3    s3

3ss3s3s3

333r.   c                    < V ^8  d   QhRS[ /# r@   r'   )r)   r*   s   "r+   r,   r   b  s      c r.   c                T    ^pV P                    F  pWP                  ,          pK  	  V# r   )r   rS   )r6   rS   r   s   &  r+   rS   ComposeTransform.signa  s%    A&&=D r.   c                    < V ^8  d   QhRS[ /# r@   r   )r)   r*   s   "r+   r,   r   i  s      Y r.   c                2   R pV P                   e   V P                  4       pVfn   \        \        V P                  4       Uu. uF  q"P                  NK  	  up4      p\
        P                  ! V4      V n         \
        P                  ! V 4      Vn         V# u upi r\   )r1   r   r   r   rM   rK   rL   )r6   rM   r   s   &  r+   rM   ComposeTransform.invh  sr    99 ))+C;"8DJJ3G#H3GaEE3G#HICC(DI{{4(CH
 $Is   Bc                V    V P                   V8X  d   V # \        V P                  VR 7      # rV   )r0   r   r   rX   s   &&r+   rY   ComposeTransform.with_caches  s&    z)K

zBBr.   c                <    V P                    F  pV! V4      pK  	  V# r\   )r   )r6   rf   r   s   && r+   rj   ComposeTransform.__call__x  s    JJDQA r.   c           	        V P                   '       g   \        P                  ! V4      # V.pV P                   R R  F!  pVP                  V! VR,          4      4       K#  	  VP                  V4       . pV P                  P
                  p\        V P                   VR R VR,          4       F  w  rApVP                  \        VP                  W4      WdP                  P
                  ,
          4      4       WdP                  P
                  VP                  P
                  ,
          ,          pK  	  \        P                  ! \        P                  V4      # )N:r   NNr   )r   torch
zeros_likeappendrB   rC   zipr   ry   rD   	functoolsreduceoperatoradd)r6   rf   ri   xsr   termsrC   s   &&&    r+   ry   %ComposeTransform.log_abs_det_jacobian}  s    zzz##A&& SJJsODIId2b6l# $
		!KK))	djj"Sb'2b6:JDQLL--a3YAVAV5V
 004;;3H3HHHI ; e44r.   c                N    V P                    F  pVP                  V4      pK  	  V# r\   )r   r   r6   r   r   s   && r+   r   ComposeTransform.forward_shape  s%    JJD&&u-E r.   c                `    \        V P                  4       F  pVP                  V4      pK  	  V# r\   )r   r   r   r  s   && r+   r   ComposeTransform.inverse_shape  s*    TZZ(D&&u-E )r.   c                    V P                   P                  R ,           pTRP                  V P                   Uu. uF  q"P	                  4       NK  	  up4      ,          pVR,          pV# u upi )z(
    z,
    z
))r7   r|   joinr   r}   )r6   
fmt_stringr   s   &  r+   r}   ComposeTransform.__repr__  sV    ^^,,y8
innDJJ%GJqjjlJ%GHH
e
 &Hs   A(
)r1   r   r   r   )r|   r   r   r   r   r5   r_   r   r   rB   rD   r	   r   rS   r   rM   rY   rj   ry   r   r   r}   r   r   r   r   s   @@r+   r   r   !  s      )
 ##6 7" ##6 7" 4 4    C

5*

 r.   c                     a a ] tR tRt oRtRV3R lV 3R llltRR lt]P                  ! RR7      R 4       t	]P                  ! RR7      R	 4       t
]V3R
 lR l4       t]V3R lR l4       tR tR tR tR tR tR tRtVtV ;t# )r   i  a  
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.
c                0   < V ^8  d   QhRS[ RS[RS[RR/# )r$   base_transformreinterpreted_batch_ndimsr%   r&   N)r!   r(   )r)   r*   s   "r+   r,   !IndependentTransform.__annotate__  s9     C C!C $'C 	C
 
Cr.   c                `   < \         SV `  VR 7       VP                  V4      V n        W n        R# r   )r4   r5   rY   r  r  )r6   r  r  r%   r7   s   &&&&r+   r5   IndependentTransform.__init__  s.     	J/,77
C)B&r.   c                l    V P                   V8X  d   V # \        V P                  V P                  VR 7      # r   )r0   r   r  r  rX   s   &&r+   rY   IndependentTransform.with_cache  s5    z)K#!?!?J
 	
r.   Fr   c                l    \         P                  ! V P                  P                  V P                  4      # r\   )r   r   r  rB   r  rE   s   &r+   rB   IndependentTransform.domain  s.     &&&&(F(F
 	
r.   c                l    \         P                  ! V P                  P                  V P                  4      # r\   )r   r   r  rD   r  rE   s   &r+   rD   IndependentTransform.codomain  s.     &&(($*H*H
 	
r.   c                    < V ^8  d   QhRS[ /# r@   r   )r)   r*   s   "r+   r,   r    s     - -4 -r.   c                .    V P                   P                  # r\   )r  r   rE   s   &r+   r   IndependentTransform.bijective  s    "",,,r.   c                    < V ^8  d   QhRS[ /# r@   r'   )r)   r*   s   "r+   r,   r    s     ( (c (r.   c                .    V P                   P                  # r\   )r  rS   rE   s   &r+   rS   IndependentTransform.sign  s    ""'''r.   c                    VP                  4       V P                  P                  8  d   \        R 4      hV P	                  V4      # Too few dimensions on input)dimrB   rC   r3   r  rq   s   &&r+   re   IndependentTransform._call  s7    557T[[***:;;""1%%r.   c                    VP                  4       V P                  P                  8  d   \        R 4      hV P                  P                  V4      # r  )r   rD   rC   r3   r  rM   ru   s   &&r+   rm   IndependentTransform._inverse  s=    557T]],,,:;;""&&q))r.   c                f    V P                   P                  W4      p\        W0P                  4      pV# r\   )r  ry   r   r  )r6   rf   ri   results   &&& r+   ry   )IndependentTransform.log_abs_det_jacobian  s-    $$99!?(F(FGr.   c                z    V P                   P                   R \        V P                  4       RV P                   R2# )r   z, r   )r7   r|   r   r  r  rE   s   &r+   r}   IndependentTransform.__repr__  s:    ..))*!D1D1D,E+FbIgIgHhhijjr.   c                8    V P                   P                  V4      # r\   )r  r   r   s   &&r+   r   "IndependentTransform.forward_shape      ""0077r.   c                8    V P                   P                  V4      # r\   )r  r   r   s   &&r+   r   "IndependentTransform.inverse_shape  r+  r.   )r  r  r   r   )r|   r   r   r   r   r5   rY   r   r   rB   rD   r   r   rS   re   rm   ry   r}   r   r   r   r   r   r   s   @@r+   r   r     s     C C
 ##6
 7

 ##6
 7

 - - ( (&
*

k88 8r.   c                      a a ] tR tRt oRtRtRV3R lV 3R lllt]P                  R 4       t	]P                  R 4       t
RR ltR	 tR
 tR tR tR tRtVtV ;t# )r   i  a  
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.
    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. (Default 0.)
Tc                X   < V ^8  d   QhRS[ P                  RS[ P                  RS[RR/# )r$   in_shape	out_shaper%   r&   N)r   Sizer(   )r)   r*   s   "r+   r,   ReshapeTransform.__annotate__  s;     
0 
0**
0 ::
0 	
0
 

0r.   c                  < \         P                  ! V4      V n        \         P                  ! V4      V n        V P                  P	                  4       V P                  P	                  4       8w  d   \        R 4      h\        SV `  VR7       R# )z6in_shape, out_shape have different numbers of elementsrV   N)r   r2  r0  r1  numelr3   r4   r5   )r6   r0  r1  r%   r7   s   &&&&r+   r5   ReshapeTransform.__init__  sc     

8,I.== DNN$8$8$::UVVJ/r.   c                r    \         P                  ! \         P                  \        V P                  4      4      # r\   )r   r   r   lenr0  rE   s   &r+   rB   ReshapeTransform.domain  s&     &&{'7'7T]]9KLLr.   c                r    \         P                  ! \         P                  \        V P                  4      4      # r\   )r   r   r   r8  r1  rE   s   &r+   rD   ReshapeTransform.codomain  s&     &&{'7'7T^^9LMMr.   c                l    V P                   V8X  d   V # \        V P                  V P                  VR 7      # r   )r0   r   r0  r1  rX   s   &&r+   rY   ReshapeTransform.with_cache  s,    z)Kt~~*UUr.   c                    VP                   R VP                  4       \        V P                  4      ,
           pVP	                  W P
                  ,           4      # r\   )r   r   r8  r0  reshaper1  )r6   rf   batch_shapes   && r+   re   ReshapeTransform._call  s=    gg<#dmm*< <=yy~~566r.   c                    VP                   R VP                  4       \        V P                  4      ,
           pVP	                  W P
                  ,           4      # r\   )r   r   r8  r1  r?  r0  )r6   ri   r@  s   && r+   rm   ReshapeTransform._inverse#  s=    gg=#dnn*= =>yy}}455r.   c                    VP                   R VP                  4       \        V P                  4      ,
           pVP	                  V4      # r\   )r   r   r8  r0  	new_zeros)r6   rf   ri   r@  s   &&& r+   ry   %ReshapeTransform.log_abs_det_jacobian'  s6    gg<#dmm*< <={{;''r.   c                4   \        V4      \        V P                  4      8  d   \        R 4      h\        V4      \        V P                  4      ,
          pWR V P                  8w  d   \        RWR  RV P                   24      hVRV V P                  ,           # r  NzShape mismatch: expected z	 but got )r8  r0  r3   r1  r6   r   cuts   && r+   r   ReshapeTransform.forward_shape+  s    u:DMM**:;;%j3t}}--;$--'+E$K=	$--Q  Tc{T^^++r.   c                4   \        V4      \        V P                  4      8  d   \        R 4      h\        V4      \        V P                  4      ,
          pWR V P                  8w  d   \        RWR  RV P                   24      hVRV V P                  ,           # rH  )r8  r1  r3   r0  rI  s   && r+   r   ReshapeTransform.inverse_shape5  s    u:DNN++:;;%j3t~~..;$..(+E$K=	$..AQR  Tc{T]]**r.   )r0  r1  r   r   )r|   r   r   r   r   r   r5   r   r   rB   rD   rY   re   rm   ry   r   r   r   r   r   r   s   @@r+   r   r     sw      I
0 
0 ##M $M ##N $NV
76(,+ +r.   c                   t   a  ] tR tRt o Rt]P                  t]P                  t	Rt
^tR tR tR tR tRtV tR	# )
r   i@  z0
Transform via the mapping :math:`y = \exp(x)`.
Tc                "    \        V\        4      # r\   )r   r   r]   s   &&r+   r_   ExpTransform.__eq__J      %..r.   c                "    VP                  4       # r\   )exprq   s   &&r+   re   ExpTransform._callM      uuwr.   c                "    VP                  4       # r\   logru   s   &&r+   rm   ExpTransform._inverseP  rU  r.   c                    V# r\   rH   rx   s   &&&r+   ry   !ExpTransform.log_abs_det_jacobianS      r.   rH   Nr|   r   r   r   r   r   r   rB   positiverD   r   rS   r_   re   rm   ry   r   r   r*   s   @r+   r   r   @  sE      F##HID/ r.   c                      a a ] tR tRt oRt]P                  t]P                  tRt	RV3R lV 3R lllt
RR lt]V3R lR l4       tR	 tR
 tR tR tR tR tRtVtV ;t# )r   iW  z<
Transform via the mapping :math:`y = x^{\text{exponent}}`.
Tc                *   < V ^8  d   QhRS[ RS[RR/# )r$   exponentr%   r&   Nr   r(   )r)   r*   s   "r+   r,   PowerTransform.__annotate__`  s"     3 3 3S 3 3r.   c                L   < \         SV `  VR 7       \        V4      w  V n        R# r   )r4   r5   r   rb  )r6   rb  r%   r7   s   &&&r+   r5   PowerTransform.__init__`  s"    J/(2r.   c                V    V P                   V8X  d   V # \        V P                  VR 7      # r   )r0   r   rb  rX   s   &&r+   rY   PowerTransform.with_cached  s&    z)Kdmm
CCr.   c                    < V ^8  d   QhRS[ /# r@   r'   )r)   r*   s   "r+   r,   rd  j  s     $ $c $r.   c                6    V P                   P                  4       # r\   )rb  rS   rE   s   &r+   rS   PowerTransform.signi  s    }}!!##r.   c                    \        V\        4      '       g   R # V P                  P                  VP                  4      P	                  4       P                  4       # r   )r   r   rb  eqr   itemr]   s   &&r+   r_   PowerTransform.__eq__m  s=    %00}}/335::<<r.   c                8    VP                  V P                  4      # r\   powrb  rq   s   &&r+   re   PowerTransform._callr  s    uuT]]##r.   c                F    VP                  ^V P                  ,          4      # r   rq  ru   s   &&r+   rm   PowerTransform._inverseu  s    uuQ&''r.   c                n    V P                   V,          V,          P                  4       P                  4       # r\   )rb  absrX  rx   s   &&&r+   ry   #PowerTransform.log_abs_det_jacobianx  s(    !A%**,0022r.   c                Z    \         P                  ! V\        V P                  R R4      4      # r   rH   r   broadcast_shapesgetattrrb  r   s   &&r+   r   PowerTransform.forward_shape{  "    %%eWT]]GR-PQQr.   c                Z    \         P                  ! V\        V P                  R R4      4      # rz  r{  r   s   &&r+   r   PowerTransform.inverse_shape~  r  r.   )rb  r   r   )r|   r   r   r   r   r   r^  rB   rD   r   r5   rY   r	   rS   r_   re   rm   ry   r   r   r   r   r   r   s   @@r+   r   r   W  sq      !!F##HI3 3D
 $ $=
$(3RR Rr.   c                     \         P                  ! V P                  4      p\         P                  ! \         P                  ! V 4      VP
                  R VP                  ,
          R7      #       ?minr   )r   finfodtypeclampsigmoidtinyeps)rf   r  s   & r+   _clipped_sigmoidr    s<    KK E;;u}}Q'UZZS599_MMr.   c                   t   a  ] tR tRt o Rt]P                  t]P                  t	Rt
^tR tR tR tR tRtV tR	# )
r   i  z_
Transform via the mapping :math:`y = \frac{1}{1 + \exp(-x)}` and :math:`x = \text{logit}(y)`.
Tc                "    \        V\        4      # r\   )r   r   r]   s   &&r+   r_   SigmoidTransform.__eq__      %!122r.   c                    \        V4      # r\   )r  rq   s   &&r+   re   SigmoidTransform._call  s    ""r.   c                    \         P                  ! VP                  4      pVP                  VP                  R VP
                  ,
          R7      pVP                  4       V) P                  4       ,
          # r  )r   r  r  r  r  r  rX  log1p)r6   ri   r  s   && r+   rm   SigmoidTransform._inverse  sK    AGG$GG

eiiG8uuw1"%%r.   c                h    \         P                  ! V) 4      ) \         P                  ! V4      ,
          # r\   )Fr   rx   s   &&&r+   ry   %SigmoidTransform.log_abs_det_jacobian  s!    

A2A..r.   rH   N)r|   r   r   r   r   r   r   rB   unit_intervalrD   r   rS   r_   re   rm   ry   r   r   r_  s   @r+   r   r     sE      F((HID3#&
/ /r.   c                   t   a  ] tR tRt o Rt]P                  t]P                  t	Rt
^tR tR tR tR tRtV tR	# )
r   i  z
Transform via the mapping :math:`\text{Softplus}(x) = \log(1 + \exp(x))`.
The implementation reverts to the linear function when :math:`x > 20`.
Tc                "    \        V\        4      # r\   )r   r   r]   s   &&r+   r_   SoftplusTransform.__eq__  s    %!233r.   c                    \        V4      # r\   r   rq   s   &&r+   re   SoftplusTransform._call  s    {r.   c                j    V) P                  4       P                  4       P                  4       V,           # r\   )expm1negrX  ru   s   &&r+   rm   SoftplusTransform._inverse  s'    zz|!%%'!++r.   c                    \        V) 4      ) # r\   r  rx   s   &&&r+   ry   &SoftplusTransform.log_abs_det_jacobian  s    !}r.   rH   Nr]  r_  s   @r+   r   r     sE     
 F##HID4, r.   c                      a  ] tR tRt o Rt]P                  t]P                  ! RR4      t	Rt
^tR tR tR tR tR	tV tR
# )r   i  a  
Transform via the mapping :math:`y = \tanh(x)`.

It is equivalent to

.. code-block:: python

    ComposeTransform(
        [
            AffineTransform(0.0, 2.0),
            SigmoidTransform(),
            AffineTransform(-1.0, 2.0),
        ]
    )

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.

r  Tc                "    \        V\        4      # r\   )r   r   r]   s   &&r+   r_   TanhTransform.__eq__  s    %//r.   c                "    VP                  4       # r\   )tanhrq   s   &&r+   re   TanhTransform._call  s    vvxr.   c                .    \         P                  ! V4      # r\   )r   atanhru   s   &&r+   rm   TanhTransform._inverse  s     {{1~r.   c                x    R \         P                  ! R 4      V,
          \        RV,          4      ,
          ,          # )       @g       )mathrX  r   rx   s   &&&r+   ry   "TanhTransform.log_abs_det_jacobian  s*     dhhsma'(4!8*<<==r.   rH   Ng      )r|   r   r   r   r   r   r   rB   intervalrD   r   rS   r_   re   rm   ry   r   r   r_  s   @r+   r   r     sL     , F##D#.HID0
> >r.   c                   f   a  ] tR tRt o Rt]P                  t]P                  t	R t
R tR tRtV tR# )r   i  z*Transform via the mapping :math:`y = |x|`.c                "    \        V\        4      # r\   )r   r   r]   s   &&r+   r_   AbsTransform.__eq__  rQ  r.   c                "    VP                  4       # r\   )rw  rq   s   &&r+   re   AbsTransform._call  rU  r.   c                    V# r\   rH   ru   s   &&r+   rm   AbsTransform._inverse  r\  r.   rH   N)r|   r   r   r   r   r   r   rB   r^  rD   r_   re   rm   r   r   r_  s   @r+   r   r     s2     5F##H/ r.   c                     a a ] tR tRt oRtRtRV3R lV 3R lllt]V3R lR l4       t]	P                  ! RR	7      R
 4       t]	P                  ! RR	7      R 4       tRR ltR t]V3R lR l4       tR tR tR tR tR tRtVtV ;t# )r   i  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.
Tc          
      V   < V ^8  d   QhRS[ S[,          RS[ S[,          RS[RS[RR/# )r$   locscalerC   r%   r&   N)r   floatr(   )r)   r*   s   "r+   r,   AffineTransform.__annotate__  sE     
$ 
$e^
$ ~
$ 	
$
 
$ 

$r.   c                L   < \         SV `  VR 7       Wn        W n        W0n        R# r   )r4   r5   r  r  
_event_dim)r6   r  r  rC   r%   r7   s   &&&&&r+   r5   AffineTransform.__init__  s$     	J/
#r.   c                    < V ^8  d   QhRS[ /# r@   r'   )r)   r*   s   "r+   r,   r    s      3 r.   c                    V P                   # r\   )r  rE   s   &r+   rC   AffineTransform.event_dim  s    r.   Fr   c                    V P                   ^ 8X  d   \        P                  # \        P                  ! \        P                  V P                   4      # r   rC   r   r   r   rE   s   &r+   rB   AffineTransform.domain  9     >>Q###&&{'7'7HHr.   c                    V P                   ^ 8X  d   \        P                  # \        P                  ! \        P                  V P                   4      # r   r  rE   s   &r+   rD   AffineTransform.codomain  r  r.   c                    V P                   V8X  d   V # \        V P                  V P                  V P                  VR 7      # r   )r0   r   r  r  rC   rX   s   &&r+   rY   AffineTransform.with_cache!  s7    z)KHHdjj$..Z
 	
r.   c                   \        V\        4      '       g   R # \        V P                  \        4      '       d?   \        VP                  \        4      '       d   V P                  VP                  8w  d   R # M=V P                  VP                  8H  P	                  4       P                  4       '       g   R # \        V P                  \        4      '       dA   \        VP                  \        4      '       d!   V P                  VP                  8w  d   R #  R# V P                  VP                  8H  P	                  4       P                  4       '       g   R # R# )FT)r   r   r  r   r   rn  r  r]   s   &&r+   r_   AffineTransform.__eq__(  s    %11dhh((Z		7-K-Kxx599$ % HH		)..05577djj'**z%++w/O/OzzU[[( )  JJ%++-22499;;r.   c                0   < V ^8  d   QhRS[ S[,          /# r@   rc  )r)   r*   s   "r+   r,   r  =  s     ! !fsl !r.   c                    \        V P                  \        4      '       d;   \        V P                  4      ^ 8  d   ^# \        V P                  4      ^ 8  d   R# ^ # V P                  P	                  4       # )r   r   )r   r  r   r  rS   rE   s   &r+   rS   AffineTransform.sign<  sU    djj'**djj)A-1Utzz9JQ9N2UTUUzz  r.   c                J    V P                   V P                  V,          ,           # r\   r  r  rq   s   &&r+   re   AffineTransform._callB  s    xx$**q.((r.   c                H    WP                   ,
          V P                  ,          # r\   r  ru   s   &&r+   rm   AffineTransform._inverseE  s    HH

**r.   c                    VP                   pV P                  p\        V\        4      '       d6   \        P
                  ! V\        P                  ! \        V4      4      4      pM$\        P                  ! V4      P                  4       pV P                  '       dV   VP                  4       R V P                  )  R,           pVP                  V4      P                  R4      pVR V P                  )  pVP                  V4      # )Nr   )r   )r   r  r   r   r   	full_liker  rX  rw  rC   sizeviewsumexpand)r6   rf   ri   r   r  r%  result_sizes   &&&    r+   ry   $AffineTransform.log_abs_det_jacobianH  s    

eW%%__QU(<=FYYu%))+F>>> ++-(94>>/:UBK[[-11"5F+T^^O,E}}U##r.   c           	         \         P                  ! V\        V P                  R R4      \        V P                  R R4      4      # rz  r   r|  r}  r  r  r   s   &&r+   r   AffineTransform.forward_shapeU  7    %%7488Wb174::wPR3S
 	
r.   c           	         \         P                  ! V\        V P                  R R4      \        V P                  R R4      4      # rz  r  r   s   &&r+   r   AffineTransform.inverse_shapeZ  r  r.   )r  r  r  r   r   r   )r|   r   r   r   r   r   r5   r   rC   r   r   rB   rD   rY   r_   rS   re   rm   ry   r   r   r   r   r   r   s   @@r+   r   r     s     	 I
$ 
$   ##6I 7I
 ##6I 7I

( ! !
)+$


 
r.   c                   z   a  ] tR tRt o Rt]P                  t]P                  t	Rt
R tR tRR ltR tR	 tR
tV tR# )r   i`  a|  
Transforms an unconstrained real vector :math:`x` with length :math:`D*(D-1)/2` into the
Cholesky factor of a D-dimension correlation matrix. This Cholesky factor is a lower
triangular matrix with positive diagonals and unit Euclidean norm for each row.
The transform is processed as follows:

    1. First we convert x into a lower triangular matrix in row order.
    2. For each row :math:`X_i` of the lower triangular part, we apply a *signed* version of
       class :class:`StickBreakingTransform` to transform :math:`X_i` into a
       unit Euclidean length vector using the following steps:
       - Scales into the interval :math:`(-1, 1)` domain: :math:`r_i = \tanh(X_i)`.
       - Transforms into an unsigned domain: :math:`z_i = r_i^2`.
       - Applies :math:`s_i = StickBreakingTransform(z_i)`.
       - Transforms back into signed domain: :math:`y_i = sign(r_i) * \sqrt{s_i}`.
Tc                   \         P                  ! V4      p\         P                  ! VP                  4      P                  pVP                  RV,           ^V,
          R7      p\        VRR7      pV^,          p^V,
          P                  4       P                  R4      pV\         P                  ! VP                  R,          VP                  VP                  R7      ,           pV\        VRRR13,          ^^ .^R7      ,          pV# )r   r  diag)r  device.Nvaluer   )r   r  r  r  r  r  r   sqrtcumprodeyer   r  r   )r6   rf   r  rzz1m_cumprod_sqrtri   s   &&     r+   re   CorrCholeskyTransform._callu  s    JJqMkk!''"&&GGSa#gG.qr* qDE<<>11"5		!''"+QWWQXXFF$S#2#X.Aa@@r.   c                Z   ^\         P                  ! W,          RR7      ,
          p\        VRRR13,          ^^ .^R7      p\        VRR7      p\        VRR7      pWEP	                  4       ,          pVP                  4       VP                  4       P                  4       ,
          ^,          pV# )r   r   .Nr  r  r   )r   cumsumr   r
   r  r  r  )r6   ri   y_cumsumy_cumsum_shiftedy_vecy_cumsum_vectrf   s   &&      r+   rm   CorrCholeskyTransform._inverse  s     u||AEr22xSbS1Aq6C"12.)*:D''))WWY(A-r.   Nc                L   ^W",          P                  RR7      ,
          p\        VRR7      pRVP                  4       P                  R4      ,          pRV\	        RV,          4      ,           \
        P                  ! R4      ,
          P                  RR7      ,          pWg,           # )r   r  r        ?r  r   )r  r
   rX  r  r   r  )r6   rf   ri   intermediates
y1m_cumsumy1m_cumsum_trilstick_breaking_logdettanh_logdets   &&&&    r+   ry   *CorrCholeskyTransform.log_abs_det_jacobian  s     !%B//
 -ZbA #&;&;&=&A&A"&E EAa 00488C=@EE"EMM$22r.   c                    \        V4      ^8  d   \        R4      hVR,          p\        R^V,          ,           R,          R,           4      pW3^,
          ,          ^,          V8w  d   \        R4      hVRR W33,           # )r   r  g      ?r  z.Input is not a flattened lower-diagonal numberNr   )r8  r3   round)r6   r   NDs   &&  r+   r   #CorrCholeskyTransform.forward_shape  sp    u:>:;;"I4!a%<C'#-.A;!q MNNSbzQF""r.   c                    \        V4      ^8  d   \        R4      hVR,          VR,          8w  d   \        R4      hVR,          pW"^,
          ,          ^,          pVRR V3,           # )r$   r  zInput is not squareNr  r   r8  r3   )r6   r   r  r  s   &&  r+   r   #CorrCholeskyTransform.inverse_shape  sa    u:>:;;9b	!233"IQK1SbzQD  r.   rH   r\   )r|   r   r   r   r   r   real_vectorrB   corr_choleskyrD   r   re   rm   ry   r   r   r   r   r_  s   @r+   r   r   `  sE       $$F((HI
3#! !r.   c                   r   a  ] tR tRt o Rt]P                  t]P                  t	R t
R tR tR tR tRtV tR	# )
r   i  a$  
Transform from unconstrained space to the simplex via :math:`y = \exp(x)` then
normalizing.

This is not bijective and cannot be used for HMC. However this acts mostly
coordinate-wise (except for the final normalization), and thus is
appropriate for coordinate-wise optimization algorithms.
c                "    \        V\        4      # r\   )r   r   r]   s   &&r+   r_   SoftmaxTransform.__eq__  r  r.   c                    TpW"P                  RR4      ^ ,          ,
          P                  4       pW3P                  RR4      ,          # )r   Tr   )r   rS  r  )r6   rf   logprobsprobss   &&  r+   re   SoftmaxTransform._call  s<    LLT2155::<yyT***r.   c                &    TpVP                  4       # r\   rW  )r6   ri   r  s   && r+   rm   SoftmaxTransform._inverse  s    yy{r.   c                <    \        V4      ^8  d   \        R4      hV# r   r  r  r   s   &&r+   r   SoftmaxTransform.forward_shape      u:>:;;r.   c                <    \        V4      ^8  d   \        R4      hV# r  r  r   s   &&r+   r   SoftmaxTransform.inverse_shape  r  r.   rH   N)r|   r   r   r   r   r   r  rB   simplexrD   r_   re   rm   r   r   r   r   r_  s   @r+   r   r     s@      $$F""H3+

 r.   c                   |   a  ] tR tRt o Rt]P                  t]P                  t	Rt
R tR tR tR tR tR	 tR
tV tR# )r    i  a  
Transform from unconstrained space to the simplex of one additional
dimension via a stick-breaking process.

This transform arises as an iterated sigmoid transform in a stick-breaking
construction of the `Dirichlet` distribution: the first logit is
transformed via sigmoid to the first probability and the probability of
everything else, and then the process recurses.

This is bijective and appropriate for use in HMC; however it mixes
coordinates together and is less appropriate for optimization.
Tc                "    \        V\        4      # r\   )r   r    r]   s   &&r+   r_   StickBreakingTransform.__eq__      %!788r.   c                ^   VP                   R,          ^,           VP                  VP                   R,          4      P                  R4      ,
          p\        WP	                  4       ,
          4      p^V,
          P                  R4      p\        V^ ^.^R7      \        V^^ .^R7      ,          pV# )r   r  r   )r   new_onesr  r  rX  r  r   )r6   rf   offsetr  	z_cumprodri   s   &&    r+   re   StickBreakingTransform._call  s    q1::aggbk#:#A#A"#EEQ-.UOOB'	Aq6#c)aV1&EEr.   c                   VR RR13,          pVP                   R,          VP                  VP                   R,          4      P                  R4      ,
          p^VP                  R4      ,
          p\        P                  ! V\        P
                  ! VP                  4      P                  R7      pVP                  4       VP                  4       ,
          VP                  4       ,           pV# ).N)r  r   )	r   r(  r  r   r  r  r  r  rX  )r6   ri   y_cropr)  sfrf   s   &&    r+   rm   StickBreakingTransform._inverse  s    38qzz&,,r*:;BB2FFr"" [[QWW!5!:!:;JJL2668#fjjl2r.   c                l   VP                   R,          ^,           VP                  VP                   R,          4      P                  R4      ,
          pWP                  4       ,
          pV) \        P
                  ! V4      ,           VRRR13,          P                  4       ,           P                  R4      pV# )r   .Nr   )r   r(  r  rX  r  
logsigmoidr  )r6   rf   ri   r)  detJs   &&&  r+   ry   +StickBreakingTransform.log_abs_det_jacobian  s~    q1::aggbk#:#A#A"#EE

Q\\!_$qcrc{'88==bAr.   c                n    \        V4      ^8  d   \        R4      hVRR VR,          ^,           3,           # r   r  Nr   r  r   s   &&r+   r   $StickBreakingTransform.forward_shape  5    u:>:;;SbzU2Y],,,r.   c                n    \        V4      ^8  d   \        R4      hVRR VR,          ^,
          3,           # r5  r  r   s   &&r+   r   $StickBreakingTransform.inverse_shape	  r7  r.   rH   N)r|   r   r   r   r   r   r  rB   r"  rD   r   r_   re   rm   ry   r   r   r   r   r_  s   @r+   r    r      sJ      $$F""HI9-
- -r.   c                      a  ] tR tRt o Rt]P                  ! ]P                  ^4      t]P                  t
R tR tR tRtV tR# )r   i  z
Transform from unconstrained matrices to lower-triangular matrices with
nonnegative diagonal entries.

This is useful for parameterizing positive definite matrices in terms of
their Cholesky factorization.
c                "    \        V\        4      # r\   )r   r   r]   s   &&r+   r_   LowerCholeskyTransform.__eq__  r&  r.   c                    VP                  R4      VP                  RRR7      P                  4       P                  4       ,           # r   )dim1dim2r   r  )trildiagonalrS  
diag_embedrq   s   &&r+   re   LowerCholeskyTransform._call  4    vvbzAJJBRJ8<<>IIKKKr.   c                    VP                  R4      VP                  RRR7      P                  4       P                  4       ,           # r>  )rA  rB  rX  rC  ru   s   &&r+   rm   LowerCholeskyTransform._inverse!  rE  r.   rH   N)r|   r   r   r   r   r   r   r   rB   lower_choleskyrD   r_   re   rm   r   r   r_  s   @r+   r   r     sF      $$[%5%5q9F))H9LL Lr.   c                      a  ] tR tRt o Rt]P                  ! ]P                  ^4      t]P                  t
R tR tR tRtV tR# )r   i%  zF
Transform from unconstrained matrices to positive-definite matrices.
c                "    \        V\        4      # r\   )r   r   r]   s   &&r+   r_    PositiveDefiniteTransform.__eq__-  s    %!:;;r.   c                F    \        4       ! V4      pWP                  ,          # r\   )r   mTrq   s   &&r+   re   PositiveDefiniteTransform._call0  s    "$Q'44xr.   c                r    \         P                  P                  V4      p\        4       P	                  V4      # r\   )r   linalgcholeskyr   rM   ru   s   &&r+   rm   "PositiveDefiniteTransform._inverse4  s*    LL!!!$%'++A..r.   rH   N)r|   r   r   r   r   r   r   r   rB   positive_definiterD   r_   re   rm   r   r   r_  s   @r+   r   r   %  sC      $$[%5%5q9F,,H</ /r.   c                   
  a a ] tR tRt oRtRV3R lV 3R lllt]V3R lR l4       t]V3R lR l4       tRR	 lt	R
 t
R tR t]V3R lR l4       t]P                   R 4       t]P                   R 4       tV3R ltRtVtV ;t# )r   i9  a  
Transform functor that applies a sequence of transforms `tseq`
component-wise to each submatrix at `dim`, of length `lengths[dim]`,
in a way compatible with :func:`torch.cat`.

Example::

   x0 = torch.cat([torch.range(1, 10), torch.range(1, 10)], dim=0)
   x = torch.cat([x0, x0], dim=0)
   t0 = CatTransform([ExpTransform(), identity_transform], dim=0, lengths=[10, 10])
   t = CatTransform([t0, t0], dim=0, lengths=[20, 20])
   y = t(x)
c          
      d   < V ^8  d   QhRS[ S[,          RS[RS[ S[,          R,          RS[RR/# )r$   tseqr   lengthsNr%   r&   r   r!   r(   )r)   r*   s   "r+   r,   CatTransform.__annotate__J  sK      y!  #%	
  
r.   c                b  < \         ;QJ d    R  V 4       F  '       d   K   RM	  RM! R  V 4       4      '       g   \        R4      hV'       d    V Uu. uF  qUP                  V4      NK  	  pp\        SV `  VR7       \        V4      V n        Vf   ^.\        V P                  4      ,          p\        V4      V n        \        V P                  4      \        V P                  4      8w  d9   \        R\        V P                  4       R\        V P                  4       R24      hW n	        R# u upi )	c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir\   r   r!   r   r  s   & r+   r   (CatTransform.__init__.<locals>.<genexpr>Q       :T:a++T   FT0All elements of tseq must be Transform instancesrV   Nz	lengths (z) must match transforms (r   )
r   r   rY   r4   r5   r   
transformsr8  rW  r   )r6   rV  r   rW  r%   r  r7   s   &&&&& r+   r5   CatTransform.__init__J  s     s:T:sss:T::: !STT6:;dLL,dD;J/t*?cC00GG}t||DOO 44 C-..GDOOH\G]]^_   <s   D,c                    < V ^8  d   QhRS[ /# r@   r'   )r)   r*   s   "r+   r,   rY  a  s     9 93 9r.   c                :    \        R  V P                   4       4      # )c              3   8   "   T F  qP                   x  K  	  R # 5ir\   )rC   r]  s   & r+   r   )CatTransform.event_dim.<locals>.<genexpr>b       81;;r   )r   rb  rE   s   &r+   rC   CatTransform.event_dim`  s    8888r.   c                    < V ^8  d   QhRS[ /# r@   r'   )r)   r*   s   "r+   r,   rY  e  s     ! ! !r.   c                ,    \        V P                  4      # r\   )r  rW  rE   s   &r+   lengthCatTransform.lengthd  s    4<<  r.   c                    V P                   V8X  d   V # \        V P                  V P                  V P                  V4      # r\   )r0   r   rb  r   rW  rX   s   &&r+   rY   CatTransform.with_cacheh  s2    z)KDOOTXXt||ZPPr.   c                   VP                  4       ) V P                   u;8:  d   VP                  4       8  g-   M \        R V P                    RVP                  4        R24      hVP                  V P                   4      V P                  8w  dB   \        RV P                    RVP                  V P                   4       RV P                   24      h. p^ p\	        V P
                  V P                  4       F@  w  rEVP                  V P                   W54      pVP                  V! V4      4       W5,           pKB  	  \        P                  ! W P                   R7      # )dim  out of range for tensor with  dimensionsx.size() =  must equal length r  )r   r   r  rl  r   rb  rW  narrowr   r   cat)r6   rf   yslicesstarttransrl  xslices   &&     r+   re   CatTransform._callm  s   DHH.quuw. txxj >quuwi{S  66$((t{{* $((4txx(8'99LT[[MZ   $,,?MEXXdhh6FNN5=)NE @ yyhh//r.   c                   VP                  4       ) V P                   u;8:  d   VP                  4       8  g-   M \        R V P                    RVP                  4        R24      hVP                  V P                   4      V P                  8w  dB   \        RV P                    RVP                  V P                   4       RV P                   24      h. p^ p\	        V P
                  V P                  4       FI  w  rEVP                  V P                   W54      pVP                  VP                  V4      4       W5,           pKK  	  \        P                  ! W P                   R7      # )rq  rr  rs  y.size(ru  rv  r  )r   r   r  rl  r   rb  rW  rw  r   rM   r   rx  )r6   ri   xslicesrz  r{  rl  yslices   &&     r+   rm   CatTransform._inverse~  s   DHH.quuw. txxj >quuwi{S  66$((t{{* $((4txx(8'99LT[[MZ   $,,?MEXXdhh6FNN599V,-NE @ yyhh//r.   c                   VP                  4       ) V P                   u;8:  d   VP                  4       8  g-   M \        R V P                    RVP                  4        R24      hVP                  V P                   4      V P                  8w  dB   \        RV P                    RVP                  V P                   4       RV P                   24      hVP                  4       ) V P                   u;8:  d   VP                  4       8  g-   M \        R V P                    RVP                  4        R24      hVP                  V P                   4      V P                  8w  dB   \        RV P                    RVP                  V P                   4       RV P                   24      h. p^ p\	        V P
                  V P                  4       F  w  rVVP                  V P                   WF4      pVP                  V P                   WF4      pVP                  Wx4      p	VP                  V P                  8  d'   \        WP                  VP                  ,
          4      p	VP                  V	4       WF,           pK  	  V P                   p
V
^ 8  d   WP                  4       ,
          p
WP                  ,           p
V
^ 8  d   \        P                  ! W:R7      # \        V4      # )	rq   out of range for x with rs  rt  ru  rv   out of range for y with r  r  )r   r   r  rl  r   rb  rW  rw  ry   rC   r   r   r   rx  r  )r6   rf   ri   
logdetjacsrz  r{  rl  r|  r  	logdetjacr   s   &&&        r+   ry   !CatTransform.log_abs_det_jacobian  s'   DHH.quuw. txxj 9!%%'+N  66$((t{{* $((4txx(8'99LT[[MZ  DHH.quuw. txxj 9!%%'+N  66$((t{{* $((4txx(8'99LT[[MZ  
 $,,?MEXXdhh6FXXdhh6F226BI/*9nnu6VW	i(NE @ hh!8-CNN"799Z11z?"r.   c                    < V ^8  d   QhRS[ /# r@   r   )r)   r*   s   "r+   r,   rY         9 94 9r.   c                    \         ;QJ d&    R  V P                   4       F  '       d   K   R# 	  R# ! R  V P                   4       4      # )c              3   8   "   T F  qP                   x  K  	  R # 5ir\   r   r]  s   & r+   r   )CatTransform.bijective.<locals>.<genexpr>  rh  r   FTr   rb  rE   s   &r+   r   CatTransform.bijective  3    s88ss8s8s8888r.   c                    \         P                  ! V P                   Uu. uF  qP                  NK  	  upV P                  V P
                  4      # u upi r\   )r   rx  rb  rB   r   rW  r6   r  s   & r+   rB   CatTransform.domain  s<     #/!XX/4<<
 	
/   Ac                    \         P                  ! V P                   Uu. uF  qP                  NK  	  upV P                  V P
                  4      # u upi r\   )r   rx  rb  rD   r   rW  r  s   & r+   rD   CatTransform.codomain  s<     !%1AZZ1488T\\
 	
1r  c                6   < V ^8  d   Qh/ S[ S[,          ;R&   # r$   rb  r   r!   )r)   r*   s   "r+   r,   rY  9  s      Y r.   )r   rW  rb  )r   Nr   r   )r|   r   r   r   r   r5   r	   rC   rl  rY   re   rm   ry   r   r   r   r   rB   rD   r   r   r   r   r   s   @@r+   r   r   9  s       , 9 9 ! !Q
0"0"##J 9 9 ##
 $

 ##
 $
Q  r.   c                      a a ] tR tRt oRtRV3R lV 3R llltRR ltR tR tR t	R	 t
]V3R
 lR l4       t]P                  R 4       t]P                  R 4       tV3R ltRtVtV ;t# )r   i  a7  
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)
c                @   < V ^8  d   QhRS[ S[,          RS[RS[RR/# )r$   rV  r   r%   r&   NrX  )r)   r*   s   "r+   r,   StackTransform.__annotate__  s2     	 	Y'	.1	CF			r.   c                6  < \         ;QJ d    R  V 4       F  '       d   K   RM	  RM! R  V 4       4      '       g   \        R4      hV'       d    V Uu. uF  qDP                  V4      NK  	  pp\        SV `  VR7       \        V4      V n        W n        R# u upi )c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir\   r\  r]  s   & r+   r   *StackTransform.__init__.<locals>.<genexpr>  r_  r`  FTra  rV   N)r   r   rY   r4   r5   r   rb  r   )r6   rV  r   r%   r  r7   s   &&&& r+   r5   StackTransform.__init__  su     s:T:sss:T::: !STT6:;dLL,dD;J/t* <s   Bc                j    V P                   V8X  d   V # \        V P                  V P                  V4      # r\   )r0   r   rb  r   rX   s   &&r+   rY   StackTransform.with_cache  s,    z)KdootxxDDr.   c                    \        VP                  V P                  4      4       Uu. uF  q!P                  V P                  V4      NK   	  up# u upi r\   )ranger  r   select)r6   r  is   && r+   _sliceStackTransform._slice  s;    /4QVVDHH5E/FG/F!1%/FGGGs   $Ac           
        VP                  4       ) V P                   u;8:  d   VP                  4       8  g-   M \        R V P                    RVP                  4        R24      hVP                  V P                   4      \        V P                  4      8w  dK   \        RV P                    RVP                  V P                   4       R\        V P                  4       24      h. p\        V P                  V4      V P                  4       F  w  r4VP                  V! V4      4       K  	  \        P                  ! W P                   R7      # )rq  rr  rs  rt  ru   must equal len(transforms) r  )
r   r   r  r8  rb  r   r  r   r   stack)r6   rf   ry  r|  r{  s   &&   r+   re   StackTransform._call  s    DHH.quuw. txxj >quuwi{S  66$((s4??33 $((4txx(8'99UVYZ^ZiZiVjUkl   QAMFNN5=) B{{711r.   c           
        VP                  4       ) V P                   u;8:  d   VP                  4       8  g-   M \        R V P                    RVP                  4        R24      hVP                  V P                   4      \        V P                  4      8w  dK   \        RV P                    RVP                  V P                   4       R\        V P                  4       24      h. p\        V P                  V4      V P                  4       F%  w  r4VP                  VP                  V4      4       K'  	  \        P                  ! W P                   R7      # )rq  rr  rs  r  ru  r  r  )r   r   r  r8  rb  r   r  r   rM   r   r  )r6   ri   r  r  r{  s   &&   r+   rm   StackTransform._inverse  s    DHH.quuw. txxj >quuwi{S  66$((s4??33 $((4txx(8'99UVYZ^ZiZiVjUkl   QAMFNN599V,- B{{711r.   c           
        VP                  4       ) V P                   u;8:  d   VP                  4       8  g-   M \        R V P                    RVP                  4        R24      hVP                  V P                   4      \        V P                  4      8w  dK   \        RV P                    RVP                  V P                   4       R\        V P                  4       24      hVP                  4       ) V P                   u;8:  d   VP                  4       8  g-   M \        R V P                    RVP                  4        R24      hVP                  V P                   4      \        V P                  4      8w  dK   \        RV P                    RVP                  V P                   4       R\        V P                  4       24      h. pV P                  V4      pV P                  V4      p\        WTV P                  4       F&  w  rgpVP                  VP                  Wg4      4       K(  	  \        P                  ! W0P                   R7      # )	rq  r  rs  rt  ru  r  r  r  r  )r   r   r  r8  rb  r  r   r   ry   r   r  )	r6   rf   ri   r  ry  r  r|  r  r{  s	   &&&      r+   ry   #StackTransform.log_abs_det_jacobian  s   DHH.quuw. txxj 9!%%'+N  66$((s4??33 $((4txx(8'99UVYZ^ZiZiVjUkl  DHH.quuw. txxj 9!%%'+N  66$((s4??33 $((4txx(8'99UVYZ^ZiZiVjUkl  
++a.++a.%(4??%K!FEe88HI &L{{:8844r.   c                    < V ^8  d   QhRS[ /# r@   r   )r)   r*   s   "r+   r,   r    r  r.   c                    \         ;QJ d&    R  V P                   4       F  '       d   K   R# 	  R# ! R  V P                   4       4      # )c              3   8   "   T F  qP                   x  K  	  R # 5ir\   r   r]  s   & r+   r   +StackTransform.bijective.<locals>.<genexpr>  rh  r   FTr  rE   s   &r+   r   StackTransform.bijective  r  r.   c                    \         P                  ! V P                   Uu. uF  qP                  NK  	  upV P                  4      # u upi r\   )r   r  rb  rB   r   r  s   & r+   rB   StackTransform.domain!  s3       DOO!DOq((O!DdhhOO!D   Ac                    \         P                  ! V P                   Uu. uF  qP                  NK  	  upV P                  4      # u upi r\   )r   r  rb  rD   r   r  s   & r+   rD   StackTransform.codomain&  s3       doo!Fo**o!FQQ!Fr  c                6   < V ^8  d   Qh/ S[ S[,          ;R&   # r  r  )r)   r*   s   "r+   r,   r    s      Y r.   )r   rb  r  r   )r|   r   r   r   r   r5   rY   r  re   rm   ry   r   r   r   r   rB   rD   r   r   r   r   r   s   @@r+   r   r     s     
	 	E
H2250 9 9 ##P $P ##R $RC  r.   c                      a a ] tR tRt oRtRt]P                  t^t	RV3R lV 3R lllt
]V3R lR l4       tR tR	 tR
 tRR ltRtVtV ;t# )r   i,  a  
Transform via the cumulative distribution function of a probability distribution.

Args:
    distribution (Distribution): Distribution whose cumulative distribution function to use for
        the transformation.

Example::

    # Construct a Gaussian copula from a multivariate normal.
    base_dist = MultivariateNormal(
        loc=torch.zeros(2),
        scale_tril=LKJCholesky(2).sample(),
    )
    transform = CumulativeDistributionTransform(Normal(0, 1))
    copula = TransformedDistribution(base_dist, [transform])
Tc                *   < V ^8  d   QhRS[ RS[RR/# )r$   distributionr%   r&   N)r   r(   )r)   r*   s   "r+   r,   ,CumulativeDistributionTransform.__annotate__C  s"     ) )\ )s )4 )r.   c                4   < \         SV `  VR 7       Wn        R# r   )r4   r5   r  )r6   r  r%   r7   s   &&&r+   r5   (CumulativeDistributionTransform.__init__C  s    J/(r.   c                B   < V ^8  d   QhRS[ P                  R,          /# )r$   r&   Nr   )r)   r*   s   "r+   r,   r  H  s     ) )..5 )r.   c                .    V P                   P                  # r\   )r  supportrE   s   &r+   rB   &CumulativeDistributionTransform.domainG  s      (((r.   c                8    V P                   P                  V4      # r\   )r  cdfrq   s   &&r+   re   %CumulativeDistributionTransform._callK  s      $$Q''r.   c                8    V P                   P                  V4      # r\   )r  icdfru   s   &&r+   rm   (CumulativeDistributionTransform._inverseN  s      %%a((r.   c                8    V P                   P                  V4      # r\   )r  log_probrx   s   &&&r+   ry   4CumulativeDistributionTransform.log_abs_det_jacobianQ  s      ))!,,r.   c                V    V P                   V8X  d   V # \        V P                  VR 7      # r   )r0   r   r  rX   s   &&r+   rY   *CumulativeDistributionTransform.with_cacheT  s(    z)K.t/@/@ZXXr.   )r  r   r   )r|   r   r   r   r   r   r   r  rD   rS   r5   r   rB   re   rm   ry   rY   r   r   r   r   s   @@r+   r   r   ,  sZ     $ I((HD) ) ) )()-Y Yr.   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   identity_transform)1r   r  r   rK   collections.abcr   r   torch.nn.functionalnn
functionalr  r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   r   r	   r
   r   r   r   torch.typesr   __all__r!   rJ   r   r  r   r   r   r   r  r   r   r   r   r   r   r   r    r   r   r   r   r   rH   r.   r+   <module>r     sg       $     + 9  . 0f fRE.	 E.Py D &b) K89 K8\I+y I+X9 .(RY (RVN
/y /2	 0*>I *>Z9  h
i h
VP!I P!f!y !H5-Y 5-pLY L,/	 /(K
9 K
\bRY bRJ+Yi +Yr.   