ó
    EñiïX  ã                   ó¾  • S SK Jr  S SKJr   S SKr/ SQr " S S5      r " S S\5      rS	 r " S
 S\	\5      r
 " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S  S!\5      r " S" S#\5      r " S$ S%\5      r " S& S'\5      r " S( S)\5      r " S* S+\5      r " S, S-\5      r " S. S/\5      r " S0 S1\5      r " S2 S3\5      r " S4 S5\5      r " S6 S7\5      r  " S8 S9\5      r! " S: S;\5      r"\" 5       r#\
r$\r%\" 5       r&\" 5       r'\" S 5      r(\" S<5      r)\r*\" 5       r+\%" \+S<5      r,\" S=5      r-\" S=5      r.\r/\r0\r1\r2\" S=S>5      r3\r4\r5\" 5       r6\" 5       r7\" 5       r8\" 5       r9\" 5       r:\" 5       r;\" 5       r<\ " 5       r=\!r>\"r?g)?é    )ÚCallable)ÚAnyN) Ú
ConstraintÚbooleanÚcatÚcorr_choleskyÚ	dependentÚdependent_propertyÚgreater_thanÚgreater_than_eqÚindependentÚinteger_intervalÚintervalÚhalf_open_intervalÚis_dependentÚ	less_thanÚlower_choleskyÚlower_triangularÚMixtureSameFamilyConstraintÚmultinomialÚnonnegativeÚnonnegative_integerÚone_hotÚpositiveÚpositive_semidefiniteÚpositive_definiteÚpositive_integerÚrealÚreal_vectorÚsimplexÚsquareÚstackÚ	symmetricÚunit_intervalc                   ó,   • \ rS rSrSrSrSrS rS rSr	g)	r   éP   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                 ó   • [         e)z{
Returns a byte tensor of ``sample_shape + batch_shape`` indicating
whether each event in value satisfies this constraint.
)ÚNotImplementedError©ÚselfÚvalues     Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributions/constraints.pyÚcheckÚConstraint.checkb   s
   € ô
 "Ð!ó    c                 ó:   • U R                   R                  SS  S-   $ )Né   z())Ú	__class__Ú__name__©r*   s    r,   Ú__repr__ÚConstraint.__repr__i   s   € Ø�~‰~×&Ñ& q rÐ*¨TÑ1Ð1r/   © N)
r3   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úis_discreteÚ	event_dimr-   r5   Ú__static_attributes__r7   r/   r,   r   r   P   s   † ñð €KØ€Iò"õ2r/   r   c                   ó|   ^ • \ rS rSrSr\\S.U 4S jjr\S\4S j5       r	\S\
4S j5       r\\S.S jrS	 rS
rU =r$ )Ú
_Dependentém   a!  
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.
©r<   r=   c                ó:   >• Xl         X l        [        TU ]  5         g ©N)Ú_is_discreteÚ
_event_dimÚsuperÚ__init__)r*   r<   r=   r2   s      €r,   rH   Ú_Dependent.__init__{   s   ø€ Ø'ÔØ#ŒÜ‰ÑÕr/   Úreturnc                 óV   • U R                   [        L a  [        S5      eU R                   $ )Nz,.is_discrete cannot be determined statically)rE   ÚNotImplementedr(   r4   s    r,   r<   Ú_Dependent.is_discrete€   s(   € à×Ñ¤Ò.Ü%Ð&TÓUÐUØ× Ñ Ð r/   c                 óV   • U R                   [        L a  [        S5      eU R                   $ )Nz*.event_dim cannot be determined statically)rF   rL   r(   r4   s    r,   r=   Ú_Dependent.event_dim†   s$   € à�?‰?œnÒ,Ü%Ð&RÓSÐSØ�‰Ðr/   c                óh   • U[         L a  U R                  nU[         L a  U R                  n[        XS9$ )zo
Support for syntax to customize static attributes::

    constraints.dependent(is_discrete=True, event_dim=1)
rB   )rL   rE   rF   r@   )r*   r<   r=   s      r,   Ú__call__Ú_Dependent.__call__Œ   s3   € ð œ.Ò(Ø×+Ñ+ˆKØœÒ&ØŸ™ˆIÜ kÑGÐGr/   c                 ó   • [        S5      e)Nz1Cannot determine validity of dependent constraint)Ú
ValueError©r*   Úxs     r,   r-   Ú_Dependent.check˜   s   € ÜÐLÓMÐMr/   ©rF   rE   )r3   r8   r9   r:   r;   rL   rH   ÚpropertyÚboolr<   Úintr=   rQ   r-   r>   Ú__classcell__©r2   s   @r,   r@   r@   m   sh   ø† ñð '5À÷ ð ð
 ð!˜Tó !ó ð!ð
 ð˜3ó ó ðð
 '5Àõ 
