U
    D‹ÑhÒH  ã                   @   s¢  d Z ddlZddddddd	d
dddddddddddddddddddddd d!gZG d"d„ dƒZG d#d$„ d$eƒZd%d„ ZG d&d'„ d'eeƒZG d(d)„ d)eƒZG d*d+„ d+eƒZ	G d,d-„ d-eƒZ
G d.d/„ d/eƒZG d0d1„ d1eƒZG d2d3„ d3eƒZG d4d5„ d5eƒZG d6d7„ d7eƒZG d8d9„ d9eƒZG d:d;„ d;eƒZG d<d=„ d=eƒZG d>d?„ d?eƒZG d@dA„ dAeƒZG dBdC„ dCeƒZG dDdE„ dEeƒZG dFdG„ dGeƒZG dHdI„ dIeƒZG dJdK„ dKeƒZG dLdM„ dMeƒZG dNdO„ dOeƒZG dPdQ„ dQeƒZG dRdS„ dSeƒZG dTdU„ dUeƒZeƒ ZeZ eZ!e	ƒ Z"e
ƒ Z#edƒZ$edVƒZ%eZ&eƒ Z'e!e'dVƒZ(edWƒZ)edWƒZ*eZ+eZ,eZ-eZ.edWdXƒZ/eZ0eZ1eƒ Z2eƒ Z3eƒ Z4eƒ Z5eƒ Z6eƒ Z7eƒ Z8eƒ Z9eZ:eZ;dS )Yaö  
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                   @   s(   e Zd ZdZdZdZdd„ Zd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                 C   s   t ‚dS )z“
        Returns a byte tensor of ``sample_shape + batch_shape`` indicating
        whether each event in value satisfies this constraint.
        N)ÚNotImplementedError©ÚselfÚvalue© r%   úM/tmp/user/2202/pip-unpacked-wheel-bf9o3bgk/torch/distributions/constraints.pyÚcheckZ   s    zConstraint.checkc                 C   s   | j jdd … d S )Né   z())Ú	__class__Ú__name__©r#   r%   r%   r&   Ú__repr__a   s    zConstraint.__repr__N)r*   Ú
__module__Ú__qualname__Ú__doc__Úis_discreteÚ	event_dimr'   r,   r%   r%   r%   r&   r   H   s
   c                       sX   e Zd ZdZeedœ‡ fdd„
Zedd„ ƒZedd„ ƒZeedœd	d
„Z	dd„ Z
‡  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.
    ©r0   r1   c                   s   || _ || _tƒ  ¡  d S ©N)Ú_is_discreteÚ
_event_dimÚsuperÚ__init__©r#   r0   r1   ©r)   r%   r&   r8   s   s    z_Dependent.__init__c                 C   s   | j tkrtdƒ‚| j S )Nz,.is_discrete cannot be determined statically)r5   ÚNotImplementedr!   r+   r%   r%   r&   r0   x   s    
z_Dependent.is_discretec                 C   s   | j tkrtdƒ‚| j S )Nz*.event_dim cannot be determined statically)r6   r;   r!   r+   r%   r%   r&   r1   ~   s    
z_Dependent.event_dimc                C   s(   |t kr| j}|t kr| j}t||d�S )z‡
        Support for syntax to customize static attributes::

            constraints.dependent(is_discrete=True, event_dim=1)
        r3   )r;   r5   r6   r2   r9   r%   r%   r&   Ú__call__„   s
    z_Dependent.__call__c                 C   s   t dƒ‚d S )Nz1Cannot determine validity of dependent constraint)Ú
ValueError©r#   Úxr%   r%   r&   r'   �   s    z_Dependent.check)r*   r-   r.   r/   r;   r8   Úpropertyr0   r1   r<   r'   Ú__classcell__r%   r%   r:   r&   r2   e   s   

r2   c                 C   s
   t | tƒS r4   )Ú
isinstancer2   )Ú
constraintr%   r%   r&   r   ”   s    c                       s2   e Zd ZdZdeedœ‡ fdd„Zdd„ Z‡  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.
    Nr3   c                   s   t ƒ  |¡ || _|| _d S r4   )r7   r8   r5   r6   )r#   Úfnr0   r1   r:   r%   r&   r8   ±   s    z_DependentProperty.__init__c                 C   s   t || j| jd�S )zÄ
        Support for syntax to customize static attributes::

            @constraints.dependent_property(is_discrete=True, event_dim=1)
            def support(self):
                ...
        r3   )rD   r5   r6   )r#   rE   r%   r%   r&   r<   ¸   s
      ÿz_DependentProperty.__call__)N)r*   r-   r.   r/   r;   r8   r<   rA   r%   r%   r:   r&   rD   ˜   s    ÿ ÿrD   c                       sH   e Zd ZdZ‡ fdd„Zedd„ ƒZedd„ ƒZdd	„ Zd
