
    9ibT                        S SK JrJrJr   S SKr/ SQr " S S5      r " S S\5      rS r " S	 S
\	\5      r
 " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S \5      r " S! S"\5      r " S# S$\5      r " S% S&\5      r " S' S(\5      r " S) S*\5      r " S+ S,\5      r " S- S.\5      r " S/ S0\5      r " S1 S2\5      r " S3 S4\5      r " S5 S6\5      r  " S7 S8\5      r! " S9 S:\5      r"\" 5       r#\
r$\r%\" 5       r&\" 5       r'\" S 5      r(\" S;5      r)\r*\" 5       r+\%" \+S;5      r,\" S<5      r-\" S<5      r.\r/\r0\r1\r2\" S<S=5      r3\r4\r5\" 5       r6\" 5       r7\" 5       r8\" 5       r9\" 5       r:\" 5       r;\" 5       r<\ " 5       r=\!r>\"r?g)>    )AnyCallableOptionalN) 
Constraintbooleancatcorr_cholesky	dependentdependent_propertygreater_thangreater_than_eqindependentinteger_intervalintervalhalf_open_intervalis_dependent	less_thanlower_choleskylower_triangularMixtureSameFamilyConstraintmultinomialnonnegativenonnegative_integerone_hotpositivepositive_semidefinitepositive_definitepositive_integerrealreal_vectorsimplexsquarestack	symmetricunit_intervalc                   ,    \ rS rSrSrSrSrS rS rSr	g)	r   O   a  
Abstract base class for constraints.

A constraint object represents a region over which a variable is valid,
e.g. within which a variable can be optimized.

Attributes:
    is_discrete (bool): Whether constrained space is discrete.
        Defaults to False.
    event_dim (int): Number of rightmost dimensions that together define
        an event. The :meth:`check` method will remove this many dimensions
        when computing validity.
Fr   c                     [         e)z{
Returns a byte tensor of ``sample_shape + batch_shape`` indicating
whether each event in value satisfies this constraint.
)NotImplementedErrorselfvalues     _/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/distributions/constraints.pycheckConstraint.checka   s
    
 "!    c                 :    U R                   R                  SS  S-   $ )N   z())	__class____name__r+   s    r-   __repr__Constraint.__repr__h   s    ~~&&qr*T11r0    N)
r4   
__module____qualname____firstlineno____doc__is_discrete	event_dimr.   r6   __static_attributes__r8   r0   r-   r   r   O   s     KI"2r0   r   c                   |   ^  \ rS rSrSr\\S.U 4S jjr\S\4S j5       r	\S\
4S j5       r\\S.S jrS	 rS
rU =r$ )
_Dependentl   a!  
Placeholder for variables whose support depends on other variables.
These variables obey no simple coordinate-wise constraints.

Args:
    is_discrete (bool): Optional value of ``.is_discrete`` in case this
        can be computed statically. If not provided, access to the
        ``.is_discrete`` attribute will raise a NotImplementedError.
    event_dim (int): Optional value of ``.event_dim`` in case this
        can be computed statically. If not provided, access to the
        ``.event_dim`` attribute will raise a NotImplementedError.
r=   r>   c                :   > Xl         X l        [        TU ]  5         g N)_is_discrete
_event_dimsuper__init__)r+   r=   r>   r3   s      r-   rI   _Dependent.__init__z   s    '#r0   returnc                 V    U R                   [        L a  [        S5      eU R                   $ )Nz,.is_discrete cannot be determined statically)rF   NotImplementedr)   r5   s    r-   r=   _Dependent.is_discrete   s(    .%&TUU   r0   c                 V    U R                   [        L a  [        S5      eU R                   $ )Nz*.event_dim cannot be determined statically)rG   rM   r)   r5   s    r-   r>   _Dependent.event_dim   s$    ??n,%&RSSr0   c                h    U[         L a  U R                  nU[         L a  U R                  n[        XS9$ )zo
Support for syntax to customize static attributes::

    constraints.dependent(is_discrete=True, event_dim=1)