H÷Nð Nr/   r@   c                 ó"   • [        U [        5      $ )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            
       óˆ   ^ • \ rS rSrSr S\\S.S\S\4   S-  S\S-  S\	S-  S	S4U 4S
 jjjjr
S\S\4   S	S 4S jrSrU =r$ )Ú_DependentPropertyé¶   aŽ  
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.
NrB   Úfn.r<   r=   rJ   c                ó<   >• [         TU ]  U5        X l        X0l        g rD   )rG   rH   rE   rF   )r*   rd   r<   r=   r2   s       €r,   rH   Ú_DependentProperty.__init__Ð   s   ø€ ô 	‰Ñ˜ÔØ'ÔØ#�r/   c                 ó>   • [        XR                  U R                  S9$ )z”
Support for syntax to customize static attributes::

    @constraints.dependent_property(is_discrete=True, event_dim=1)
    def support(self): ...
rB   )rb   rE   rF   )r*   rd   s     r,   rQ   Ú_DependentProperty.__call__Û   s    € ô "Ø×-Ñ-¸¿¹ñ
ð 	
r/   rX   rD   )r3   r8   r9   r:   r;   rL   r   r   rZ   r[   rH   rQ   r>   r\   r]   s   @r,   rb   rb   ¶   s‚   ø† ñð6 )-ð	$ð $2Ø .ò	$à�S˜#�XÑ Ñ%ð	$ð ˜D‘[ð		$ð
 ˜‘:ð	$ð 