d„ Z	‡  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                    sB   t |tƒst‚t |tƒst‚|dks(t‚|| _|| _tƒ  ¡  d S ©Nr   )rB   r   ÚAssertionErrorÚintÚbase_constraintÚreinterpreted_batch_ndimsr7   r8   )r#   rJ   rK   r:   r%   r&   r8   Ì   s    z_IndependentConstraint.__init__c                 C   s   | j jS r4   )rJ   r0   r+   r%   r%   r&   r0   Ô   s    z"_IndependentConstraint.is_discretec                 C   s   | j j| j S r4   )rJ   r1   rK   r+   r%   r%   r&   r1   Ø   s    z _IndependentConstraint.event_dimc                 C   sp   | j  |¡}| ¡ | jk r@| j j| j }td|› d| ¡ › �ƒ‚| |jd | ¡ | j … d ¡}| d¡}|S )NzExpected value.dim() >= z	 but got ©éÿÿÿÿrM   )	rJ   r'   ÚdimrK   r1   r=   ZreshapeÚshapeÚall)r#   r$   ÚresultÚexpectedr%   r%   r&   r'   Ü   s    ÿÿ
z_IndependentConstraint.checkc                 C   s*   | j jdd … › dt| jƒ› d| j› d�S )Nr(   ú(z, ú))r)   r*   ÚreprrJ   rK   r+   r%   r%   r&   r,   é   s    z_IndependentConstraint.__repr__)r*   r-   r.   r/   r8   r@   r0   r1   r'   r,   rA   r%   r%   r:   r&   rF   Å   s   

rF   c                   @   s   e Zd ZdZdZdd„ ZdS )Ú_Booleanz/
    Constrain to the two values `{0, 1}`.
    Tc                 C   s   |dk|dkB S )Nr   r(   r%   r"   r%   r%   r&   r'   ô   s    z_Boolean.checkN)r*   r-   r.   r/   r0   r'   r%   r%   r%   r&   rV   í   s   rV   c                   @   s    e Zd ZdZdZdZdd„ ZdS )Ú_OneHotz'
    Constrain to one-hot vectors.
    Tr(   c                 C   s.   |dk|dkB }|  d¡ d¡}| d¡|@ S )Nr   r(   rM   )ÚsumÚeqrP   )r#   r$   Z
is_booleanÚis_normalizedr%   r%   r&   r'      s    z_OneHot.checkN)r*   r-   r.   r/   r0   r1   r'   r%   r%   r%   r&   rW   ø   s   rW   c                       s4   e Zd ZdZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )	Ú_IntegerIntervalzH
    Constrain to an integer interval `[lower_bound, upper_bound]`.
    Tc                    s   || _ || _tƒ  ¡  d S r4   ©Úlower_boundÚupper_boundr7   r8   ©r#   r]   r^   r:   r%   r&   r8     s    z_IntegerInterval.__init__c                 C   s    |d dk| j |k@ || jk@ S ©Nr(   r   ©r]   r^   r"   r%   r%   r&   r'     s    ÿz_IntegerInterval.checkc                 C   s.   | j jdd … }|d| j› d| j› d�7 }|S ©Nr(   ú(lower_bound=z, upper_bound=rT   ©r)   r*   r]   r^   ©r#   Z