rC   )rM   rF   rG   rA   )r+   r=   r>   s      r-   __call___Dependent.__call__   s3     .(++K&IkGGr0   c                     [        S5      e)Nz1Cannot determine validity of dependent constraint)
ValueErrorr+   xs     r-   r.   _Dependent.check   s    LMMr0   rG   rF   )r4   r9   r:   r;   r<   rM   rI   propertyboolr=   intr>   rR   r.   r?   __classcell__r3   s   @r-   rA   rA   l   sh     '5  
 !T ! !
 3  
 '5 
HN Nr0   rA   c                 "    [        U [        5      $ )a  
Checks if ``constraint`` is a ``_Dependent`` object.

Args:
    constraint : A ``Constraint`` object.

Returns:
    ``bool``: True if ``constraint`` can be refined to the type ``_Dependent``, False otherwise.

Examples:
    >>> import torch
    >>> from torch.distributions import Bernoulli
    >>> from torch.distributions.constraints import is_dependent

    >>> dist = Bernoulli(probs=torch.tensor([0.6], requires_grad=True))
    >>> constraint1 = dist.arg_constraints["probs"]
    >>> constraint2 = dist.arg_constraints["logits"]

    >>> for constraint in [constraint1, constraint2]:
    >>>     if is_dependent(constraint):
    >>>         continue
)
isinstancerA   )
constraints    r-   r   r      s    . j*--r0   c            
          ^  \ rS rSrSr S\\S.S\\S\4      S\\	   S\\
   S	S4U 4S
 jjjjrS\S\4   S	S 4S jrSrU =r$ )_DependentProperty   a  
Decorator that extends @property to act like a `Dependent` constraint when
called on a class and act like a property when called on an object.

Example::

    class Uniform(Distribution):
        def __init__(self, low, high):
            self.low = low
            self.high = high

        @constraints.dependent_property(is_discrete=False, event_dim=0)
        def support(self):
            return constraints.interval(self.low, self.high)

Args:
    fn (Callable): The function to be decorated.
    is_discrete (bool): Optional value of ``.is_discrete`` in case this
        can be computed statically. If not provided, access to the
        ``.is_discrete`` attribute will raise a NotImplementedError.
    event_dim (int): Optional value of ``.event_dim`` in case this
        can be computed statically. If not provided, access to the
        ``.event_dim`` attribute will raise a NotImplementedError.
NrC   fn.r=   r>   rK   c                <   > [         TU ]  U5        X l        X0l        g rE   )rH   rI   rF   rG   )r+   re   r=   r>   r3   s       r-   rI   _DependentProperty.__init__   s     	'#r0   c                 >    [        XR                  U R                  S9$ )z
Support for syntax to customize static attributes::

    @constraints.dependent_property(is_discrete=True, event_dim=1)
    def support(self): ...
rC   )rc   rF   rG   )r+   re   s     r-   rR   _DependentProperty.__call__   s      "--
 	