÷	$ñ 	$ð	
˜8 C¨ HÑ-ð 	
Ð2F÷ 	
ò 	
r/   rb   c                   óh   ^ • \ rS rSrSrU 4S jr\S\4S j5       r\S\	4S j5       r
S rS rS	rU =r$ )
Ú_IndependentConstraintéç   z«
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                 ó:  >• [        U[        5      (       d!  [        S[        U5      R                   35      e[        U[
        5      (       d!  [        S[        U5      R                   35      eUS:  a  [        SU 35      eXl        X l        [        TU ]%  5         g )Nú*base_constraint must be a Constraint, got z.reinterpreted_batch_ndims must be an int, got r   z,reinterpreted_batch_ndims must be >= 0, got )
r_   r   ÚAssertionErrorÚtyper3   r[   Úbase_constraintÚreinterpreted_batch_ndimsrG   rH   )r*   rp   rq   r2   s      €r,   rH   Ú_IndependentConstraint.__init__î   s£   ø€ Ü˜/¬:×6Ñ6Ü Ø<¼TÀ/Ó=R×=[Ñ=[Ð<\Ð]óð ô Ð3´S×9Ñ9Ü Ø@ÄÐF_ÓA`×AiÑAiÐ@jÐkóð ð % qÓ(Ü Ø>Ð?XÐ>YÐZóð ð  /ÔØ)BÔ&Ü‰ÑÕr/   rJ   c                 ó.   • U R                   R                  $ rD   ©rp   r<   r4   s    r,   r<   Ú"_IndependentConstraint.is_discreteÿ   ó   € à×#Ñ#×/Ñ/Ð/r/   c                 óH   • U R                   R                  U R                  -   $ rD   )rp   r=   rq   r4   s    r,   r=   Ú _IndependentConstraint.event_dim  s   € à×#Ñ#×-Ñ-°×0NÑ0NÑNÐNr/   c                 ó–  • U R                   R                  U5      nUR                  5       U R                  :  aB  U R                   R                  U R                  -   n[        SU SUR                  5        35      eUR                  UR                  S UR                  5       U R                  -
   S-   5      nUR                  S5      nU$ )NúExpected value.dim() >= ú	 but got ©éÿÿÿÿr}   )	rp   r-   Údimrq   r=   rT   ÚreshapeÚshapeÚall)r*   r+   ÚresultÚexpecteds       r,   r-   Ú_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                 ó€   • U R                   R                  SS   S[        U R                  5       SU R                   S3$ )Nr1   Ú(z, Ú))r2   r3   Úreprrp   rq   r4   s    r,   r5   Ú_IndependentConstraint.__repr__  sA   € Ø—.‘.×)Ñ)¨!¨"Ð-Ð.¨a´°T×5IÑ5IÓ0JÐ/KÈ2Èd×NlÑNlÐMmÐmnÐoÐor/   )rp   rq   ©r3   r8   r9   r:   r;   rH   rY   rZ   r<   r[   r=   r-   r5   r>   r\   r]   s   @r,   rj   rj   ç   sW   ø† ñõð" ð0˜Tó 0ó ð0ð ðO˜3ó Oó ðOò÷pð pr/   rj   c                   óh   ^ • \ rS rSrSrU 4S jr\S\4S j5       r\S\	4S j5       r
S rS rS	rU =r$ )
r   i  av  
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                 óš   >• [        U[        5      (       d!  [        S[        U5      R                   35      eXl        [        TU ]  5         g )Nrm   )r_   r   rn   ro   r3   rp   rG   rH   )r*   rp   r2   s     €r,   rH   Ú$MixtureSameFamilyConstraint.__init__%  sF   ø€ Ü˜/¬:×6Ñ6Ü Ø<¼TÀ/Ó=R×=[Ñ=[Ð<\Ð]óð ð  /ÔÜ‰ÑÕr/   rJ   c                 ó.   • U R                   R                  $ rD   rt   r4   s    r,   r<   Ú'MixtureSameFamilyConstraint.is_discrete-  rv   r/   c                 ó.   • U R                   R                  $ rD   )rp   r=   r4   s    r,   r=   Ú%MixtureSameFamilyConstraint.event_dim1  s   € à×#Ñ#×-Ñ-Ð-r/   c                 ó¤  • UR                  SU R                  -
  5      nU R                  R                  U5      nUR	                  5       U R                  :  a)  [        SU R                   SUR	                  5        35      eUR	                  5       U R                  -
  nUR                  UR                  SU S-   5      nUR                  S5      nU$ )z€
Check validity of ``value`` as a possible outcome of sampling
the :class:`~torch.distribution.MixtureSameFamily` distribution.
r}   rz   r{   Nr|   )	Ú	unsqueezer=   rp   r-   r~   rT   r   r€   r�   )r*   r+   Úunsqueezed_valuer‚   Únum_dim_to_keeps        r,   r-   Ú!MixtureSameFamilyConstraint.check5  s´   € ð
 !Ÿ?™?¨2°·±Ñ+>Ó?ÐØ×%Ñ%×+Ñ+Ð,<Ó=ˆØ�9‰9‹;˜Ÿ™Ó'ÜØ*¨4¯>©>Ð*:¸)ÀEÇIÁIÃKÀ=ÐQóð ð  Ÿ)™)›+¨¯©Ñ6ˆØ—‘ §¡Ð-=¨oÐ >ÀÑ FÓGˆØ—‘˜B“ˆØˆr/   c                 ó`   • U R                   R                   S[        U R                  5       S3$ )Nr†   r‡   )r2   r3   rˆ   rp   r4   s    r,   r5   Ú$MixtureSameFamilyConstraint.__repr__E  s,   € Ø—.‘.×)Ñ)Ð*¨!¬D°×1EÑ1EÓ,FÐ+GÀqÐIÐIr/   )rp   rŠ   r]   s   @r,   r   r     sT   ø† ñ
õð ð0˜Tó 0ó ð0ð ð.˜3ó .ó ð.ò÷ Jð Jr/   r   c                   ó"   • \ rS rSrSrSrS rSrg)Ú_BooleaniI  z'
Constrain to the two values `{0, 1}`.
Tc                 ó   • US:H  US:H  -  $ )Nr   r1   r7   r)   s     r,   r-   Ú_Boolean.checkP  s   € Ø˜‘
˜u¨™zÑ*Ð*r/   r7   N)r3   r8   r9   r:   r;   r<   r-   r>   r7   r/   r,   rš   rš   I  s   † ñð €Kõ+r/   rš   c                   ó&   • \ rS rSrSrSrSrS rSrg)Ú_OneHotiT  z
Constrain to one-hot vectors.
Tr1   c                 ó€   • US:H  US:H  -  nUR                  S5      R                  S5      nUR                  S5      U-  $ )Nr   r1   r}   )ÚsumÚeqr�   )r*   r+   Ú
is_booleanÚis_normalizeds       r,   r-   Ú_OneHot.check\  s@   € Ø˜q‘j U¨a¡ZÑ0ˆ
ØŸ	™	 "›×(Ñ(¨Ó+ˆØ�~‰~˜bÓ! MÑ1Ð1r/   r7   N)	r3   r8   r9   r:   r;   r<   r=   r-   r>   r7   r/   r,   rž   rž   T  s   † ñð €KØ€Iõ2r/   rž   c                   ó<   ^ • \ rS rSrSrSrU 4S jrS rS rSr	U =r
$ )Ú_IntegerIntervalib  z@
Constrain to an integer interval `[lower_bound, upper_bound]`.
Tc                 ó:   >• Xl         X l        [        TU ]  5         g rD   ©Úlower_boundÚupper_boundrG   rH   ©r*   r©   rª   r2   s      €r,   rH   Ú_IntegerInterval.__init__i  ó   ø€ Ø&ÔØ&ÔÜ‰ÑÕr/   c                 óP   • US-  S:H  U R                   U:*  -  XR                  :*  -  $ ©Nr1   r   ©r©   rª   r)   s     r,   r-   Ú_IntegerInterval.checkn  s0   € à�Q‰Y˜!‰^ × 0Ñ 0°EÑ 9Ñ:¸e×GWÑGWÑ>WÑXð	
r/   c                 óx   • U R                   R                  SS  nUSU R                   SU R                   S3-  nU$ ©Nr1   ú(lower_bound=z, upper_bound=r‡   ©r2   r3   r©   rª   ©r*   Ú
fmt_strings     r,   r5   Ú_IntegerInterval.__repr__s  óJ   € Ø—^‘^×,Ñ,¨Q¨RÐ0ˆ
ØØ˜D×,Ñ,Ð-¨^¸D×<LÑ<LÐ;MÈQÐOñ	
ˆ
ð Ðr/   r°   ©r3   r8   r9   r:   r;   r<   rH   r-   r5   r>   r\   r]   s   @r,   r¦   r¦   b  s#   ø† ñð €Kõò

