
    jX                        d dl mZ d dlmZ 	 d dlZg dZ G d d          Z G d de          Zd	 Z G d
 de	e          Z
 G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d  d!e          Z G d" d#e          Z G d$ d%e          Z G d& d'e          Z G d( d)e          Z G d* d+e          Z G d, d-e          Z G d. d/e          Z G d0 d1e          Z G d2 d3e          Z G d4 d5e          Z G d6 d7e          Z  G d8 d9e          Z! G d: d;e          Z" e            Z#e
Z$eZ% e            Z& e            Z' ed           Z( ed<          Z)eZ* e            Z+ e%e+d<          Z, ed=          Z- ed=          Z.eZ/eZ0eZ1eZ2 ed=d>          Z3eZ4eZ5 e            Z6 e            Z7 e            Z8 e            Z9 e            Z: e            Z; e            Z< e             Z=e!Z>e"Z?dS )?    )Callable)AnyN) 
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                   &    e Zd ZdZdZdZd Zd ZdS )r   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                     t           )z
        Returns a byte tensor of ``sample_shape + batch_shape`` indicating
        whether each event in value satisfies this constraint.
        )NotImplementedErrorselfvalues     i/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/torch/distributions/constraints.pycheckzConstraint.checkb   s
    
 "!    c                 0    | j         j        dd          dz   S )N   z())	__class____name__r)   s    r+   __repr__zConstraint.__repr__i   s    ~&qrr*T11r-   N)r1   
__module____qualname____doc__is_discrete	event_dimr,   r3    r-   r+   r   r   P   sH          KI" " "2 2 2 2 2r-   r   c                   v     e Zd ZdZeed fd
Zedefd            Zede	fd            Z
eeddZd Z xZS )	
_DependentaI  
    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.
    r7   r8   c                d    || _         || _        t                                                       d S N)_is_discrete
_event_dimsuper__init__)r)   r7   r8   r0   s      r+   rB   z_Dependent.__init__{   s.    '#r-   returnc                 J    | j         t          u rt          d          | j         S )Nz,.is_discrete cannot be determined statically)r?   NotImplementedr'   r2   s    r+   r7   z_Dependent.is_discrete   s(    ..%&TUUU  r-   c                 J    | j         t          u rt          d          | j         S )Nz*.event_dim cannot be determined statically)r@   rE   r'   r2   s    r+   r8   z_Dependent.event_dim   s&    ?n,,%&RSSSr-   c                d    |t           u r| j        }|t           u r| j        }t          ||          S )z
        Support for syntax to customize static attributes::

            constraints.dependent(is_discrete=True, event_dim=1)
        r<   )rE   r?   r@   r;   )r)   r7   r8   s      r+   __call__z_Dependent.__call__   s<     .((+K&&IkYGGGGr-   c                      t          d          )Nz1Cannot determine validity of dependent constraint)
ValueErrorr)   xs     r+   r,   z_Dependent.check   s    LMMMr-   )r1   r4   r5   r6   rE   rB   propertyboolr7   intr8   rH   r,   __classcell__r0   s   @r+   r;   r;   m   s          '5       
 !T ! ! ! X!
 3    X
 '5 
H 
H 
H 
H 
HN N N N N N Nr-   r;   c                 ,    t          | t                    S )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
    )
isinstancer;   )
constraints    r+   r   r      s    . j*---r-   c            
            e Zd ZdZ	 deeddedef         dz  dedz  dedz  ddf fd	Z	dedef         dd fd
Z
 xZS )_DependentPropertya  
    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.
    Nr<   fn.r7   r8   rC   c                f    t                                          |           || _        || _        d S r>   )rA   rB   r?   r@   )r)   rW   r7   r8   r0   s       r+   rB   z_DependentProperty.__init__   s0     	'#r-   c                 :    t          || j        | j                  S )z
        Support for syntax to customize static attributes::

            @constraints.dependent_property(is_discrete=True, event_dim=1)
            def support(self): ...
        r<   )rV   r?   r@   )r)   rW   s     r+   rH   z_DependentProperty.__call__   s'     "D-
 
 
 	
r-   r>   )r1   r4   r5   r6   rE   r   r   rN   rO   rB   rH   rP   rQ   s   @r+   rV   rV      s         6 )-	$ $2 .	$ 	$ 	$S#X%	$ D[		$
 :	$ 
	$ 	$ 	$ 	$ 	$ 	$	
8CH- 	
2F 	
 	
 	
 	
 	
 	
 	
 	