r0   rY   rE   )r4   r9   r:   r;   r<   rM   r   r   r   r[   r\   rI   rR   r?   r]   r^   s   @r-   rc   rc      s    6 ,0	$ '5#1	$Xc3h'(	$ d^		$
 C=	$ 
	$ 	$	
8CH- 	
2F 	
 	
r0   rc   c                   h   ^  \ rS rSrSrU 4S jr\S\4S j5       r\S\	4S j5       r
S rS rS	rU =r$ )
_IndependentConstraint   z
Wraps a constraint by aggregating over ``reinterpreted_batch_ndims``-many
dims in :meth:`check`, so that an event is valid only if all its
independent entries are valid.
c                    > [        U[        5      (       d   e[        U[        5      (       d   eUS:  d   eXl        X l        [
        TU ]  5         g Nr   )r`   r   r\   base_constraintreinterpreted_batch_ndimsrH   rI   )r+   ro   rp   r3   s      r-   rI   _IndependentConstraint.__init__   sO    /:66663S9999(A---.)B&r0   rK   c                 .    U R                   R                  $ rE   ro   r=   r5   s    r-   r=   "_IndependentConstraint.is_discrete       ##///r0   c                 H    U R                   R                  U R                  -   $ rE   )ro   r>   rp   r5   s    r-   r>    _IndependentConstraint.event_dim   s    ##--0N0NNNr0   c                    U R                   R                  U5      nUR                  5       U R                  :  aB  U R                   R                  U R                  -   n[        SU SUR                  5        35      eUR                  UR                  S UR                  5       U R                  -
   S-   5      nUR                  S5      nU$ )NExpected value.dim() >= 	 but got r|   )	ro   r.   dimrp   r>   rU   reshapeshapeall)r+   r,   resultexpecteds       r-   r.   _IndependentConstraint.check   s    %%++E2::<$888++558V8VVH*8*Ieiik]K  LLH6::<$*H*HHIEQ
 Br0   c                     U R                   R                  SS   S[        U R                  5       SU R                   S3$ )Nr2   (z, ))r3   r4   reprro   rp   r5   s    r-   r6   _IndependentConstraint.__repr__
  sA    ..))!"-.aT5I5I0J/K2dNlNlMmmnoor0   )ro   rp   r4   r9   r:   r;   r<   rI   rZ   r[   r=   r\   r>   r.   r6   r?   r]   r^   s   @r-   rk   rk      sW     0T 0 0 O3 O Op pr0   rk   c                   h   ^  \ rS rSrSrU 4S jr\S\4S j5       r\S\	4S j5       r
S rS rS	rU =r$ )
r   i  av  
Constraint for the :class:`~torch.distribution.MixtureSameFamily`
distribution that adds back the rightmost batch dimension before
performing the validity check with the component distribution
constraint.

Args:
    base_constraint: The ``Constraint`` object of
        the component distribution of
        the :class:`~torch.distribution.MixtureSameFamily` distribution.
c                 \   > [        U[        5      (       d   eXl        [        TU ]  5         g rE   )r`   r   ro   rH   rI   )r+   ro   r3   s     r-   rI   $MixtureSameFamilyConstraint.__init__  s'    /:6666.r0   rK   c                 .    U R                   R                  $ rE   rs   r5   s    r-   r=   'MixtureSameFamilyConstraint.is_discrete   ru   r0   c                 .    U R                   R                  $ rE   )ro   r>   r5   s    r-   r>   %MixtureSameFamilyConstraint.event_dim$  s    ##---r0   c                    UR                  SU R                  -
  5      nU R                  R                  U5      nUR	                  5       U R                  :  a)  [        SU R                   SUR	                  5        35      eUR	                  5       U R                  -
  nUR                  UR                  SU S-   5      nUR                  S5      nU$ )z
Check validity of ``value`` as a possible outcome of sampling
the :class:`~torch.distribution.MixtureSameFamily` distribution.
r|   ry   rz   Nr{   )		unsqueezer>   ro   r.   r}   rU   r~   r   r   )r+   r,   unsqueezed_valuer   num_dim_to_keeps        r-   r.   !MixtureSameFamilyConstraint.check(  s    
 !??2+>?%%++,<=99;'*4>>*:)EIIK=Q   ))+6-=o > FGBr0   c                 `    U R                   R                   S[        U R                  5       S3$ )Nr   r   )r3   r4   r   ro   r5   s    r-   r6   $MixtureSameFamilyConstraint.__repr__8  s,    ..))*!D1E1E,F+GqIIr0   )ro   r   r^   s   @r-   r   r     sT    

 0T 0 0 .3 . . J Jr0   r   c                   "    \ rS rSrSrSrS rSrg)_Booleani<  z'
Constrain to the two values `{0, 1}`.
Tc                     US:H  US:H  -  $ )Nr   r2   r8   r*   s     r-   r.   _Boolean.checkC  s    
uz**r0   r8   N)r4   r9   r:   r;   r<   r=   r.   r?   r8   r0   r-   r   r   <  s     K+r0   r   c                   &    \ rS rSrSrSrSrS rSrg)_OneHotiG  z
Constrain to one-hot vectors.
Tr2   c                     US:H  US:H  -  nUR                  S5      R                  S5      nUR                  S5      U-  $ )Nr   r2   r|   )sumeqr   )r+   r,   
is_booleanis_normalizeds       r-   r.   _OneHot.checkO  s@    qjUaZ0
		"((+~~b!M11r0   r8   N)	r4   r9   r:   r;   r<   r=   r>   r.   r?   r8   r0   r-   r   r   G  s     KI2r0   r   c                   <   ^  \ rS rSrSrSrU 4S jrS rS rSr	U =r