÷
ð r/   r¦   c                   ó<   ^ • \ rS rSrSrSrU 4S jrS rS rSr	U =r
$ )Ú_IntegerLessThani{  z9
Constrain to an integer interval `(-inf, upper_bound]`.
Tc                 ó.   >• Xl         [        TU ]	  5         g rD   ©rª   rG   rH   ©r*   rª   r2   s     €r,   rH   Ú_IntegerLessThan.__init__‚  ó   ø€ Ø&ÔÜ‰ÑÕr/   c                 ó0   • US-  S:H  XR                   :*  -  $ r¯   ©rª   r)   s     r,   r-   Ú_IntegerLessThan.check†  ó   € Ø˜‘	˜Q‘ 5×,<Ñ,<Ñ#<Ñ=Ð=r/   c                 ó^   • U R                   R                  SS  nUSU R                   S3-  nU$ ©Nr1   z(upper_bound=r‡   ©r2   r3   rª   r¶   s     r,   r5   Ú_IntegerLessThan.__repr__‰  ó8   € Ø—^‘^×,Ñ,¨Q¨RÐ0ˆ
Ø˜ d×&6Ñ&6Ð%7°qÐ9Ñ9ˆ
ØÐr/   rÃ   rº   r]   s   @r,   r¼   r¼   {  ó#   ø† ñð €Kõò>÷ð r/   r¼   c                   ó<   ^ • \ rS rSrSrSrU 4S jrS rS rSr	U =r
$ )Ú_IntegerGreaterThani�  z8
Constrain to an integer interval `[lower_bound, inf)`.
Tc                 ó.   >• Xl         [        TU ]	  5         g rD   ©r©   rG   rH   ©r*   r©   r2   s     €r,   rH   Ú_IntegerGreaterThan.__init__–  rÁ   r/   c                 ó0   • US-  S:H  XR                   :¬  -  $ r¯   ©r©   r)   s     r,   r-   Ú_IntegerGreaterThan.checkš  rÅ   r/   c                 ó^   • U R                   R                  SS  nUSU R                   S3-  nU$ ©Nr1   r´   r‡   ©r2   r3   r©   r¶   s     r,   r5   Ú_IntegerGreaterThan.__repr__�  rÊ   r/   rÓ   rº   r]   s   @r,   rÍ   rÍ   �  rË   r/   rÍ   c                   ó   • \ rS rSrSrS rSrg)Ú_Reali£  z>
Trivially constrain to the extended real line `[-inf, inf]`.
c                 ó
   • X:H  $ rD   r7   r)   s     r,   r-   Ú_Real.check¨  s
   € Ø‰~Ðr/   r7   N)r3   r8   r9   r:   r;   r-   r>   r7   r/   r,   rÚ   rÚ   £  s   † ñõr/   rÚ   c                   ó8   ^ • \ rS rSrSrU 4S jrS rS rSrU =r	$ )Ú_GreaterThani¬  z5