r-   rV   c                   f     e Zd ZdZ fdZedefd            Zedefd            Z	d Z
d Z xZS )_IndependentConstraintz
    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                 x   t          |t                    s$t          dt          |          j                   t          |t
                    s$t          dt          |          j                   |dk     rt          d|           || _        || _        t                      	                                 d S )N*base_constraint must be a Constraint, got z.reinterpreted_batch_ndims must be an int, got r   z,reinterpreted_batch_ndims must be >= 0, got )
rS   r   AssertionErrortyper1   rO   base_constraintreinterpreted_batch_ndimsrA   rB   )r)   r`   ra   r0   s      r+   rB   z_IndependentConstraint.__init__   s    /:66 	 ]T/=R=R=[]]   3S99 	 kF_A`A`Aikk   %q(( Z?XZZ    /)B&r-   rC   c                     | j         j        S r>   r`   r7   r2   s    r+   r7   z"_IndependentConstraint.is_discrete       #//r-   c                 *    | j         j        | j        z   S r>   )r`   r8   ra   r2   s    r+   r8   z _IndependentConstraint.event_dim  s    #-0NNNr-   c                    | j                             |          }|                                | j        k     r;| j         j        | j        z   }t          d| d|                                           |                    |j        d |                                | j        z
           dz             }|                    d          }|S )NExpected value.dim() >= 	 but got rj   )	r`   r,   dimra   r8   rJ   reshapeshapeall)r)   r*   resultexpecteds       r+   r,   z_IndependentConstraint.check  s    %++E22::<<$888+58VVHK8KKeiikkKK   LH6::<<$*HHHIEQ
 
 Br-   c                 j    | j         j        dd           dt          | j                   d| j         dS )Nr/   (z, ))r0   r1   reprr`   ra   r2   s    r+   r3   z_IndependentConstraint.__repr__  s=    .)!""-ooT5I0J0JoodNloooor-   r1   r4   r5   r6   rB   rM   rN   r7   rO   r8   r,   r3   rP   rQ   s   @r+   r[   r[      s             " 0T 0 0 0 X0 O3 O O O XO  p p p p p p pr-   r[   c                   f     e Zd ZdZ fdZedefd            Zedefd            Z	d Z
d Z xZS )r   a  
    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                     t          |t                    s$t          dt          |          j                   || _        t                                                       d S )Nr]   )rS   r   r^   r_   r1   r`   rA   rB   )r)   r`   r0   s     r+   rB   z$MixtureSameFamilyConstraint.__init__%  sc    /:66 	 ]T/=R=R=[]]    /r-   rC   c                     | j         j        S r>   rc   r2   s    r+   r7   z'MixtureSameFamilyConstraint.is_discrete-  rd   r-   c                     | j         j        S r>   )r`   r8   r2   s    r+   r8   z%MixtureSameFamilyConstraint.event_dim1  s    #--r-   c                    |                     d| j        z
            }| j                            |          }|                                | j        k     r,t          d| j         d|                                           |                                | j        z
  }|                    |j        d|         dz             }|                    d          }|S )z
        Check validity of ``value`` as a possible outcome of sampling
        the :class:`~torch.distribution.MixtureSameFamily` distribution.
        rj   rg   rh   Nri   )		unsqueezer8   r`   r,   rk   rJ   rl   rm   rn   )r)   r*   unsqueezed_valuero   num_dim_to_keeps        r+   r,   z!MixtureSameFamilyConstraint.check5  s    
 !??2+>??%++,<==99;;''Q4>QQEIIKKQQ    ))++6-=o-= > FGGBr-   c                 J    | j         j         dt          | j                   dS )Nrr   rs   )r0   r1   rt   r`   r2   s    r+   r3   z$MixtureSameFamilyConstraint.__repr__E  s)    .)IID1E,F,FIIIIr-   ru   rQ   s   @r+   r   r     s        
 
     0T 0 0 0 X0 .3 . . . X.   J J J J J J Jr-   r   c                       e Zd ZdZdZd ZdS )_Booleanz/
    Constrain to the two values `{0, 1}`.
    Tc                     |dk    |dk    z  S )Nr   r/   r9   r(   s     r+   r,   z_Boolean.checkP  s    
uz**r-   N)r1   r4   r5   r6   r7   r,   r9   r-   r+   r   r   I  s4          K+ + + + +r-   r   c                        e Zd ZdZdZdZd ZdS )_OneHotz'
    Constrain to one-hot vectors.
    Tr/   c                     |dk    |dk    z  }|                     d                              d          }|                    d          |z  S )Nr   r/   rj   )sumeqrn   )r)   r*   