fmt_stringr%   r%   r&   r,     s
    ÿz_IntegerInterval.__repr__©	r*   r-   r.   r/   r0   r8   r'   r,   rA   r%   r%   r:   r&   r[     s
   r[   c                       s4   e Zd ZdZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )	Ú_IntegerLessThanzA
    Constrain to an integer interval `(-inf, upper_bound]`.
    Tc                    s   || _ tƒ  ¡  d S r4   ©r^   r7   r8   ©r#   r^   r:   r%   r&   r8   &  s    z_IntegerLessThan.__init__c                 C   s   |d dk|| j k@ S r`   ©r^   r"   r%   r%   r&   r'   *  s    z_IntegerLessThan.checkc                 C   s&   | j jdd … }|d| j› d�7 }|S ©Nr(   z(upper_bound=rT   ©r)   r*   r^   re   r%   r%   r&   r,   -  s    z_IntegerLessThan.__repr__rf   r%   r%   r:   r&   rg     s
   rg   c                       s4   e Zd ZdZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )	Ú_IntegerGreaterThanz@
    Constrain to an integer interval `[lower_bound, inf)`.
    Tc                    s   || _ tƒ  ¡  d S r4   ©r]   r7   r8   ©r#   r]   r:   r%   r&   r8   :  s    z_IntegerGreaterThan.__init__c                 C   s   |d dk|| j k@ S r`   ©r]   r"   r%   r%   r&   r'   >  s    z_IntegerGreaterThan.checkc                 C   s&   | j jdd … }|d| j› d�7 }|S ©Nr(   rc   rT   ©r)   r*   r]   re   r%   r%   r&   r,   A  s    z_IntegerGreaterThan.__repr__rf   r%   r%   r:   r&   rm   3  s
   rm   c                   @   s   e Zd ZdZdd„ ZdS )Ú_RealzF
    Trivially constrain to the extended real line `[-inf, inf]`.
    c                 C   s   ||kS r4   r%   r"   r%   r%   r&   r'   L  s    z_Real.checkN)r*   r-   r.   r/   r'   r%   r%   r%   r&   rs   G  s   rs   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú_GreaterThanz=
    Constrain to a real half line `(lower_bound, inf]`.
    c                    s   || _ tƒ  ¡  d S r4   rn   ro   r:   r%   r&   r8   U  s    z_GreaterThan.__init__c                 C   s
   | j |k S r4   rp   r"   r%   r%   r&   r'   Y  s    z_GreaterThan.checkc                 C   s&   | j jdd … }|d| j› d�7 }|S rq   rr   re   r%   r%   r&   r,   \  s    z_GreaterThan.__repr__©r*   r-   r.   r/   r8   r'   r,   rA   r%   r%   r:   r&   rt   P  s   rt   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú_GreaterThanEqz=
    Constrain to a real half line `[lower_bound, inf)`.
    c                    s   || _ tƒ  ¡  d S r4   rn   ro   r:   r%   r&   r8   g  s    z_GreaterThanEq.__init__c                 C   s
   | j |kS r4   rp   r"   r%   r%   r&   r'   k  s    z_GreaterThanEq.checkc                 C   s&   | j jdd … }|d| j› d�7 }|S rq   rr   re   r%   r%   r&   r,   n  s    z_GreaterThanEq.__repr__ru   r%   r%   r:   r&   rv   b  s   rv   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú	_LessThanz>
    Constrain to a real half line `[-inf, upper_bound)`.
    c                    s   || _ tƒ  ¡  d S r4   rh   ri   r:   r%   r&   r8   y  s    z_LessThan.__init__c                 C   s
   || j k S r4   rj   r"   r%   r%   r&   r'   }  s    z_LessThan.checkc                 C   s&   | j jdd … }|d| j› d�7 }|S rk   rl   re   r%   r%   r&   r,   €  s    z_LessThan.__repr__ru   r%   r%   r:   r&   rw   t  s   rw   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú	_IntervalzD
    Constrain to a real interval `[lower_bound, upper_bound]`.
    c                    s   || _ || _tƒ  ¡  d S r4   r\   r_   r:   r%   r&   r8   ‹  s    z_Interval.__init__c                 C   s   | j |k|| jk@ S r4   ra   r"   r%   r%   r&   r'   �  s    z_Interval.checkc                 C   s.   | j jdd … }|d| j› d| j› d�7 }|S rb   rd   re   r%   r%   r&   r,   “  s
    ÿz_Interval.__repr__ru   r%   r%   r:   r&   rx   †  s   rx   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú_HalfOpenIntervalzD
    Constrain to a real interval `[lower_bound, upper_bound)`.
    c                    s   || _ || _tƒ  ¡  d S r4   r\   r_   r:   r%   r&   r8      s    z_HalfOpenInterval.__init__c                 C   s   | j |k|| jk @ S r4   ra   r"   r%   r%   r&   r'   ¥  s    z_HalfOpenInterval.checkc                 C   s.   | j jdd … }|d| j› d| j› d�7 }|S rb   rd   re   r%   r%   r&   r,   ¨  s
    ÿz_HalfOpenInterval.__repr__ru   r%   r%   r:   r&   ry   ›  s   ry   c                   @   s   e Zd ZdZdZd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                 C   s(   t j|dkdd�| d¡d  ¡ dk @ S )Nr   rM   ©rN   r(   ç�íµ ÷Æ°>)ÚtorchrP   rX   Úabsr"   r%   r%   r&   r'   ¸  s    z_Simplex.checkN©r*   r-   r.   r/   r1   r'   r%   r%   r%   r&   rz   °  s   rz   c                   @   s(   e Zd ZdZdZdZdd„ Zd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                 C   s
   || _ d S r4   rj   ri   r%   r%   r&   r8   È  s    z_Multinomial.__init__c                 C   s"   |dkj dd�|jdd�| jk@ S )Nr   rM   r{   )rP   rX   r^   r>   r%   r%   r&   r'   Ë  s    z_Multinomial.checkN)r*   r-   r.   r/   r0   r1   r8   r'   r%   r%   r%   r&   r€   ¼  s
   r€   c                   @   s   e Zd ZdZdZdd„ ZdS )Ú_LowerTriangularz8
    Constrain to lower-triangular square matrices.
    é   c                 C   s.   |  ¡ }||k |jd d… d ¡ d¡d S )NéþÿÿÿrL   rM   r   )ÚtrilÚviewrO   Úmin)r#   r$   Ú
