
    }YhbT                        d dl mZmZ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 d/ d0e          Z G d1 d2e          Z G d3 d4e          Z G d5 d6e          Z  G d7 d8e          Z! G d9 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 )>    )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                   &    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     q/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/distributions/constraints.pycheckzConstraint.checka   s
    
 "!    c                 0    | j         j        dd          dz   S )N   z())	__class____name__r*   s    r,   __repr__zConstraint.__repr__h   s    ~&qrr*T11r.   N)r2   
__module____qualname____doc__is_discrete	event_dimr-   r4    r.   r,   r   r   O   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.
    r8   r9   c                d    || _         || _        t                                                       d S N)_is_discrete
_event_dimsuper__init__)r*   r8   r9   r1   s      r,   rC   z_Dependent.__init__z   s.    '#r.   returnc                 J    | j         t          u rt          d          | j         S )Nz,.is_discrete cannot be determined statically)r@   NotImplementedr(   r3   s    r,   r8   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)rA   rF   r(   r3   s    r,   r9   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=   )rF   r@   rA   r<   )r*   r8   r9   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.   )r2   r5   r6   r7   rF   rC   propertyboolr8   intr9   rI   r-   __classcell__r1   s   @r,   r<   r<   l   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edef                  dee         dee	         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.r8   r9   rD   c                f    t                                          |           || _        || _        d S r?   )rB   rC   r@   rA   )r*   rX   r8   r9   r1   s       r,   rC   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=   )rW   r@   rA   )r*   rX   s     r,   rI   z_DependentProperty.__call__   s'     "D-
 
 
 	
r.   r?   )r2   r5   r6   r7   rF   r   r   r   rO   rP   rC   rI   rQ   rR   s   @r,   rW   rW      s         6 ,0	$ '5#1	$ 	$ 	$Xc3h'(	$ d^		$
 C=	$ 
	$ 	$ 	$ 	$ 	$ 	$	
8CH- 	
2F 	
 	
 	
 	
 	
 	
 	
 	
r.   rW   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                     t          |t                    sJ t          |t                    sJ |dk    sJ || _        || _        t                                                       d S Nr   )rT   r   rP   base_constraintreinterpreted_batch_ndimsrB   rC   )r*   r_   r`   r1   s      r,   rC   z_IndependentConstraint.__init__   sm    /:666663S99999(A----.)B&r.   rD   c                     | j         j        S r?   r_   r8   r3   s    r,   r8   z"_IndependentConstraint.is_discrete       #//r.   c                 *    | j         j        | j        z   S r?   )r_   r9   r`   r3   s    r,   r9   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 ri   )	r_   r-   dimr`   r9   rK   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 )Nr0   (z, ))r1   r2   reprr_   r`   r3   s    r,   r4   z_IndependentConstraint.__repr__
  s=    .)!""-ooT5I0J0JoodNloooor.   r2   r5   r6   r7   rC   rN   rO   r8   rP   r9   r-   r4   rQ   rR   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J || _        t                                                       d S r?   )rT   r   r_   rB   rC   )r*   r_   r1   s     r,   rC   z$MixtureSameFamilyConstraint.__init__  s=    /:66666.r.   rD   c                     | j         j        S r?   rb   r3   s    r,   r8   z'MixtureSameFamilyConstraint.is_discrete   rc   r.   c                     | j         j        S r?   )r_   r9   r3   s    r,   r9   z%MixtureSameFamilyConstraint.event_dim$  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.
        ri   rf   rg   Nrh   )		unsqueezer9   r_   r-   rj   rK   rk   rl   rm   )r*   r+   unsqueezed_valuern   num_dim_to_keeps        r,   r-   z!MixtureSameFamilyConstraint.check(  s    
 !??2+>??%++,<==99;;''Q4>QQEIIKKQQ    ))++6-=o-= > FGGBr.   c                 J    | j         j         dt          | j                   dS )Nrq   rr   )r1   r2   rs   r_   r3   s    r,   r4   z$MixtureSameFamilyConstraint.__repr__8  s)    .)IID1E,F,FIIIIr.   rt   rR   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   r0   r:   r)   s     r,   r-   z_Boolean.checkC  s    
uz**r.   N)r2   r5   r6   r7   r8   r-   r:   r.   r,   r   r   <  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.
    Tr0   c                     |dk    |dk    z  }|                     d                              d          }|                    d          |z  S )Nr   r0   ri   )sumeqrm   )r*   r+   
