
    ǄgK                        d 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 e       ZeZ eZ! e	       Z" e
       Z# ed      Z$ ed9      Z%eZ& e       Z' e!e'd9      Z( ed:      Z) ed:      Z*eZ+eZ,eZ-eZ. ed:d;      Z/eZ0eZ1 e       Z2 e       Z3 e       Z4 e       Z5 e       Z6 e       Z7 e       Z8 e       Z9eZ:eZ;y)<a  
The following constraints are implemented:

- ``constraints.boolean``
- ``constraints.cat``
- ``constraints.corr_cholesky``
- ``constraints.dependent``
- ``constraints.greater_than(lower_bound)``
- ``constraints.greater_than_eq(lower_bound)``
- ``constraints.independent(constraint, reinterpreted_batch_ndims)``
- ``constraints.integer_interval(lower_bound, upper_bound)``
- ``constraints.interval(lower_bound, upper_bound)``
- ``constraints.less_than(upper_bound)``
- ``constraints.lower_cholesky``
- ``constraints.lower_triangular``
- ``constraints.multinomial``
- ``constraints.nonnegative``
- ``constraints.nonnegative_integer``
- ``constraints.one_hot``
- ``constraints.positive_integer``
- ``constraints.positive``
- ``constraints.positive_semidefinite``
- ``constraints.positive_definite``
- ``constraints.real_vector``
- ``constraints.real``
- ``constraints.simplex``
- ``constraints.symmetric``
- ``constraints.stack``
- ``constraints.square``
- ``constraints.symmetric``
- ``constraints.unit_interval``
    N)
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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y)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     g/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/distributions/constraints.pycheckzConstraint.check[   s
    
 "!    c                 :    | j                   j                  dd  dz   S )N   z())	__class____name__r&   s    r(   __repr__zConstraint.__repr__b   s    ~~&&qr*T11r*   N)r.   
__module____qualname____doc__is_discrete	event_dimr)   r0    r*   r(   r   r   I   s     KI"2r*   r   c                   ^     e Zd ZdZeed fd
Zed        Ze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.
    r4   r5   c                >    || _         || _        t        |           y N)_is_discrete
_event_dimsuper__init__)r&   r4   r5   r-   s      r(   r?   z_Dependent.__init__t   s    '#r*   c                 T    | j                   t        u rt        d      | j                   S )Nz,.is_discrete cannot be determined statically)r<   NotImplementedr$   r/   s    r(   r4   z_Dependent.is_discretey   s(    .%&TUU   r*   c                 T    | j                   t        u rt        d      | j                   S )Nz*.event_dim cannot be determined statically)r=   rA   r$   r/   s    r(   r5   z_Dependent.event_dim   s$    ??n,%&RSSr*   c                l    |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)
        r9   )rA   r<   r=   r8   )r&   r4   r5   s      r(   __call__z_Dependent.__call__   s5     .(++K&IkYGGr*   c                     t        d      )Nz1Cannot determine validity of dependent constraint)
ValueErrorr&   xs     r(   r)   z_Dependent.check   s    LMMr*   )r.   r1   r2   r3   rA   r?   propertyr4   r5   rD   r)   __classcell__r-   s   @r(   r8   r8   f   sO     '5 
 ! !
  
 '5 
HNr*   r8   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
    )