$ )_IntegerIntervaliU  z@
Constrain to an integer interval `[lower_bound, upper_bound]`.
Tc                 :   > Xl         X l        [        TU ]  5         g rE   lower_boundupper_boundrH   rI   r+   r   r   r3   s      r-   rI   _IntegerInterval.__init__\      &&r0   c                 P    US-  S:H  U R                   U:*  -  XR                  :*  -  $ Nr2   r   r   r   r*   s     r-   r.   _IntegerInterval.checka  s0    QY!^ 0 0E 9:eGWGW>WX	
r0   c                 x    U R                   R                  SS  nUSU R                   SU R                   S3-  nU$ Nr2   (lower_bound=z, upper_bound=r   r3   r4   r   r   r+   
fmt_strings     r-   r6   _IntegerInterval.__repr__f  J    ^^,,QR0
D,,-^D<L<L;MQO	

 r0   r   r4   r9   r:   r;   r<   r=   rI   r.   r6   r?   r]   r^   s   @r-   r   r   U  s#     K


 r0   r   c                   <   ^  \ rS rSrSrSrU 4S jrS rS rSr	U =r
$ )_IntegerLessThanin  z9
Constrain to an integer interval `(-inf, upper_bound]`.
Tc                 .   > Xl         [        TU ]	  5         g rE   r   rH   rI   r+   r   r3   s     r-   rI   _IntegerLessThan.__init__u      &r0   c                 0    US-  S:H  XR                   :*  -  $ r   r   r*   s     r-   r.   _IntegerLessThan.checky      	Q5,<,<#<==r0   c                 ^    U R                   R                  SS  nUSU R                   S3-  nU$ Nr2   z(upper_bound=r   r3   r4   r   r   s     r-   r6   _IntegerLessThan.__repr__|  8    ^^,,QR0
d&6&6%7q99
r0   r   r   r^   s   @r-   r   r   n  #     K> r0   r   c                   <   ^  \ rS rSrSrSrU 4S jrS rS rSr	U =r
$ )_IntegerGreaterThani  z8
Constrain to an integer interval `[lower_bound, inf)`.
Tc                 .   > Xl         [        TU ]	  5         g rE   r   rH   rI   r+   r   r3   s     r-   rI   _IntegerGreaterThan.__init__  r   r0   c                 0    US-  S:H  XR                   :  -  $ r   r   r*   s     r-   r.   _IntegerGreaterThan.check  r   r0   c                 ^    U R                   R                  SS  nUSU R                   S3-  nU$ Nr2   r   r   r3   r4   r   r   s     r-   r6   _IntegerGreaterThan.__repr__  r   r0   r   r   r^   s   @r-   r   r     r   r0   r   c                       \ rS rSrSrS rSrg)_Reali  z>
Trivially constrain to the extended real line `[-inf, inf]`.
c                 
    X:H  $ rE   r8   r*   s     r-   r.   _Real.check  s
    ~r0   r8   N)r4   r9   r:   r;   r<   r.   r?   r8   r0   r-   r   r     s    r0   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )_GreaterThani  z5