Constrain to a real half line `(lower_bound, inf]`.
c                 ó.   >• Xl         [        TU ]	  5         g rD   rÏ   rÐ   s     €r,   rH   Ú_GreaterThan.__init__±  rÁ   r/   c                 ó    • U R                   U:  $ rD   rÓ   r)   s     r,   r-   Ú_GreaterThan.checkµ  s   € Ø×Ñ %Ñ'Ð'r/   c                 ó^   • U R                   R                  SS  nUSU R                   S3-  nU$ rÖ   r×   r¶   s     r,   r5   Ú_GreaterThan.__repr__¸  rÊ   r/   rÓ   ©
r3   r8   r9   r:   r;   rH   r-   r5   r>   r\   r]   s   @r,   rÞ   rÞ   ¬  ó   ø† ñõò(÷ð r/   rÞ   c                   ó8   ^ • \ rS rSrSrU 4S jrS rS rSrU =r	$ )Ú_GreaterThanEqi¾  z5
Constrain to a real half line `[lower_bound, inf)`.
c                 ó.   >• Xl         [        TU ]	  5         g rD   rÏ   rÐ   s     €r,   rH   Ú_GreaterThanEq.__init__Ã  rÁ   r/   c                 ó    • U R                   U:*  $ rD   rÓ   r)   s     r,   r-   Ú_GreaterThanEq.checkÇ  s   € Ø×Ñ 5Ñ(Ð(r/   c                 ó^   • U R                   R                  SS  nUSU R                   S3-  nU$ rÖ   r×   r¶   s     r,   r5   Ú_GreaterThanEq.__repr__Ê  rÊ   r/   rÓ   rå   r]   s   @r,   rè   rè   ¾  s   ø† ñõò)÷ð r/   rè   c                   ó8   ^ • \ rS rSrSrU 4S jrS rS rSrU =r	$ )Ú	_LessThaniÐ  z6
Constrain to a real half line `[-inf, upper_bound)`.
c                 ó.   >• Xl         [        TU ]	  5         g rD   r¾   r¿   s     €r,   rH   Ú_LessThan.__init__Õ  rÁ   r/   c                 ó   • XR                   :  $ rD   rÃ   r)   s     r,   r-   Ú_LessThan.checkÙ  s   € Ø×'Ñ'Ñ'Ð'r/   c                 ó^   • U R                   R                  SS  nUSU R                   S3-  nU$ rÇ   rÈ   r¶   s     r,   r5   Ú_LessThan.__repr__Ü  rÊ   r/   rÃ   rå   r]   s   @r,   rð   rð   Ð  ræ   r/   rð   c                   ó8   ^ • \ rS rSrSrU 4S jrS rS rSrU =r	$ )Ú	_Intervaliâ  z<
Constrain to a real interval `[lower_bound, upper_bound]`.
c                 ó:   >• Xl         X l        [        TU ]  5         g rD   r¨   r«   s      €r,   rH   Ú_Interval.__init__ç  r­   r/   c                 ó>   • U R                   U:*  XR                  :*  -  $ rD   r°   r)   s     r,   r-   Ú_Interval.checkì  s!   € Ø× Ñ  EÑ)¨e×7GÑ7GÑ.GÑHÐHr/   c                 óx   • U R                   R                  SS  nUSU R                   SU R                   S3-  nU$ r³   rµ   r¶   s     r,   r5   Ú_Interval.__repr__ï  r¹   r/   r°   rå   r]   s   @r,   rø   rø   â  s   ø† ñõò
I÷ð r/   rø   c                   ó8   ^ • \ rS rSrSrU 4S jrS rS rSrU =r	$ )Ú_HalfOpenIntervali÷  z<
Constrain to a real interval `[lower_bound, upper_bound)`.
c                 ó:   >• Xl         X l        [        TU ]  5         g rD   r¨   r«   s      €r,   rH   Ú_HalfOpenInterval.__init__ü  r­   r/   c                 ó>   • U R                   U:*  XR                  :  -  $ rD   r°   r)   s     r,   r-   Ú_HalfOpenInterval.check  s!   € Ø× Ñ  EÑ)¨e×6FÑ6FÑ.FÑGÐGr/   c                 óx   • U R                   R                  SS  nUSU R                   SU R                   S3-  nU$ r³   rµ   r¶   s     r,   r5   Ú_HalfOpenInterval.__repr__  r¹   r/   r°   rå   r]   s   @r,   r   r   ÷  s   ø† ñõò
H÷ð r/   r   c                   ó"   • \ rS rSrSrSrS rSrg)Ú_Simplexi  zt
Constrain to the unit simplex in the innermost (rightmost) dimension.
Specifically: `x >= 0` and `x.sum(-1) == 1`.
r1   c                 ó~   • [         R                  " US:¬  SS9UR                  S5      S-
  R                  5       S:  -  $ )Nr   r}   ©r~   r1   ç�íµ ÷Æ°>)Útorchr�   r    Úabsr)   s     r,   r-   Ú_Simplex.check  s7   € Ü�yŠy˜ !™¨Ñ,°·±¸2³ÀÑ1B×0GÑ0GÓ0IÈDÑ0PÑQÐQr/   r7   N©r3   r8   r9   r:   r;   r=   r-   r>   r7   r/   r,   r  r    s   † ñð
 €IõRr/   r  c                   ó,   • \ rS rSrSrSrSrS rS rSr	g)	Ú_Multinomiali  a  
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``.
Tr1   c                 ó   • Xl         g rD   rÃ   )r*   rª   s     r,   rH   Ú_Multinomial.__init__$  s   € Ø&Õr/   c                 ó`   • US:¬  R                  SS9UR                  SS9U R                  :*  -  $ )Nr   r}   r
  )r�   r    rª   rU   s     r,   r-   Ú_Multinomial.check'  s1   € Ø�Q‘�|‰| ˆ|Ð# q§u¡u° u }¸×8HÑ8HÑ'HÑIÐIr/   rÃ   N)
r3   r8   r9   r:   r;   r<   r=   rH   r-   r>   r7   r/   r,   r  r    s   † ñð €KØ€Iò'õJr/   r  c                   ó"   • \ rS rSrSrSrS rSrg)Ú_LowerTriangulari+  z0
Constrain to lower-triangular square matrices.
é   c                 óŒ   • UR                  5       nX!:H  R                  UR                  S S S-   5      R                  S5      S   $ )Néþÿÿÿr|   r}   r   )ÚtrilÚviewr€   Úmin)r*   r+   Ú
value_trils      r,   r-   Ú_LowerTriangular.check2  sA   € Ø—Z‘Z“\ˆ
ØÑ#×)Ñ)¨%¯+©+°c°rÐ*:¸UÑ*BÓC×GÑGÈÓKÈAÑNÐNr/   r7   Nr  r7   r/   r,   r  r  +  s   † ñð €IõOr/   r  c                   ó"   • \ rS rSrSrSrS rSrg)Ú_LowerCholeskyi7  zH
Constrain to lower-triangular square matrices with positive diagonals.
r  c                 óÞ   • UR                  5       nX!:H  R                  UR                  S S S-   5      R                  S5      S   nUR	                  SSS9S:„  R                  S5      S   nX4-  $ )Nr  r|   r}   r   )Údim1Údim2)r  r  r€   r  Údiagonal)r*   r+   r  r   Úpositive_diagonals        r,   r-   Ú_LowerCholesky.check>  sv   € Ø—Z‘Z“\ˆ
àÑ ×&Ñ& u§{¡{°3°BÐ'7¸%Ñ'?Ó@×DÑDÀRÓHÈÑKð 	ð #Ÿ^™^°¸"˜^Ð=ÀÑA×FÑFÀrÓJÈ1ÑMÐØÑ3Ð3r/   r7   Nr  r7   r/   r,   r!  r!  7  s   † ñð €Iõ4r/   r!  c                   ó"   • \ rS rSrSrSrS rSrg)Ú_CorrCholeskyiH  zq
Constrain to lower-triangular square matrices with positive diagonals and each
row vector being of unit length.
r  c                 ón  • [         R                  " UR                  5      R                  UR	                  S5      -  S-  n[         R
                  R                  UR                  5       SS9nUS-
  R                  5       R                  U5      R                  SS9n[        5       R                  U5      U-  $ )Nr}   é
   r
  ç      ð?)r  ÚfinfoÚdtypeÚepsÚsizeÚlinalgÚnormÚdetachr  Úler�   r!  r-   )r*   r+   ÚtolÚrow_normÚunit_row_norms        r,   r-   Ú_CorrCholesky.checkP  s”   € ä�KŠK˜Ÿ™Ó$×(Ñ(¨5¯:©:°b«>Ñ9¸BÑ>ð 	ô —<‘<×$Ñ$ U§\¡\£^¸Ð$Ð<ˆØ! C™×,Ñ,Ó.×1Ñ1°#Ó6×:Ñ:¸rÐ:ÐBˆÜÓ×%Ñ% eÓ,¨}Ñ<Ð<r/   r7   Nr  r7   r/   r,   r)  r)  H  s   † ñð
 €Iõ=r/   r)  c                   ó"   • \ rS rSrSrSrS rSrg)Ú_SquareiY  z
Constrain to square matrices.
r  c                 ó´   • [         R                  " UR                  S S UR                  S   UR                  S   :H  [         R                  UR                  S9$ )Nr  r}   )r0  Ú
fill_valuer.  Údevice)r  Úfullr€   rZ   r=  r)   s     r,   r-   Ú_Square.check`  sG   € Ü�zŠzØ—‘˜S˜bÐ!ØŸ™ B™¨5¯;©;°r©?Ñ:Ü—*‘*Ø—<‘<ñ	
ð 	
r/   r7   Nr  r7   r/   r,   r:  r:  Y  s   † ñð €Iõ
r/   r:  c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )Ú
_Symmetricii  z)
Constrain to Symmetric square matrices.
c                 óÊ   >• [         TU ]  U5      nUR                  5       (       d  U$ [        R                  " XR
                  SS9R                  S5      R                  S5      $ )Nr  )Úatolr  r}   )rG   r-   r�   r  ÚiscloseÚmT)r*   r+   Úsquare_checkr2   s      €r,   r-   Ú_Symmetric.checkn  sQ   ø€ Ü‘w‘} UÓ+ˆØ×Ñ×!Ñ!ØÐÜ�}Š}˜U§H¡H°4Ñ8×<Ñ<¸RÓ@×DÑDÀRÓHÐHr/   r7   ©r3   r8   r9   r:   r;   r-   r>   r\   r]   s   @r,   rA  rA  i  s   ø† ñ÷Ió Ir/   rA  c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )Ú_PositiveSemidefiniteiu  z.