is_booleanis_normalizeds       r+   r,   z_OneHot.check\  sH    qjUaZ0
		"((++~~b!!M11r-   N)r1   r4   r5   r6   r7   r8   r,   r9   r-   r+   r   r   T  s9          KI2 2 2 2 2r-   r   c                   2     e Zd ZdZdZ fdZd Zd Z xZS )_IntegerIntervalzH
    Constrain to an integer interval `[lower_bound, upper_bound]`.
    Tc                 d    || _         || _        t                                                       d S r>   lower_boundupper_boundrA   rB   r)   r   r   r0   s      r+   rB   z_IntegerInterval.__init__i  /    &&r-   c                 D    |dz  dk    | j         |k    z  || j        k    z  S Nr/   r   r   r   r(   s     r+   r,   z_IntegerInterval.checkn  s,    QY!^ 0E 9:etGW>WX	
r-   c                 Z    | j         j        dd          }|d| j         d| j         dz  }|S Nr/   (lower_bound=z, upper_bound=rs   r0   r1   r   r   r)   
fmt_strings     r+   r3   z_IntegerInterval.__repr__s  C    ^,QRR0
OD,OOD<LOOO	

 r-   	r1   r4   r5   r6   r7   rB   r,   r3   rP   rQ   s   @r+   r   r   b  sg          K    

 
 

      r-   r   c                   2     e Zd ZdZdZ fdZd Zd Z xZS )_IntegerLessThanzA
    Constrain to an integer interval `(-inf, upper_bound]`.
    Tc                 V    || _         t                                                       d S r>   r   rA   rB   r)   r   r0   s     r+   rB   z_IntegerLessThan.__init__  '    &r-   c                 ,    |dz  dk    || j         k    z  S r   r   r(   s     r+   r,   z_IntegerLessThan.check      	Q5D,<#<==r-   c                 J    | j         j        dd          }|d| j         dz  }|S Nr/   z(upper_bound=rs   r0   r1   r   r   s     r+   r3   z_IntegerLessThan.__repr__  4    ^,QRR0