is_booleanis_normalizeds       r,   r-   z_OneHot.checkO  sH    qjUaZ0
		"((++~~b!!M11r.   N)r2   r5   r6   r7   r8   r9   r-   r:   r.   r,   r   r   G  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_boundrB   rC   r*   r   r   r1   s      r,   rC   z_IntegerInterval.__init__\  /    &&r.   c                 D    |dz  dk    | j         |k    z  || j        k    z  S Nr0   r   r   r   r)   s     r,   r-   z_IntegerInterval.checka  s,    QY!^ 0E 9:etGW>WX	
r.   c                 Z    | j         j        dd          }|d| j         d| j         dz  }|S Nr0   (lower_bound=z, upper_bound=rr   r1   r2   r   r   r*   
fmt_strings     r,   r4   z_IntegerInterval.__repr__f  C    ^,QRR0
OD,OOD<LOOO	

 r.   	r2   r5   r6   r7   r8   rC   r-   r4   rQ   rR   s   @r,   r   r   U  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   rB   rC   r*   r   r1   s     r,   rC   z_IntegerLessThan.__init__u  '    &r.   c                 ,    |dz  dk    || j         k    z  S r   r   r)   s     r,   r-   z_IntegerLessThan.checky      	Q5D,<#<==r.   c                 J    | j         j        dd          }|d| j         dz  }|S Nr0   z(upper_bound=rr   r1   r2   r   r   s     r,   r4   z_IntegerLessThan.__repr__|  4    ^,QRR0
9d&69999
r.   r   rR   s   @r,   r   r   n  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   rB   rC   r*   r   r1   s     r,   rC   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 Nr0   r   rr   r1   r2   r   r   s     r,   r4   z_IntegerGreaterThan.__repr__  r   r.   r   rR   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?   r:   r)   s     r,   r-   z_Real.check  s    ~r.   N)r2   r5   r6   r7   r-   r:   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,   rC   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,   r4   z_GreaterThan.__repr__  r   r.   r2   r5   r6   r7   rC   r-   r4   rQ   rR   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,   rC   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,   r4   z_GreaterThanEq.__repr__  r   r.   r   rR   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,   rC   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,   r4   z_LessThan.__repr__  r   r.   r   rR   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,   rC   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,   r4   z_Interval.__repr__  r   r.   r   rR   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,   rC   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,   r4   z_HalfOpenInterval.__repr__  r   r.   r   rR   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`.
    r0   c                     t          j        |dk    d          |                    d          dz
                                  dk     z  S )Nr   ri   rj   r0   ư>)torchrm   r   absr)   s     r,   r-   z_Simplex.check  s@    y!,,,21B0G0G0I0ID0PQQr.   Nr2   r5   r6   r7   r9   r-   r:   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``.
    Tr0   c                     || _         d S r?   r   )r*   r   s     r,   rC   z_Multinomial.__init__  s    &r.   c                 v    |dk                         d          |                    d          | j        k    z  S )Nr   ri   r   )rm   r   r   rL   s     r,   r-   z_Multinomial.check  s3    Q|||##quuu}}8H'HIIr.   N)r2   r5   r6   r7   r8   r9   rC   r-   r:   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 )Nrh   ri   r   )trilviewrl   min)r*   r+   
value_trils      r,   r-   z_LowerTriangular.check%  sK    ZZ\\
e#))%+crc*:U*BCCGGKKANNr.   Nr   r:   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   rh   ri   r   )dim1dim2)r   r   rl   r   diagonal)r*   r+   r   r   positive_diagonals        r,   r-   z_LowerCholesky.check1  s    ZZ\\
5 &&u{3B3'7%'?@@DDRHHK 	 #^^"^==AFFrJJ1M"333r.   Nr   r:   r.   r,   r   r   *  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 )Nri   
   r         ?)r   finfodtypeepssizelinalgnormdetachr   lerm   r   r-   )r*   r+   tolrow_normunit_row_norms        r,   r-   z_CorrCholesky.checkC  s    K$$(5::b>>9B> 	 <$$U\\^^$<<!C,,..11#66::r:BB%%e,,}<<r.   Nr   r:   r.   r,   r   r   ;  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   ri   )r   
fill_valuer   device)r   fullrl   rO   r  r)   s     r,   r-   z_Square.checkS  sG    zSbS!B5;r?:*<	
 
 
 	
r.   Nr   r:   r.   r,   r   r   L  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   ri   )rB   r-   rm   r   isclosemT)r*   r+   square_checkr1   s      r,   r-   z_Symmetric.checka  sg    ww}}U++!! 	 }UEH4888<<R@@DDRHHHr.   r2   r5   r6   r7   r-   rQ   rR   s   @r,   r  r  \  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   ri   )rB   r-   rm   r   r   eigvalshger*   r+   	sym_checkr1   s      r,   r-   z_PositiveSemidefinite.checkm  s`    GGMM%((	}} 	|$$U++..q1155b999r.   r
  rR   s   @r,   r  r  h  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 r^   )rB   r-   rm   r   r   cholesky_exinfor   r  s      r,   r-   z_PositiveDefinite.checky  sU    GGMM%((	}} 	|''..366q999r.   r
  rR   s   @r,   r  r  t  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                 h   t          d |D                       sJ t          |          | _        |dgt          | j                  z  }t          |          | _        t          | j                  t          | j                  k    sJ || _        t                                                       d S )Nc              3   @   K   | ]}t          |t                    V  d S r?   rT   r   .0cs     r,   	<genexpr>z _Cat.__init__.<locals>.<genexpr>  ,      ;;:a,,;;;;;;r.   r0   )rm   listcseqlenlengthsrj   rB   rC   )r*   r#  rj   r%  r1   s       r,   rC   z_Cat.__init__  s    ;;d;;;;;;;;JJ	?cC	NN*GG}}4<  C	NN2222r.   rD   c                 >    t          d | j        D                       S )Nc              3   $   K   | ]}|j         V  d S r?   r8   r  s     r,   r   z#_Cat.is_discrete.<locals>.<genexpr>  $      44Q1=444444r.   anyr#  r3   s    r,   r8   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?   r9   r  s     r,   r   z!_Cat.event_dim.<locals>.<genexpr>  s$      2211;222222r.   )maxr#  r3   s    r,   r9   z_Cat.event_dim  s!    22	222222r.   c                    |                                  | j         cxk    r|                                 k     sn J g }d}t          | j        | j                  D ]N\  }}|                    | j         ||          }|                    |                    |                     ||z   }Ot          j        || j                   S r^   )	rj   zipr#  r%  narrowappendr-   r   r   )r*   r+   checksstartconstrlengthvs          r,   r-   z
