Ë
    P/æj°K  ã                   ó’  — 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     úb/root/repos/pocs/video-evals/.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   € Ø�~‰~×&Ñ& q rÐ*¨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Ü k¸YÔ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ÜÐ3´SÔ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   € à×#Ñ#×-Ñ-°×0NÑ0NÑ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¸×8VÑ8VÑVˆHÜØ*¨8¨*°I¸e¿i¹i»k¸]ÐKóð ð —‘Ø�L‰LÐH˜6Ÿ:™:›<¨$×*HÑ*HÑHÐIÈEÑ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´°T×5IÑ5IÓ0JÐ/KÈ2Èd×NlÑNlÐMmÐmnÐ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@   € Ø˜q‘j U¨a¡ZÑ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   € à�Q‰Y˜!‰^ × 0Ñ 0°EÑ 9Ñ:¸eÀt×GWÑGWÑ>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   € Ø—^‘^×,Ñ,¨Q¨RÐ0ˆ
ØØ˜D×,Ñ,Ð-¨^¸D×<LÑ<LÐ;MÈQÐ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‘ 5¨D×,<Ñ,<Ñ#<Ñ=Ð=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   € Ø—^‘^×,Ñ,¨Q¨RÐ0ˆ
Ø˜ d×&6Ñ&6Ð%7°qÐ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Ñ)¨e°t×7GÑ7GÑ.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Ñ)¨e°d×6FÑ6FÑ.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   € Ü�y‰y˜ !™¨Ô,°·±¸2³ÀÑ1B×0GÑ0GÓ0IÈDÑ0PÑ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‘�|‰| ˆ|Ó# q§u¡u° u£}¸×8HÑ8HÑ'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 )Néþÿÿÿr^   r_   r   )ÚtrilÚviewrb   Úmin)r&   r'   Ú
value_trils      r(   r)   z_LowerTriangular.checkí  sC   € Ø—Z‘Z“\ˆ
Ø˜eÑ#×)Ñ)¨%¯+©+°c°rÐ*:¸UÑ*BÓC×GÑGÈÓKÈAÑ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{   € Ø—Z‘Z“\ˆ
à˜5Ñ ×&Ñ& u§{¡{°3°BÐ'7¸%Ñ'?Ó@×DÑDÀRÓHÈÑKð 	ð #Ÿ^™^°¸"˜^Ó=ÀÑA×FÑFÀrÓJÈ1Ñ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”   € ä�K‰K˜Ÿ™Ó$×(Ñ(¨5¯:©:°b«>Ñ9¸BÑ>ð 	ô —<‘<×$Ñ$ 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   € Ü�z‰zØ—‘˜S˜bÐ!ØŸ™ 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Ó+ˆØ×ÑÔ!ØÐÜ�}‰}˜U E§H¡H°4Ô8×<Ñ<¸RÓ@×DÑDÀRÓ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   ø€ Ü‘G‘M %Ó(ˆ	Ø�}‰}ŒØÐÜ�|‰|×$Ñ$ UÓ+×.Ñ.¨qÓ1×5Ñ5°bÓ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   ø€ Ü‘G‘M %Ó(ˆ	Ø�}‰}ŒØÐÜ�|‰|×'Ñ'¨Ó.×3Ñ3×6Ñ6°qÓ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ˆŒ	Øˆ?Ø�cœC §	¡	›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>[  ó   è ø€ Ò4 Q�1—=•=Ñ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   è ø€ Ò2 1�1—;•;Ñ2ùr  )Ú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£   € Ø—	‘	“ˆ|˜tŸx™xÔ5¨%¯)©)«+Ò5Ð5Ñ5Ð5Ð5ØˆØˆÜ! $§)¡)¨T¯\©\Ó:ò 	#‰NˆF�FØ—‘˜TŸX™X u¨fÓ5ˆAØ�M‰M˜&Ÿ,™, q›/Ô*Ø˜F‘N‰Eð	#ô �y‰y˜ §¡Ó*Ð*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 !�!—+•+Ñ1ùr  r   r,   )r  r  r`   )r&   r`   s     r(   r5   z_Stack.event_dim}  s4   € äÑ1 t§y¡yÔ1Ó1ˆØ�8‰8�c‰>˜AÒØ�1‰HˆCØˆ
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¦   € Ø—	‘	“ˆ|˜tŸx™xÔ5¨%¯)©)«+Ò5Ð5Ñ5Ð5Ð5Ü16°u·z±zÀ$Ç(Á(Ó7KÓ1LÖM¨Aˆe�l‰l˜4Ÿ8™8 QÕ'ÐMˆÐMÜ�{‰{Ü.1°"°d·i±iÓ.@×A¡  FˆV�\‰\˜!�_ÓAÀ4Ç8Á8ó
ð 	
ùò 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ô +ô2ˆjô 2ô�zô ô2�zô ô(˜*ô ô(ˆJô ô�:ô ô$�Zô ô$�
ô ô$�
ô ô*˜
ô ô*	Rˆzô 	RôJ�:ô Jô&	O�zô 	Oô4�Zô 4ô"=�Jô =ô"
ˆjô 
ô 	I�ô 	Iô	:˜Jô 	:ô	:˜
ô 	:ô!+ˆ:ô !+ôH
ˆZô 
ñB ‹L€	Ø'Ð Ø$€Ù
‹*€Ù
‹)€Ù)¨!Ó,Ð Ù& qÓ)Ð Ø#Ð Ùƒw€Ù˜$ Ó"€Ù˜Ó€Ù˜SÓ!€Ø€Ø €Ø€	Ø€Ù˜#˜sÓ#€Ø€Ø&Ð Ù
‹*€Ù#Ó%Ð ÙÓ!€Ù“€Ù	‹€Ù‹L€	Ù-Ó/Ð Ù%Ó'Ð Ø
€Ø�r*   