Constrain to a real half line `(lower_bound, inf]`.
c                 .   > Xl         [        TU ]	  5         g rE   r   r   s     r-   rI   _GreaterThan.__init__  r   r0   c                      U R                   U:  $ rE   r   r*   s     r-   r.   _GreaterThan.check  s    %''r0   c                 ^    U R                   R                  SS  nUSU R                   S3-  nU$ r   r   r   s     r-   r6   _GreaterThan.__repr__  r   r0   r   
r4   r9   r:   r;   r<   rI   r.   r6   r?   r]   r^   s   @r-   r   r         ( r0   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )_GreaterThanEqi  z5
Constrain to a real half line `[lower_bound, inf)`.
c                 .   > Xl         [        TU ]	  5         g rE   r   r   s     r-   rI   _GreaterThanEq.__init__  r   r0   c                      U R                   U:*  $ rE   r   r*   s     r-   r.   _GreaterThanEq.check  s    5((r0   c                 ^    U R                   R                  SS  nUSU R                   S3-  nU$ r   r   r   s     r-   r6   _GreaterThanEq.__repr__  r   r0   r   r   r^   s   @r-   r   r     s    ) r0   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )	_LessThani  z6
Constrain to a real half line `[-inf, upper_bound)`.
c                 .   > Xl         [        TU ]	  5         g rE   r   r   s     r-   rI   _LessThan.__init__  r   r0   c                     XR                   :  $ rE   r   r*   s     r-   r.   _LessThan.check  s    ''''r0   c                 ^    U R                   R                  SS  nUSU R                   S3-  nU$ r   r   r   s     r-   r6   _LessThan.__repr__  r   r0   r   r   r^   s   @r-   r   r     r   r0   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )	_Intervali  z<
Constrain to a real interval `[lower_bound, upper_bound]`.
c                 :   > Xl         X l        [        TU ]  5         g rE   r   r   s      r-   rI   _Interval.__init__  r   r0   c                 >    U R                   U:*  XR                  :*  -  $ rE   r   r*   s     r-   r.   _Interval.check  s!      E)e7G7G.GHHr0   c                 x    U R                   R                  SS  nUSU R                   SU R                   S3-  nU$ r   r   r   s     r-   r6   _Interval.__repr__  r   r0   r   r   r^   s   @r-   r   r     s    
I r0   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )_HalfOpenIntervali  z<
Constrain to a real interval `[lower_bound, upper_bound)`.
c                 :   > Xl         X l        [        TU ]  5         g rE   r   r   s      r-   rI   _HalfOpenInterval.__init__  r   r0   c                 >    U R                   U:*  XR                  :  -  $ rE   r   r*   s     r-   r.   _HalfOpenInterval.check  s!      E)e6F6F.FGGr0   c                 x    U R                   R                  SS  nUSU R                   SU R                   S3-  nU$ r   r   r   s     r-   r6   _HalfOpenInterval.__repr__  r   r0   r   r   r^   s   @r-   r   r     s    
H r0   r   c                   "    \ rS rSrSrSrS rSrg)_Simplexi  zt
Constrain to the unit simplex in the innermost (rightmost) dimension.
Specifically: `x >= 0` and `x.sum(-1) == 1`.
r2   c                 ~    [         R                  " US:  SS9UR                  S5      S-
  R                  5       S:  -  $ )Nr   r|   r}   r2   ư>)torchr   r   absr*   s     r-   r.   _Simplex.check  s7    yy!,21B0G0G0ID0PQQr0   r8   Nr4   r9   r:   r;   r<   r>   r.   r?   r8   r0   r-   r  r    s    
 IRr0   r  c                   ,    \ rS rSrSrSrSrS rS rSr	g)	_Multinomiali  a  
Constrain to nonnegative integer values summing to at most an upper bound.

Note due to limitations of the Multinomial distribution, this currently
checks the weaker condition ``value.sum(-1) <= upper_bound``. In the future
this may be strengthened to ``value.sum(-1) == upper_bound``.
Tr2   c                     Xl         g rE   r   )r+   r   s     r-   rI   _Multinomial.__init__  s    &r0   c                 `    US:  R                  SS9UR                  SS9U R                  :*  -  $ )Nr   r|   r	  )r   r   r   rV   s     r-   r.   _Multinomial.check  s1    Q|||#quuu}8H8H'HIIr0   r   N)
r4   r9   r:   r;   r<   r=   r>   rI   r.   r?   r8   r0   r-   r  r    s     KI'Jr0   r  c                   "    \ rS rSrSrSrS rSrg)_LowerTriangulari  z0
Constrain to lower-triangular square matrices.
   c                     UR                  5       nX!:H  R                  UR                  S S S-   5      R                  S5      S   $ )Nr{   r|   r   )trilviewr   min)r+   r,   
value_trils      r-   r.   _LowerTriangular.check%  sA    ZZ\
#))%++cr*:U*BCGGKANNr0   r8   Nr  r8   r0   r-   r  r    s     IOr0   r  c                   "    \ rS rSrSrSrS rSrg)_LowerCholeskyi*  zH
Constrain to lower-triangular square matrices with positive diagonals.
r  c                     UR                  5       nX!:H  R                  UR                  S S S-   5      R                  S5      S   nUR	                  SSS9S:  R                  S5      S   nX4-  $ )Nr  r{   r|   r   )dim1dim2)r  r  r   r  diagonal)r+   r,   r  r   positive_diagonals        r-   r.   _LowerCholesky.check1  sv    ZZ\
 &&u{{3B'7%'?@DDRHK 	 #^^"^=AFFrJ1M33r0   r8   Nr  r8   r0   r-   r   r   *  s     I4r0   r   c                   "    \ rS rSrSrSrS rSrg)_CorrCholeskyi;  zq
Constrain to lower-triangular square matrices with positive diagonals and each
row vector being of unit length.
r  c                 n   [         R                  " UR                  5      R                  UR	                  S5      -  S-  n[         R
                  R                  UR                  5       SS9nUS-
  R                  5       R                  U5      R                  SS9n[        5       R                  U5      U-  $ )Nr|   
   r	        ?)r  finfodtypeepssizelinalgnormdetachr  ler   r   r.   )r+   r,   tolrow_normunit_row_norms        r-   r.   _CorrCholesky.checkC  s    KK$((5::b>9B> 	 <<$$U\\^$<!C,,.11#6::r:B%%e,}<<r0   r8   Nr  r8   r0   r-   r(  r(  ;  s    
 I=r0   r(  c                   "    \ rS rSrSrSrS rSrg)_SquareiL  z
Constrain to square matrices.
r  c                     [         R                  " UR                  S S UR                  S   UR                  S   :H  [         R                  UR                  S9$ )Nr  r|   )r/  
fill_valuer-  device)r  fullr   r[   r<  r*   s     r-   r.   _Square.checkS  sG    zzSb!B5;;r?:**<<	
 	
r0   r8   Nr  r8   r0   r-   r9  r9  L  s     I
r0   r9  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
_Symmetrici\  z)
Constrain to Symmetric square matrices.
c                    > [         TU ]  U5      nUR                  5       (       d  U$ [        R                  " XR
                  SS9R                  S5      R                  S5      $ )Nr
  )atolr  r|   )rH   r.   r   r  isclosemT)r+   r,   square_checkr3   s      r-   r.   _Symmetric.checka  sQ    w}U+!!}}UHH48<<R@DDRHHr0   r8   r4   r9   r:   r;   r<   r.   r?   r]   r^   s   @r-   r@  r@  \  s    I Ir0   r@  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )_PositiveSemidefiniteih  z.
Constrain to positive-semidefinite matrices.
c                    > [         TU ]  U5      nUR                  5       (       d  U$ [        R                  R                  U5      R                  S5      R                  S5      $ )Nr   r|   )rH   r.   r   r  r0  eigvalshger+   r,   	sym_checkr3   s      r-   r.   _PositiveSemidefinite.checkm  sM    GM%(	}}||$$U+..q155b99r0   r8   rG  r^   s   @r-   rI  rI  h      : :r0   rI  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )_PositiveDefiniteit  z*
Constrain to positive-definite matrices.
c                    > [         TU ]  U5      nUR                  5       (       d  U$ [        R                  R                  U5      R                  R                  S5      $ rn   )rH   r.   r   r  r0  cholesky_exinfor   rM  s      r-   r.   _PositiveDefinite.checky  sH    GM%(	}}||''.3366q99r0   r8   rG  r^   s   @r-   rR  rR  t  rP  r0   rR  c                   f   ^  \ rS rSrSrS	U 4S jjr\S\4S j5       r\S\	4S j5       r
S rSrU =r$ )
_Cati  z
Constraint functor that applies a sequence of constraints
`cseq` at the submatrices at dimension `dim`,
each of size `lengths[dim]`, in a way compatible with :func:`torch.cat`.
c                 4  > [        S U 5       5      (       d   e[        U5      U l        Uc  S/[        U R                  5      -  n[        U5      U l        [        U R                  5      [        U R                  5      :X  d   eX l        [        TU ]  5         g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frE   r`   r   .0cs     r-   	<genexpr> _Cat.__init__.<locals>.<genexpr>       ;d:a,,d   r2   )r   listcseqlenlengthsr}   rH   rI   )r+   rd  r}   rf  r3   s       r-   rI   _Cat.__init__  sx    ;d;;;;;J	?cC		N*GG}4<< C		N222r0   rK   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frE   r=   r\  s     r-   r_  #_Cat.is_discrete.<locals>.<genexpr>       4)Q==)   anyrd  r5   s    r-   r=   _Cat.is_discrete      4$))444r0   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frE   r>   r\  s     r-   r_  !_Cat.event_dim.<locals>.<genexpr>  s     2	1;;	rm  )maxrd  r5   s    r-   r>   _Cat.event_dim  s    2		222r0   c                    UR                  5       * U R                   s=::  a  UR                  5       :  d   e   e/ nSn[        U R                  U R                  5       HE  u  pEUR	                  U R                   X55      nUR                  UR                  U5      5        X5-   nMG     [        R                  " X R                   5      $ rn   )	r}   ziprd  rf  narrowappendr.   r  r   )r+   r,   checksstartconstrlengthvs          r-   r.   
_Cat.check  s    		|txx5%))+55555!$))T\\:NFTXXu5AMM&,,q/*NE ; yy**r0   )rd  r}   rf  )r   Nr4   r9   r:   r;   r<   rI   rZ   r[   r=   r\   r>   r.   r?   r]   r^   s   @r-   rX  rX    sM     5T 5 5 33 3 3+ +r0   rX  c                   f   ^  \ rS rSrSrS	U 4S jjr\S\4S j5       r\S\	4S j5       r
S rSrU =r$ )
_Stacki  z
Constraint functor that applies a sequence of constraints
`cseq` at the submatrices at dimension `dim`,
in a way compatible with :func:`torch.stack`.
c                    > [        S U 5       5      (       d   e[        U5      U l        X l        [        TU ]  5         g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frE   r[  r\  s     r-   r_  "_Stack.__init__.<locals>.<genexpr>  ra  rb  )r   rc  rd  r}   rH   rI   )r+   rd  r}   r3   s      r-   rI   _Stack.__init__  s5    ;d;;;;;J	r0   rK   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frE   rj  r\  s     r-   r_  %_Stack.is_discrete.<locals>.<genexpr>  rl  rm  rn  r5   s    r-   r=   _Stack.is_discrete  rq  r0   c                 n    [        S U R                   5       5      nU R                  U-   S:  a  US-  nU$ )Nc              3   8   #    U  H  oR                   v   M     g 7frE   rt  r\  s     r-   r_  #_Stack.event_dim.<locals>.<genexpr>  s     1y!++yrm  r   r2   )rv  rd  r}   )r+   r}   s     r-   r>   _Stack.event_dim  s4    1tyy1188c>A1HC
r0   c           	         UR                  5       * U R                   s=::  a  UR                  5       :  d   e   e[        UR                  U R                   5      5       Vs/ s H  o!R                  U R                   U5      PM      nn[        R
                  " [        X0R                  5       VVs/ s H  u  pEUR                  U5      PM     snnU R                   5      $ s  snf s  snnf rE   )	r}   ranger/  selectr  r#   ry  rd  r.   )r+   r,   ivsr  r~  s         r-   r.   _Stack.check  s    		|txx5%))+5555516uzz$((7K1LM1LAll488Q'1LM{{.1"ii.@A.@V\\!_.@A488
 	
 NAs    %C/C$
)rd  r}   )r   r  r^   s   @r-   r  r    sM     5T 5 5 3  
 
r0   r  r2   g        r+  )@typingr   r   r   r  __all__r   rA   r   rZ   rc   rk   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r(  r9  r@  rI  rR  rX  r  r
   r   r   r   r   r   r   r   r   r    r   r   r   r   r   r   r%   r   r   r!   r   r   r	   r"   r$   r   r   r   r#   r8   r0   r-   <module>r     sV   + * D !H2 2:,N ,N^.4.
: .
b%pZ %pP+J* +J\+z +2j 2z 2z (* (J : $Z $
 $
 *
 *	Rz 	RJ: J&	Oz 	O4Z 4"=J ="
j 
 	I 	I	:J 	:	:
 	:!+: !+H
Z 
B L	' $
*
))!, &q) # w$"S! 	#s#& 
*#% !	L	-/ %' 
r0   