isinstancer8   )
constraints    r(   r   r      s    . j*--r*   c                   4     e Zd ZdZ	 deed fdZ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.
    r9   c                @    t         |   |       || _        || _        y r;   )r>   r?   r<   r=   )r&   fnr4   r5   r-   s       r(   r?   z_DependentProperty.__init__   s!     	'#r*   c                 F    t        || j                  | j                        S )z
        Support for syntax to customize static attributes::

            @constraints.dependent_property(is_discrete=True, event_dim=1)
            def support(self):
                ...
        r9   )rP   r<   r=   )r&   rR   s     r(   rD   z_DependentProperty.__call__   s"     "D--
 	
r*   r;   )r.   r1   r2   r3   rA   r?   rD   rJ   rK   s   @r(   rP   rP      s!    2 $&4$

r*   rP   c                   N     e Zd ZdZ fdZed        Ze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
        |           y Nr   )rM   r   intbase_constraintreinterpreted_batch_ndimsr>   r?   )r&   rY   rZ   r-   s      r(   r?   z_IndependentConstraint.__init__   sM    /:6663S999(A---.)B&r*   c                 .    | j                   j                  S r;   )rY   r4   r/   s    r(   r4   z"_IndependentConstraint.is_discrete   s    ##///r*   c                 H    | j                   j                  | j                  z   S r;   )rY   r5   rZ   r/   s    r(   r5   z _IndependentConstraint.event_dim   s    ##--0N0NNNr*   c                    | j                   j                  |      }|j                         | j                  k  rB| j                   j                  | j                  z   }t        d| d|j                                |j                  |j                  d |j                         | j                  z
   dz         }|j                  d      }|S )NzExpected value.dim() >= z	 but got r_   )	rY   r)   dimrZ   r5   rF   reshapeshapeall)r&   r'   resultexpecteds       r(   r)   z_IndependentConstraint.check   s    %%++E2::<$888++558V8VVH*8*Ieiik]K  LLH6::<$*H*HHIEQ
 Br*   c                     | j                   j                  dd   dt        | j                         d| j                   dS )Nr,   (z, ))r-   r.   reprrY   rZ   r/   s    r(   r0   z_IndependentConstraint.__repr__   sA    ..))!"-.aT5I5I0J/K2dNlNlMmmnoor*   )r.   r1   r2   r3   r?   rI   r4   r5   r)   r0   rJ   rK   s   @r(   rU   rU      sB     0 0 O Opr*   rU   c                       e Zd ZdZdZd Zy)_Booleanz/
    Constrain to the two values `{0, 1}`.
    Tc                     |dk(  |dk(  z  S )Nr   r,   r6   r%   s     r(   r)   z_Boolean.check  s    
uz**r*   N)r.   r1   r2   r3   r4   r)   r6   r*   r(   rk   rk     s     K+r*   rk   c                       e Zd ZdZdZdZd Zy)_OneHotz'
    Constrain to one-hot vectors.
    Tr,   c                     |dk(  |dk(  z  }|j                  d      j                  d      }|j                  d      |z  S )Nr   r,   r_   )sumeqrc   )r&   r'   
is_booleanis_normalizeds       r(   r)   z_OneHot.check  s@    qjUaZ0
		"((+~~b!M11r*   N)r.   r1   r2   r3   r4   r5   r)   r6   r*   r(   rn   rn     s     KI2r*   rn   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                 >    || _         || _        t        |           y r;   lower_boundupper_boundr>   r?   r&   rx   ry   r-   s      r(   r?   z_IntegerInterval.__init__$      &&r*   c                 R    |dz  dk(  | j                   |k  z  || j                  k  z  S Nr,   r   rx   ry   r%   s     r(   r)   z_IntegerInterval.check)  s2    QY!^ 0 0E 9:etGWGW>WX	