value_trilr%   r%   r&   r'   Ö  s    z_LowerTriangular.checkNr   r%   r%   r%   r&   r�   Ï  s   r�   c                   @   s   e Zd ZdZdZdd„ ZdS )Ú_LowerCholeskyzP
    Constrain to lower-triangular square matrices with positive diagonals.
    r‚   c                 C   sR   |  ¡ }||k |jd d… d ¡ d¡d }|jddd�dk d¡d }||@ S )Nrƒ   rL   rM   r   )Zdim1Zdim2)r„   r…   rO   r†   Zdiagonal)r#   r$   r‡   r   Zpositive_diagonalr%   r%   r&   r'   â  s
    $ÿz_LowerCholesky.checkNr   r%   r%   r%   r&   rˆ   Û  s   rˆ   c                   @   s   e Zd ZdZdZdd„ ZdS )Ú_CorrCholeskyz}
    Constrain to lower-triangular square matrices with positive diagonals and each
    row vector being of unit length.
    r‚   c                 C   sZ   t  |j¡j| d¡ d }t jj| ¡ dd�}|d  ¡  	|¡j
dd�}tƒ  |¡|@ S )NrM   é
   r{   ç      ð?)r}   ZfinfoÚdtypeZepsÚsizeÚlinalgZnormÚdetachr~   ÚlerP   rˆ   r'   )r#   r$   ZtolZrow_normZunit_row_normr%   r%   r&   r'   ô  s
    ÿz_CorrCholesky.checkNr   r%   r%   r%   r&   r‰   ì  s   r‰   c                   @   s   e Zd ZdZdZdd„ ZdS )Ú_Squarez'
    Constrain to square matrices.
    r‚   c                 C   s0   t j|jd d… |jd |jd kt j|jd�S )Nrƒ   rM   )r�   Z
fill_valuerŒ   Údevice)r}   ÚfullrO   Úboolr’   r"   r%   r%   r&   r'     s    üz_Square.checkNr   r%   r%   r%   r&   r‘   ý  s   r‘   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )Ú
_Symmetricz1
    Constrain to Symmetric square matrices.
    c                    s6   t ƒ  |¡}| ¡ s|S tj||jdd� d¡ d¡S )Nr|   )Zatolrƒ   rM   )r7   r'   rP   r}   ÚiscloseZmT)r#   r$   Zsquare_checkr:   r%   r&   r'     s    z_Symmetric.check©r*   r-   r.   r/   r'   rA   r%   r%   r:   r&   r•     s   r•   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )Ú_PositiveSemidefinitez6
    Constrain to positive-semidefinite matrices.
    c                    s0   t ƒ  |¡}| ¡ s|S tj |¡ d¡ d¡S )Nr   rM   )r7   r'   rP   r}   rŽ   ZeigvalshÚge©r#   r$   Z	sym_checkr:   r%   r&   r'     s    z_PositiveSemidefinite.checkr—   r%   r%   r:   r&   r˜     s   r˜   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )Ú_PositiveDefinitez2
    Constrain to positive-definite matrices.
    c                    s,   t ƒ  |¡}| ¡ s|S tj |¡j d¡S rG   )r7   r'   rP   r}   rŽ   Zcholesky_exÚinforY   rš   r:   r%   r&   r'   *  s    z_PositiveDefinite.checkr—   r%   r%   r:   r&   r›   %  s   r›   c                       sB   e Zd ZdZd‡ fdd„	Zedd„ ƒZedd	„ ƒZd