9d&69999
r-   r   rQ   s   @r+   r   r   {  g          K    > > >      r-   r   c                   2     e Zd ZdZdZ fdZd Zd Z xZS )_IntegerGreaterThanz@
    Constrain to an integer interval `[lower_bound, inf)`.
    Tc                 V    || _         t                                                       d S r>   r   rA   rB   r)   r   r0   s     r+   rB   z_IntegerGreaterThan.__init__  r   r-   c                 ,    |dz  dk    || j         k    z  S r   r   r(   s     r+   r,   z_IntegerGreaterThan.check  r   r-   c                 J    | j         j        dd          }|d| j         dz  }|S Nr/   r   rs   r0   r1   r   r   s     r+   r3   z_IntegerGreaterThan.__repr__  r   r-   r   rQ   s   @r+   r   r     r   r-   r   c                       e Zd ZdZd ZdS )_RealzF
    Trivially constrain to the extended real line `[-inf, inf]`.
    c                     ||k    S r>   r9   r(   s     r+   r,   z_Real.check  s    ~r-   N)r1   r4   r5   r6   r,   r9   r-   r+   r   r     s-             r-   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )_GreaterThanz=
    Constrain to a real half line `(lower_bound, inf]`.
    c                 V    || _         t                                                       d S r>   r   r   s     r+   rB   z_GreaterThan.__init__  r   r-   c                     | j         |k     S r>   r   r(   s     r+   r,   z_GreaterThan.check  s    %''r-   c                 J    | j         j        dd          }|d| j         dz  }|S r   r   r   s     r+   r3   z_GreaterThan.__repr__  r   r-   r1   r4   r5   r6   rB   r,   r3   rP   rQ   s   @r+   r   r     `             ( ( (      r-   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )_GreaterThanEqz=
    Constrain to a real half line `[lower_bound, inf)`.
    c                 V    || _         t                                                       d S r>   r   r   s     r+   rB   z_GreaterThanEq.__init__  r   r-   c                     | j         |k    S r>   r   r(   s     r+   r,   z_GreaterThanEq.check  s    5((r-   c                 J    | j         j        dd          }|d| j         dz  }|S r   r   r   s     r+   r3   z_GreaterThanEq.__repr__  r   r-   r   rQ   s   @r+   r   r     s`             ) ) )      r-   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )	_LessThanz>
    Constrain to a real half line `[-inf, upper_bound)`.
    c                 V    || _         t                                                       d S r>   r   r   s     r+   rB   z_LessThan.__init__  r   r-   c                     || j         k     S r>   r   r(   s     r+   r,   z_LessThan.check  s    t'''r-   c                 J    | j         j        dd          }|d| j         dz  }|S r   r   r   s     r+   r3   z_LessThan.__repr__  r   r-   r   rQ   s   @r+   r   r     r   r-   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )	_IntervalzD
    Constrain to a real interval `[lower_bound, upper_bound]`.
    c                 d    || _         || _        t                                                       d S r>   r   r   s      r+   rB   z_Interval.__init__  r   r-   c                 0    | j         |k    || j        k    z  S r>   r   r(   s     r+   r,   z_Interval.check  s     E)et7G.GHHr-   c                 Z    | j         j        dd          }|d| j         d| j         dz  }|S r   r   r   s     r+   r3   z_Interval.__repr__  r   r-   r   rQ   s   @r+   r   r     sc             
I I I      r-   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )_HalfOpenIntervalzD
    Constrain to a real interval `[lower_bound, upper_bound)`.
    c                 d    || _         || _        t                                                       d S r>   r   r   s      r+   rB   z_HalfOpenInterval.__init__  r   r-   c                 0    | j         |k    || j        k     z  S r>   r   r(   s     r+   r,   z_HalfOpenInterval.check  s     E)ed6F.FGGr-   c                 Z    | j         j        dd          }|d| j         d| j         dz  }|S r   r   r   s     r+   r3   z_HalfOpenInterval.__repr__  r   r-   r   rQ   s   @r+   r   r     sc             
H H H      r-   r   c                       e Zd ZdZdZd ZdS )_Simplexz
    Constrain to the unit simplex in the innermost (rightmost) dimension.
    Specifically: `x >= 0` and `x.sum(-1) == 1`.
    r/   c                     t          j        |dk    d          |                    d          dz
                                  dk     z  S )Nr   rj   rk   r/   ư>)torchrn   r   absr(   s     r+   r,   z_Simplex.check  s@    y!,,,21B0G0G0I0ID0PQQr-   Nr1   r4   r5   r6   r8   r,   r9   r-   r+   r   r     s9         
 IR R R R Rr-   r   c                   &    e Zd ZdZdZdZd Zd ZdS )_Multinomiala3  
    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``.
    Tr/   c                     || _         d S r>   r   )r)   r   s     r+   rB   z_Multinomial.__init__$  s    &r-   c                 v    |dk                         d          |                    d          | j        k    z  S )Nr   rj   r   )rn   r   r   rK   s     r+   r,   z_Multinomial.check'  s3    Q|||##quuu}}8H'HIIr-   N)r1   r4   r5   r6   r7   r8   rB   r,   r9   r-   r+   r   r     sM          KI' ' 'J J J J Jr-   r   c                       e Zd ZdZdZd ZdS )_LowerTriangularz8
    Constrain to lower-triangular square matrices.
       c                     |                                 }||k                        |j        d d         dz                                 d          d         S )Nri   rj   r   )trilviewrm   min)r)   r*   
value_trils      r+   r,   z_LowerTriangular.check2  sK    ZZ\\
e#))%+crc*:U*BCCGGKKANNr-   Nr   r9   r-   r+   r   r   +  s9          IO O O O Or-   r   c                       e Zd ZdZdZd ZdS )_LowerCholeskyzP
    Constrain to lower-triangular square matrices with positive diagonals.
    r   c                     |                                 }||k                        |j        d d         dz                                 d          d         }|                    dd          dk                        d          d         }||z  S )Nr   ri   rj   r   )dim1dim2)r   r   rm   r   diagonal)r)   r*   r   r   positive_diagonals        r+   r,   z_LowerCholesky.check>  s    ZZ\\
5 &&u{3B3'7%'?@@DDRHHK 	 #^^"^==AFFrJJ1M"333r-   Nr   r9   r-   r+   r   r   7  s4          I4 4 4 4 4r-   r   c                       e Zd ZdZdZd ZdS )_CorrCholeskyz}
    Constrain to lower-triangular square matrices with positive diagonals and each
    row vector being of unit length.
    r   c                    t          j        |j                  j        |                    d          z  dz  }t           j                            |                                d          }|dz
                                  	                    |          
                    d          }t                                          |          |z  S )Nrj   
   r         ?)r   finfodtypeepssizelinalgnormdetachr   lern   r   r,   )r)   r*   tolrow_normunit_row_norms        r+   r,   z_CorrCholesky.checkP  s    K$$(5::b>>9B> 	 <$$U\\^^$<<!C,,..11#66::r:BB%%e,,}<<r-   Nr   r9   r-   r+   r   r   H  s4         
 I= = = = =r-   r   c                       e Zd ZdZdZd ZdS )_Squarez'
    Constrain to square matrices.
    r   c                     t          j        |j        d d         |j        d         |j        d         k    t           j        |j                  S )Nr   rj   )r   
fill_valuer   device)r   fullrm   rN   r  r(   s     r+   r,   z_Square.check`  sG    zSbS!B5;r?:*<	
 
 
 	
r-   Nr   r9   r-   r+   r   r   Y  s4          I
 
 
 
 
r-   r   c                   "     e Zd ZdZ fdZ xZS )
_Symmetricz1
    Constrain to Symmetric square matrices.
    c                     t                                          |          }|                                s|S t          j        ||j        d                              d                              d          S )Nr   )atolr   rj   )rA   r,   rn   r   isclosemT)r)   r*   square_checkr0   s      r+   r,   z_Symmetric.checkn  sg    ww}}U++!! 	 }UEH4888<<R@@DDRHHHr-   r1   r4   r5   r6   r,   rP   rQ   s   @r+   r  r  i  sK         I I I I I I I I Ir-   r  c                   "     e Zd ZdZ fdZ xZS )_PositiveSemidefinitez6
    Constrain to positive-semidefinite matrices.
    c                     t                                          |          }|                                s|S t          j                            |                              d                              d          S )Nr   rj   )rA   r,   rn   r   r   eigvalshger)   r*   	sym_checkr0   s      r+   r,   z_PositiveSemidefinite.checkz  s`    GGMM%((	}} 	|$$U++..q1155b999r-   r  rQ   s   @r+   r  r  u  B         : : : : : : : : :r-   r  c                   "     e Zd ZdZ fdZ xZS )_PositiveDefinitez2
    Constrain to positive-definite matrices.
    c                     t                                          |          }|                                s|S t          j                            |          j                            d          S )Nr   )rA   r,   rn   r   r   cholesky_exinfor   r  s      r+   r,   z_PositiveDefinite.check  sU    GGMM%((	}} 	|''..366q999r-   r  rQ   s   @r+   r  r    r  r-   r  c                   b     e Zd ZdZd	 fd	Zedefd            Zedefd            Z	d Z
 xZS )
_Catz
    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`.
    r   Nc                    t          d |D                       st          d          t          |          | _        |dgt	          | j                  z  }t          |          | _        t	          | j                  t	          | j                  k    r:t          dt	          | j                   dt	          | j                   d          || _        t                                                       d S )Nc              3   @   K   | ]}t          |t                    V  d S r>   rS   r   .0cs     r+   	<genexpr>z _Cat.__init__.<locals>.<genexpr>  ,      ;;:a,,;;;;;;r-   1All elements of cseq must be Constraint instancesr/   z	lengths (z) must match cseq (rs   )	rn   r^   listcseqlenlengthsrk   rA   rB   )r)   r%  rk   r'  r0   s       r+   rB   z_Cat.__init__  s    ;;d;;;;; 	V !TUUUJJ	?cC	NN*GG}}t|DI.. SC--SS#di..SSS   r-   rC   c                 >    t          d | j        D                       S )Nc              3   $   K   | ]}|j         V  d S r>   r7   r  s     r+   r!  z#_Cat.is_discrete.<locals>.<genexpr>  $      44Q1=444444r-   anyr%  r2   s    r+   r7   z_Cat.is_discrete  !    44$)444444r-   c                 >    t          d | j        D                       S )Nc              3   $   K   | ]}|j         V  d S r>   r8   r  s     r+   r!  z!_Cat.event_dim.<locals>.<genexpr>  s$      2211;222222r-   )maxr%  r2   s    r+   r8   z_Cat.event_dim  s!    22	222222r-   c                    |                                  | j         cxk    r|                                 k     s/n t          d| j          d|                                  d          g }d}t          | j        | j                  D ]N\  }}|                    | j         ||          }|                    |                    |                     ||z   }Ot          j	        || j                   S )Ndim  out of range for value with  dimensionsr   )
rk   r^   zipr%  r'  narrowappendr,   r   r   )r)   r*   checksstartconstrlengthvs          r+   r,   z
_Cat.check  s    6666599;;6666 VtxVVeiikkVVV   !$)T\:: 	# 	#NFFTXuf55AMM&,,q//***FNEEy***r-   )r   Nr1   r4   r5   r6   rB   rM   rN   r7   rO   r8   r,   rP   rQ   s   @r+   r  r    s               5T 5 5 5 X5 33 3 3 3 X3+ + + + + + +r-   r  c                   b     e Zd ZdZd fd	Zedefd            Zedefd            Z	d Z
 xZS )	_Stackz
    Constraint functor that applies a sequence of constraints
    `cseq` at the submatrices at dimension `dim`,
    in a way compatible with :func:`torch.stack`.
    r   c                     t          d |D                       st          d          t          |          | _        || _        t                                                       d S )Nc              3   @   K   | ]}t          |t                    V  d S r>   r  r  s     r+   r!  z"_Stack.__init__.<locals>.<genexpr>  r"  r-   r#  )rn   r^   r$  r%  rk   rA   rB   )r)   r%  rk   r0   s      r+   rB   z_Stack.__init__  sb    ;;d;;;;; 	V !TUUUJJ	r-   rC   c                 >    t          d | j        D                       S )Nc              3   $   K   | ]}|j         V  d S r>   r*  r  s     r+   r!  z%_Stack.is_discrete.<locals>.<genexpr>  r+  r-   r,  r2   s    r+   r7   z_Stack.is_discrete  r.  r-   c                 h    t          d | j        D                       }| j        |z   dk     r|dz  }|S )Nc              3   $   K   | ]}|j         V  d S r>   r1  r  s     r+   r!  z#_Stack.event_dim.<locals>.<genexpr>  s$      11!!+111111r-   r   r/   )r2  r%  rk   )r)   rk   s     r+   r8   z_Stack.event_dim  s?    11ty111118c>A1HC
r-   c                                                        j         cxk    r                                 k     s/n t          d j          d                                  d           fdt                               j                             D             }t	          j        d t          | j                  D              j                   S )Nr4  r5  r6  c                 F    g | ]}                     j        |          S r9   )selectrk   )r  ir)   r*   s     r+   
<listcomp>z _Stack.check.<locals>.<listcomp>  s)    MMMAell48Q''MMMr-   c                 >    g | ]\  }}|                     |          S r9   )r,   )r  r>  r<  s      r+   rL  z _Stack.check.<locals>.<listcomp>  s&    AAAFV\\!__AAAr-   )rk   r^   ranger   r   r"   r7  r%  )r)   r*   vss   `` r+   r,   z_Stack.check  s    6666599;;6666 VtxVVeiikkVVV   NMMMMuzz$(7K7K1L1LMMM{AAc"di.@.@AAA48
 
 	
r-   )r   r?  rQ   s   @r+   rA  rA    s               5T 5 5 5 X5 3    X
 
 
 
 
 
 
r-   rA  r/   g        r   )@collections.abcr   typingr   r   __all__r   r;   r   rM   rV   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  rA  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"   r9   r-   r+   <module>rS     s=   % $ $ $ $ $       D ! ! !H2 2 2 2 2 2 2 2:,N ,N ,N ,N ,N ,N ,N ,N^. . .4.
 .
 .
 .
 .
: .
 .
 .
b.p .p .p .p .pZ .p .p .pb.J .J .J .J .J* .J .J .Jb+ + + + +z + + +2 2 2 2 2j 2 2 2    z   2    z   (    *   (    J       :   $    Z   $    
   $    
   *    
   *	R 	R 	R 	R 	Rz 	R 	R 	RJ J J J J: J J J&	O 	O 	O 	O 	Oz 	O 	O 	O4 4 4 4 4Z 4 4 4"= = = = =J = = ="
 
 
 
 
j 
 
 
 	I 	I 	I 	I 	I 	I 	I 	I	: 	: 	: 	: 	:J 	: 	: 	:	: 	: 	: 	: 	:
 	: 	: 	:(+ (+ (+ (+ (+: (+ (+ (+V!
 !
 !
 !
 !
Z !
 !
 !
J JLL	' $
(**
'))))!,, &&q)) # uwwk$""<nS!! 		#s##& 
(**##%% !!	JLL	--// %%'' 
r-   