r*   c                 x    | j                   j                  dd  }|d| j                   d| j                   dz  }|S Nr,   (lower_bound=z, upper_bound=rh   r-   r.   rx   ry   r&   
fmt_strings     r(   r0   z_IntegerInterval.__repr__.  J    ^^,,QR0
D,,-^D<L<L;MQO	

 r*   	r.   r1   r2   r3   r4   r?   r)   r0   rJ   rK   s   @r(   ru   ru     s     K


r*   ru   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                 0    || _         t        | 	          y r;   ry   r>   r?   r&   ry   r-   s     r(   r?   z_IntegerLessThan.__init__=      &r*   c                 2    |dz  dk(  || j                   k  z  S r}   ry   r%   s     r(   r)   z_IntegerLessThan.checkA       	Q5D,<,<#<==r*   c                 ^    | j                   j                  dd  }|d| j                   dz  }|S Nr,   z(upper_bound=rh   r-   r.   ry   r   s     r(   r0   z_IntegerLessThan.__repr__D  8    ^^,,QR0
d&6&6%7q99
r*   r   rK   s   @r(   r   r   6       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                 0    || _         t        | 	          y r;   rx   r>   r?   r&   rx   r-   s     r(   r?   z_IntegerGreaterThan.__init__Q  r   r*   c                 2    |dz  dk(  || j                   k\  z  S r}   rx   r%   s     r(   r)   z_IntegerGreaterThan.checkU  r   r*   c                 ^    | j                   j                  dd  }|d| j                   dz  }|S Nr,   r   rh   r-   r.   rx   r   s     r(   r0   z_IntegerGreaterThan.__repr__X  r   r*   r   rK   s   @r(   r   r   J  r   r*   r   c                       e Zd ZdZd Zy)_RealzF
    Trivially constrain to the extended real line `[-inf, inf]`.
    c                     ||k(  S r;   r6   r%   s     r(   r)   z_Real.checkc  s    ~r*   N)r.   r1   r2   r3   r)   r6   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                 0    || _         t        | 	          y r;   r   r   s     r(   r?   z_GreaterThan.__init__l  r   r*   c                      | j                   |k  S r;   r   r%   s     r(   r)   z_GreaterThan.checkp  s    %''r*   c                 ^    | j                   j                  dd  }|d| j                   dz  }|S r   r   r   s     r(   r0   z_GreaterThan.__repr__s  r   r*   r.   r1   r2   r3   r?   r)   r0   rJ   rK   s   @r(   r   r   g      (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                 0    || _         t        | 	          y r;   r   r   s     r(   r?   z_GreaterThanEq.__init__~  r   r*   c                      | j                   |k  S r;   r   r%   s     r(   r)   z_GreaterThanEq.check  s    5((r*   c                 ^    | j                   j                  dd  }|d| j                   dz  }|S r   r   r   s     r(   r0   z_GreaterThanEq.__repr__  r   r*   r   rK   s   @r(   r   r   y  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                 0    || _         t        | 	          y r;   r   r   s     r(   r?   z_LessThan.__init__  r   r*   c                      || j                   k  S r;   r   r%   s     r(   r)   z_LessThan.check  s    t''''r*   c                 ^    | j                   j                  dd  }|d| j                   dz  }|S r   r   r   s     r(   r0   z_LessThan.__repr__  r   r*   r   rK   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                 >    || _         || _        t        |           y r;   rw   rz   s      r(   r?   z_Interval.__init__  r{   r*   c                 @    | j                   |k  || j                  k  z  S r;   r~   r%   s     r(   r)   z_Interval.check  s#      E)et7G7G.GHHr*   c                 x    | j                   j                  dd  }|d| j                   d| j                   dz  }|S r   r   r   s     r(   r0   z_Interval.__repr__  r   r*   r   rK   s   @r(   r   r     s    
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                 >    || _         || _        t        |           y r;   rw   rz   s      r(   r?   z_HalfOpenInterval.__init__  r{   r*   c                 @    | j                   |k  || j                  k  z  S r;   r~   r%   s     r(   r)   z_HalfOpenInterval.check  s#      E)ed6F6F.FGGr*   c                 x    | j                   j                  dd  }|d| j                   d| j                   dz  }|S r   r   r   s     r(   r0   z_HalfOpenInterval.__repr__  r   r*   r   rK   s   @r(   r   r     s    
Hr*   r   c                       e Zd ZdZdZd Zy)_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      |j                  d      dz
  j                         dk  z  S )Nr   r_   r`   r,   ư>)torchrc   rp   absr%   s     r(   r)   z_Simplex.check  s7    yy!,21B0G0G0ID0PQQr*   Nr.   r1   r2   r3   r5   r)   r6   r*   r(   r   r     s    
 IRr*   r   c                   $    e Zd ZdZdZdZd Zd Zy)_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                     || _         y r;   r   )r&   ry   s     r(   r?   z_Multinomial.__init__  s
    &r*   c                 l    |dk\  j                  d      |j                  d      | j                  k  z  S )Nr   r_   r   )rc   rp   ry   rG   s     r(   r)   z_Multinomial.check  s1    Q|||#quuu}8H8H'HIIr*   N)r.   r1   r2   r3   r4   r5   r?   r)   r6   r*   r(   r   r     s     KI'Jr*   r   c                       e Zd ZdZdZd Zy)_LowerTriangularz8
    Constrain to lower-triangular square matrices.
       c                     |j                         }||k(  j                  |j                  d d dz         j                  d      d   S )Nr^   r_   r   )trilviewrb   min)r&   r'   
value_trils      r(   r)   z_LowerTriangular.check  sC    ZZ\
e#))%++cr*:U*BCGGKANNr*   Nr   r6   r*   r(   r   r     s     IOr*   r   c                       e Zd ZdZdZd Zy)_LowerCholeskyzP
    Constrain to lower-triangular square matrices with positive diagonals.
    r   c                     |j                         }||k(  j                  |j                  d d dz         j                  d      d   }|j	                  dd      dkD  j                  d      d   }||z  S )Nr   r^   r_   r   )dim1dim2)r   r   rb   r   diagonal)r&   r'   r   r   positive_diagonals        r(   r)   z_LowerCholesky.check  s{    ZZ\
5 &&u{{3B'7%'?@DDRHK 	 #^^"^=AFFrJ1M"333r*   Nr   r6   r*   r(   r   r     s     I4r*   r   c                       e Zd ZdZdZd Zy)_CorrCholeskyz}
    Constrain to lower-triangular square matrices with positive diagonals and each
    row vector being of unit length.
    r   c                 x   t        j                  |j                        j                  |j	                  d      z  dz  }t         j
                  j                  |j                         d      }|dz
  j                         j                  |      j                  d      }t               j                  |      |z  S )Nr_   
   r         ?)r   finfodtypeepssizelinalgnormdetachr   lerc   r   r)   )r&   r'   tolrow_normunit_row_norms        r(   r)   z_CorrCholesky.check  s    KK$((5::b>9B> 	 <<$$U\\^$<!C,,.11#6::r:B%%e,}<<r*   Nr   r6   r*   r(   r   r     s    
 I=r*   r   c                       e Zd ZdZdZd Zy)_Squarez'
    Constrain to square matrices.
    r   c                     t        j                  |j                  d d |j                  d   |j                  d   k(  t         j                  |j                        S )Nr   r_   )r   
fill_valuer   device)r   fullrb   boolr   r%   s     r(   r)   z_Square.check  sG    zzSb!B5;;r?:**<<	
 	
r*   Nr   r6   r*   r(   r   r     s     I
r*   r   c                   "     e Zd ZdZ fdZ xZS )
_Symmetricz1
    Constrain to Symmetric square matrices.
    c                     t         |   |      }|j                         s|S t        j                  ||j
                  d      j                  d      j                  d      S )Nr   )atolr   r_   )r>   r)   rc   r   isclosemT)r&   r'   square_checkr-   s      r(   r)   z_Symmetric.check)  sP    w}U+!}}UEHH48<<R@DDRHHr*   r.   r1   r2   r3   r)   rJ   rK   s   @r(   r   r   $  s    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         |   |      }|j                         s|S t        j                  j                  |      j                  d      j                  d      S )Nr   r_   )r>   r)   rc   r   r   eigvalshger&   r'   	sym_checkr-   s      r(   r)   z_PositiveSemidefinite.check5  sK    GM%(	}}||$$U+..q155b99r*   r   rK   s   @r(   r   r   0      : :r*   r   c                   "     e Zd ZdZ fdZ xZS )_PositiveDefinitez2
    Constrain to positive-definite matrices.
    c                     t         |   |      }|j                         s|S t        j                  j                  |      j                  j                  d      S rW   )r>   r)   rc   r   r   cholesky_exinforq   r   s      r(   r)   z_PositiveDefinite.checkA  sF    GM%(	}}||''.3366q99r*   r   rK   s   @r(   r  r  <  r   r*   r  c                   J     e Zd ZdZd fd	Zed        Ze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`.
    c                 (   t        d |D              sJ t        |      | _        |dgt        | j                        z  }t        |      | _        t        | j                        t        | j                        k(  sJ || _        t        |           y )Nc              3   <   K   | ]  }t        |t                y wr;   rM   r   .0cs     r(   	<genexpr>z _Cat.__init__.<locals>.<genexpr>P       ;:a,;   r,   )rc   listcseqlenlengthsr`   r>   r?   )r&   r  r`   r  r-   s       r(   r?   z_Cat.__init__O  sw    ;d;;;;J	?cC		N*GG}4<< C		N222r*   c                 :    t        d | j                  D              S )Nc              3   4   K   | ]  }|j                     y wr;   r4   r
  s     r(   r  z#_Cat.is_discrete.<locals>.<genexpr>[       4Q1==4   anyr  r/   s    r(   r4   z_Cat.is_discreteY      4$))444r*   c                 :    t        d | j                  D              S )Nc              3   4   K   | ]  }|j                     y wr;   r5   r
  s     r(   r  z!_Cat.event_dim.<locals>.<genexpr>_  s     211;;2r  )maxr  r/   s    r(   r5   z_Cat.event_dim]  s    2		222r*   c                    |j                          | j                   cxk  r|j                         k  sJ  J g }d}t        | j                  | j                        D ]G  \  }}|j	                  | j                   ||      }|j                  |j                  |             ||z   }I t        j                  || j                         S rW   )	r`   zipr  r  narrowappendr)   r   r   )r&   r'   checksstartconstrlengthvs          r(   r)   z
_Cat.checka  s    		|txx5%))+55555!$))T\\: 	#NFFTXXuf5AMM&,,q/*FNE	# yy**r*   )r   N
r.   r1   r2   r3   r?   rI   r4   r5   r)   rJ   rK   s   @r(   r  r  H  s:     5 5 3 3+r*   r  c                   J     e Zd ZdZd fd	Zed        Ze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`.
    c                 x    t        d |D              sJ t        |      | _        || _        t        |           y )Nc              3   <   K   | ]  }t        |t                y wr;   r	  r
  s     r(   r  z"_Stack.__init__.<locals>.<genexpr>t  r  r  )rc   r  r  r`   r>   r?   )r&   r  r`   r-   s      r(   r?   z_Stack.__init__s  s4    ;d;;;;J	r*   c                 :    t        d | j                  D              S )Nc              3   4   K   | ]  }|j                     y wr;   r  r
  s     r(   r  z%_Stack.is_discrete.<locals>.<genexpr>{  r  r  r  r/   s    r(   r4   z_Stack.is_discretey  r  r*   c                 l    t        d | j                  D              }| j                  |z   dk  r|dz  }|S )Nc              3   4   K   | ]  }|j                     y wr;   r  r
  s     r(   r  z#_Stack.event_dim.<locals>.<genexpr>  s     1!!++1r  r   r,   )r  r  r`   )r&   r`   s     r(   r5   z_Stack.event_dim}  s4    1tyy1188c>A1HC
r*   c           	         |j                          | j                   cxk  r|j                         k  sJ  J t        |j                  | j                               D cg c]  }|j                  | j                   |        }}t	        j
                  t        || j                        D cg c]  \  }}|j                  |       c}}| j                         S c c}w c c}}w r;   )	r`   ranger   selectr   r   r!  r  r)   )r&   r'   ivsr(  r&  s         r(   r)   z_Stack.check  s    		|txx5%))+5555516uzz$((7K1LMAell488Q'MM{{.1"dii.@AFV\\!_A488
 	
 NAs   #C+C
)r   r)  rK   s   @r(   r+  r+  l  s:     5 5  
r*   r+  r,   g        r   )<r3   r   __all__r   r8   r   rI   rP   rU   rk   rn   ru   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   r6   r*   r(   <module>r8     s?  B  F2 2:,N ,N^.4*
: *
Z%pZ %pP+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	-/ %' 
r*   