_Cat.check  s    		|tx5555%))++555555!$)T\:: 	# 	#NFFTXuf55AMM&,,q//***FNEEy***r.   )r   Nr2   r5   r6   r7   rC   rN   rO   r8   rP   r9   r-   rQ   rR   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J 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.   )rm   r"  r#  rj   rB   rC   )r*   r#  rj   r1   s      r,   rC   z_Stack.__init__  sV    ;;d;;;;;;;;JJ	r.   rD   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*  r3   s    r,   r8   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?   r/  r  s     r,   r   z#_Stack.event_dim.<locals>.<genexpr>  s$      11!!+111111r.   r   r0   )r0  r#  rj   )r*   rj   s     r,   r9   z_Stack.event_dim  s?    11ty111118c>A1HC
r.   c                 R                                       j         cxk    r                                 k     sn J  fdt                               j                             D             }t          j        d t          | j                  D              j                   S )Nc                 F    g | ]}                     j        |          S r:   )selectrj   )r  ir*   r+   s     r,   
<listcomp>z _Stack.check.<locals>.<listcomp>  s)    MMMAell48Q''MMMr.   c                 >    g | ]\  }}|                     |          S r:   )r-   )r  r9  r7  s      r,   rG  z _Stack.check.<locals>.<listcomp>  s&    AAAFV\\!__AAAr.   )rj   ranger   r   r#   r2  r#  )r*   r+   vss   `` r,   r-   z_Stack.check  s    		|tx5555%))++555555MMMMMuzz$(7K7K1L1LMMM{AAc"di.@.@AAA48
 
 	
r.   )r   r:  rR   s   @r,   r<  r<    s               5T 5 5 5 X5 3    X
 
 
 
 
 
 
r.   r<  r0   g        r   )@typingr   r   r   r   __all__r   r<   r   rN   rW   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   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,   <module>rM     s7   + * * * * * * * * * 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P+J +J +J +J +J* +J +J +J\+ + + + +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 	: 	: 	:	: 	: 	: 	: 	:
 	: 	: 	:!+ !+ !+ !+ !+: !+ !+ !+H
 
 
 
 
Z 
 
 
B JLL	' $
(**
'))))!,, &&q)) # uwwk$""<nS!! 		#s##& 
(**##%% !!	JLL	--// %%'' 
r.   