d„ Z‡  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                    sn   t dd„ |D ƒƒst‚t|ƒ| _|d kr8dgt| jƒ }t|ƒ| _t| jƒt| jƒksZt‚|| _tƒ  ¡  d S )Nc                 s   s   | ]}t |tƒV  qd S r4   ©rB   r   ©Ú.0Úcr%   r%   r&   Ú	<genexpr>9  s     z _Cat.__init__.<locals>.<genexpr>r(   )	rP   rH   ÚlistÚcseqÚlenÚlengthsrN   r7   r8   )r#   r¤   rN   r¦   r:   r%   r&   r8   8  s    

z_Cat.__init__c                 C   s   t dd„ | jD ƒƒS )Nc                 s   s   | ]}|j V  qd S r4   ©r0   rŸ   r%   r%   r&   r¢   D  s     z#_Cat.is_discrete.<locals>.<genexpr>©Úanyr¤   r+   r%   r%   r&   r0   B  s    z_Cat.is_discretec                 C   s   t dd„ | jD ƒƒS )Nc                 s   s   | ]}|j V  qd S r4   ©r1   rŸ   r%   r%   r&   r¢   H  s     z!_Cat.event_dim.<locals>.<genexpr>)Úmaxr¤   r+   r%   r%   r&   r1   F  s    z_Cat.event_dimc                 C   s|   |  ¡  | j   kr |  ¡ k s&n t‚g }d}t| j| jƒD ]0\}}| | j ||¡}| | |¡¡ || }q<t 	|| j ¡S rG   )
rN   rH   Úzipr¤   r¦   ZnarrowÚappendr'   r}   r   )r#   r$   ZchecksÚstartÚconstrÚlengthÚvr%   r%   r&   r'   J  s    &
z
_Cat.check)r   N©
r*   r-   r.   r/   r8   r@   r0   r1   r'   rA   r%   r%   r:   r&   r�   1  s   


r�   c                       sB   e Zd ZdZd‡ fdd„	Zedd„ ƒZedd„ ƒZd	d
„ Z‡  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                    s4   t dd„ |D ƒƒst‚t|ƒ| _|| _tƒ  ¡  d S )Nc                 s   s   | ]}t |tƒV  qd S r4   rž   rŸ   r%   r%   r&   r¢   ]  s     z"_Stack.__init__.<locals>.<genexpr>)rP   rH   r£   r¤   rN   r7   r8   )r#   r¤   rN   r:   r%   r&   r8   \  s    
z_Stack.__init__c                 C   s   t dd„ | jD ƒƒS )Nc                 s   s   | ]}|j V  qd S r4   r§   rŸ   r%   r%   r&   r¢   d  s     z%_Stack.is_discrete.<locals>.<genexpr>r¨   r+   r%   r%   r&   r0   b  s    z_Stack.is_discretec                 C   s.   t dd„ | jD ƒƒ}| j| dk r*|d7 }|S )Nc                 s   s   | ]}|j V  qd S r4   rª   rŸ   r%   r%   r&   r¢   h  s     z#_Stack.event_dim.<locals>.<genexpr>r   r(   )r«   r¤   rN   )r#   rN   r%   r%   r&   r1   f  s    z_Stack.event_dimc                    sf   ˆ  ¡  ˆ j   kr ˆ  ¡ k s&n t‚‡ ‡fdd„tˆ ˆ j ¡ƒD ƒ}t dd„ t|ˆ jƒD ƒˆ j ¡S )Nc                    s   g | ]}ˆ  ˆ j|¡‘qS r%   )ÚselectrN   )r    Úir"   r%   r&   Ú
<listcomp>o  s     z _Stack.check.<locals>.<listcomp>c                 S   s   g | ]\}}|  |¡‘qS r%   )r'   )r    r±   r¯   r%   r%   r&   r¶   q  s     )rN   rH   Úranger�   r}   r   r¬   r¤   )r#   r$   Úvsr%   r"   r&   r'   m  s    &  ÿz_Stack.check)r   r²   r%   r%   r:   r&   r³   U  s   

r³   r(   g        r‹   )<r/   r}   Ú__all__r   r2   r   r@   rD   rF   rV   rW   r[   rg   rm   rs   rt   rv   rw   rx   ry   rz   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>   s²   !á#/-(	$!