Constrain to positive-semidefinite matrices.
c                 óÊ   >• [         TU ]  U5      nUR                  5       (       d  U$ [        R                  R                  U5      R                  S5      R                  S5      $ )Nr   r}   )rG   r-   r�   r  r1  ÚeigvalshÚge©r*   r+   Ú	sym_checkr2   s      €r,   r-   Ú_PositiveSemidefinite.checkz  sM   ø€ Ü‘G‘M %Ó(ˆ	Ø�}‰}�‰ØÐÜ�|‰|×$Ñ$ UÓ+×.Ñ.¨qÓ1×5Ñ5°bÓ9Ð9r/   r7   rH  r]   s   @r,   rJ  rJ  u  ó   ø† ñ÷:ó :r/   rJ  c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )Ú_PositiveDefinitei�  z*
Constrain to positive-definite matrices.
c                 óÀ   >• [         TU ]  U5      nUR                  5       (       d  U$ [        R                  R                  U5      R                  R                  S5      $ )Nr   )rG   r-   r�   r  r1  Úcholesky_exÚinfor¡   rN  s      €r,   r-   Ú_PositiveDefinite.check†  sH   ø€ Ü‘G‘M %Ó(ˆ	Ø�}‰}�‰ØÐÜ�|‰|×'Ñ'¨Ó.×3Ñ3×6Ñ6°qÓ9Ð9r/   r7   rH  r]   s   @r,   rS  rS  �  rQ  r/   rS  c                   óf   ^ • \ rS rSrSrS	U 4S jjr\S\4S j5       r\S\	4S j5       r
S rSrU =r$ )
Ú_Cati�  z²
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                 ó²  >• [        S U 5       5      (       d  [        S5      e[        U5      U l        Uc  S/[	        U R                  5      -  n[        U5      U l        [	        U R
                  5      [	        U R                  5      :w  a8  [        S[	        U R
                  5       S[	        U R                  5       S35      eX l        [        TU ]!  5         g )Nc              3   óB   #   • U  H  n[        U[        5      v •  M     g 7frD   ©r_   r   ©Ú.0Úcs     r,   Ú	<genexpr>Ú _Cat.__init__.<locals>.<genexpr>•  ó   é € Ð;²d°”:˜a¤×,Ð,²dùó   ‚ú1All elements of cseq must be Constraint instancesr1   z	lengths (z) must match cseq (r‡   )	r�   rn   ÚlistÚcseqÚlenÚlengthsr~   rG   rH   )r*   rf  r~   rh  r2   s       €r,   rH   Ú_Cat.__init__”  s®   ø€ ÜÑ;±dÓ;×;Ñ;Ü Ð!TÓUÐUÜ˜“JˆŒ	Ø‰?Ø�cœC §	¡	›NÑ*ˆGÜ˜G“}ˆŒÜˆt�|‰|Ó¤ D§I¡I£Ó.Ü ØœC §¡Ó-Ð.Ð.AÄ#ÀdÇiÁiÃ.ÐAQÐQRÐSóð ð ŒÜ‰ÑÕr/   rJ   c                 ó:   • [        S U R                   5       5      $ )Nc              3   ó8   #   • U  H  oR                   v •  M     g 7frD   ©r<   r]  s     r,   r`  Ú#_Cat.is_discrete.<locals>.<genexpr>¤  ó   é € Ð4ª) Q—=–=ª)ùó   ‚©Úanyrf  r4   s    r,   r<   Ú_Cat.is_discrete¢  ó   € äÑ4¨$¯)ª)Ó4Ó4Ð4r/   c                 ó:   • [        S U R                   5       5      $ )Nc              3   ó8   #   • U  H  oR                   v •  M     g 7frD   ©r=   r]  s     r,   r`  Ú!_Cat.event_dim.<locals>.<genexpr>¨  s   é € Ð2ª	 1—;–;ª	ùro  )Úmaxrf  r4   s    r,   r=   Ú_Cat.event_dim¦  s   € äÑ2¨¯	ª	Ó2Ó2Ð2r/   c                 óÜ  • UR                  5       * U R                   s=::  a  UR                  5       :  d,  O  [        SU R                    SUR                  5        S35      e/ nSn[        U R                  U R                  5       HE  u  pEUR                  U R                   X55      nUR                  UR                  U5      5        X5-   nMG     [        R                  " X R                   5      $ )Núdim ú out of range for value with ú dimensionsr   )
r~   rn   Úziprf  rh  ÚnarrowÚappendr-   r  r   )r*   r+   ÚchecksÚstartÚconstrÚlengthÚvs          r,   r-   Ú
_Cat.checkª  s¶   € Ø—‘“� §¡Õ6¨5¯9©9«;Õ6Ü Ø�t—x‘x�jÐ =¸e¿i¹i»k¸]È+ÐVóð ð ˆØˆÜ! $§)¡)¨T¯\©\Ö:‰NˆFØ—‘˜TŸX™X uÓ5ˆAØ�M‰M˜&Ÿ,™, q›/Ô*Ø‘NŠEñ ;ô �yŠy˜§¡Ó*Ð*r/   )rf  r~   rh  )r   N©r3   r8   r9   r:   r;   rH   rY   rZ   r<   r[   r=   r-   r>   r\   r]   s   @r,   rY  rY  �  sM   ø† ñ÷ð ð5˜Tó 5ó ð5ð ð3˜3ó 3ó ð3÷+ð +r/   rY  c                   óf   ^ • \ rS rSrSrS	U 4S jjr\S\4S j5       r\S\	4S j5       r
S rSrU =r$ )
Ú_Stacki¸  z—
Constraint functor that applies a sequence of constraints
`cseq` at the submatrices at dimension `dim`,
in a way compatible with :func:`torch.stack`.
c                 ó’   >• [        S U 5       5      (       d  [        S5      e[        U5      U l        X l        [
        TU ]  5         g )Nc              3   óB   #   • U  H  n[        U[        5      v •  M     g 7frD   r\  r]  s     r,   r`  Ú"_Stack.__init__.<locals>.<genexpr>À  rb  rc  rd  )r�   rn   re  rf  r~   rG   rH   )r*   rf  r~   r2   s      €r,   rH   Ú_Stack.__init__¿  s;   ø€ ÜÑ;±dÓ;×;Ñ;Ü Ð!TÓUÐUÜ˜“JˆŒ	ØŒÜ‰ÑÕr/   rJ   c                 ó:   • [        S U R                   5       5      $ )Nc              3   ó8   #   • U  H  oR                   v •  M     g 7frD   rl  r]  s     r,   r`  Ú%_Stack.is_discrete.<locals>.<genexpr>È  rn  ro  rp  r4   s    r,   r<   Ú_Stack.is_discreteÆ  rs  r/   c                 ón   • [        S U R                   5       5      nU R                  U-   S:  a  US-  nU$ )Nc              3   ó8   #   • U  H  oR                   v •  M     g 7frD   rv  r]  s     r,   r`  Ú#_Stack.event_dim.<locals>.<genexpr>Ì  s   é € Ð1¢y !—+–+¢yùro  r   r1   )rx  rf  r~   )r*   r~   s     r,   r=   Ú_Stack.event_dimÊ  s4   € äÑ1 t§y¢yÓ1Ó1ˆØ�8‰8�c‰>˜AÓØ�1‰HˆCØˆ
r/   c           	      ó"  • UR                  5       * U R                   s=::  a  UR                  5       :  d,  O  [        SU R                    SUR                  5        S35      e[        UR                  U R                   5      5       Vs/ s H  o!R	                  U R                   U5      PM      nn[
        R                  " [        X0R                  5       VVs/ s H  u  pEUR                  U5      PM     snnU R                   5      $ s  snf s  snnf )Nr{  r|  r}  )
r~   rn   Úranger0  Úselectr  r"   r~  rf  r-   )r*   r+   ÚiÚvsr…  rƒ  s         r,   r-   Ú_Stack.checkÑ  sÉ   € Ø—‘“� §¡Õ6¨5¯9©9«;Õ6Ü Ø�t—x‘x�jÐ =¸e¿i¹i»k¸]È+ÐVóð ô 27°u·z±zÀ$Ç(Á(Ó7KÔ1LÓMÒ1L¨A�l‰l˜4Ÿ8™8 QÖ'Ñ1LˆÐMÜ�{Š{Ü.1°"·i±iÔ.@ÔAÒ.@¡ ˆV�\‰\˜!Ž_Ñ.@ÒAÀ4Ç8Á8ó
ð 	
ùò NùãAs   Â%DÃD
)rf  r~   )r   r‡  r]   s   @r,   r‰  r‰  ¸  sM   ø† ñ÷ð ð5˜Tó 5ó ð5ð ð˜3ó ó ð÷
ð 
r/   r‰  r1   g        r,  )@Úcollections.abcr   Útypingr   r  Ú__all__r   r@   r   rY   rb   rj   r   rš   rž   r¦   r¼   rÍ   rÚ   rÞ   rè   rð   rø   r   r  r  r  r!  r)  r:  rA  rJ  rS  rY  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"   r7   r/   r,   Ú<module>rŸ     sV  ðõ %Ý ð óD ò!€÷H2ñ 2ô:,N�ô ,Nò^.ô4.
˜ :ô .
ôb.p˜Zô .pôb.J *ô .Jôb+ˆ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ô 	:ô	:˜
ô 	:ô(+ˆ:ô (+ôV!
ˆZô !
ñJ ‹L€	Ø'Ð Ø$€Ù
‹*€Ù
‹)€Ù)¨!Ó,Ð Ù& qÓ)Ð Ø#Ð Ùƒw€Ù˜$ Ó"€Ù˜Ó€Ù˜SÓ!€Ø€Ø €Ø€	Ø€Ù˜#˜sÓ#€Ø€Ø&Ð Ù
‹*€Ù#Ó%Ð ÙÓ!€Ù“€Ù	‹€Ù‹L€	Ù-Ó/Ð Ù%Ó'Ð Ø
€Ø�r/   