ó
    EñiB(  ã                   óˆ  • S r SSKJrJr  SSKJr  / SQr " S S5      r\" 5       r\" 5       r	\R                  \R                  5      \	R                  \R                  5      S 5       5       r\R                  \R                  5      S 5       r\	R                  \R                  5      S	 5       r\R                  \R                   5      \R                  \R"                  5      \	R                  \R                   5      \	R                  \R"                  5      S
 5       5       5       5       r\R                  \R&                  5      \R                  \R(                  5      \	R                  \R&                  5      \	R                  \R(                  5      S 5       5       5       5       r\R                  \R,                  5      \	R                  \R,                  5      S 5       5       r\R                  \R0                  5      \R                  \R2                  5      \	R                  \R0                  5      \	R                  \R2                  5      S 5       5       5       5       r\R                  \R6                  5      S 5       r\	R                  \R6                  5      S 5       r\	R                  \R<                  5      S 5       r\	R                  \R@                  5      \	R                  \RB                  5      S 5       5       r"\R                  \RF                  5      \	R                  \RF                  5      S 5       5       r$\R                  \RJ                  5      S 5       r&\	R                  \RJ                  5      S 5       r'\R                  \RP                  5      S 5       r)\	R                  \RP                  5      S 5       r*g)aF  
PyTorch provides two global :class:`ConstraintRegistry` objects that link
:class:`~torch.distributions.constraints.Constraint` objects to
:class:`~torch.distributions.transforms.Transform` objects. These objects both
input constraints and return transforms, but they have different guarantees on
bijectivity.

1. ``biject_to(constraint)`` looks up a bijective
   :class:`~torch.distributions.transforms.Transform` from ``constraints.real``
   to the given ``constraint``. The returned transform is guaranteed to have
   ``.bijective = True`` and should implement ``.log_abs_det_jacobian()``.
2. ``transform_to(constraint)`` looks up a not-necessarily bijective
   :class:`~torch.distributions.transforms.Transform` from ``constraints.real``
   to the given ``constraint``. The returned transform is not guaranteed to
   implement ``.log_abs_det_jacobian()``.

The ``transform_to()`` registry is useful for performing unconstrained
optimization on constrained parameters of probability distributions, which are
indicated by each distribution's ``.arg_constraints`` dict. These transforms often
overparameterize a space in order to avoid rotation; they are thus more
suitable for coordinate-wise optimization algorithms like Adam::

    loc = torch.zeros(100, requires_grad=True)
    unconstrained = torch.zeros(100, requires_grad=True)
    scale = transform_to(Normal.arg_constraints["scale"])(unconstrained)
    loss = -Normal(loc, scale).log_prob(data).sum()

The ``biject_to()`` registry is useful for Hamiltonian Monte Carlo, where
samples from a probability distribution with constrained ``.support`` are
propagated in an unconstrained space, and algorithms are typically rotation
invariant.::

    dist = Exponential(rate)
    unconstrained = torch.zeros(100, requires_grad=True)
    sample = biject_to(dist.support)(unconstrained)
    potential_energy = -dist.log_prob(sample).sum()

.. note::

    An example where ``transform_to`` and ``biject_to`` differ is
    ``constraints.simplex``: ``transform_to(constraints.simplex)`` returns a
    :class:`~torch.distributions.transforms.SoftmaxTransform` that simply
    exponentiates and normalizes its inputs; this is a cheap and mostly
    coordinate-wise operation appropriate for algorithms like SVI. In
    contrast, ``biject_to(constraints.simplex)`` returns a
    :class:`~torch.distributions.transforms.StickBreakingTransform` that
    bijects its input down to a one-fewer-dimensional space; this a more
    expensive less numerically stable transform but is needed for algorithms
    like HMC.

The ``biject_to`` and ``transform_to`` objects can be extended by user-defined
constraints and transforms using their ``.register()`` method either as a
function on singleton constraints::

    transform_to.register(my_constraint, my_transform)

or as a decorator on parameterized constraints::

    @transform_to.register(MyConstraintClass)
    def my_factory(constraint):
        assert isinstance(constraint, MyConstraintClass)
        return MyTransform(constraint.param1, constraint.param2)

You can create your own registry by creating a new :class:`ConstraintRegistry`
object.
é    )ÚconstraintsÚ
transforms)Ú_Number)ÚConstraintRegistryÚ	biject_toÚtransform_toc                   ó<   ^ • \ rS rSrSrU 4S jrSS jrS rSrU =r	$ )r   éP   z-
Registry to link constraints to transforms.
c                 ó0   >• 0 U l         [        TU ]	  5         g ©N)Ú	_registryÚsuperÚ__init__)ÚselfÚ	__class__s    €Úd/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributions/constraint_registry.pyr   ÚConstraintRegistry.__init__U   s   ø€ ØˆŒÜ‰ÑÕó    c                 ó  ^ ^• Uc  UU 4S j$ [        T[        R                  5      (       a  [        T5      m[        T[        5      (       a  [	        T[        R                  5      (       d  [        ST 35      eUT R                  T'   U$ )a–  
Registers a :class:`~torch.distributions.constraints.Constraint`
subclass in this registry. Usage::

    @my_registry.register(MyConstraintClass)
    def construct_transform(constraint):
        assert isinstance(constraint, MyConstraint)
        return MyTransform(constraint.arg_constraints)

Args:
    constraint (subclass of :class:`~torch.distributions.constraints.Constraint`):
        A subclass of :class:`~torch.distributions.constraints.Constraint`, or
        a singleton object of the desired class.
    factory (Callable): A callable that inputs a constraint object and returns
        a  :class:`~torch.distributions.transforms.Transform` object.
c                 ó(   >• TR                  TU 5      $ r   )Úregister)ÚfactoryÚ
constraintr   s    €€r   Ú<lambda>Ú-ConstraintRegistry.register.<locals>.<lambda>l   s   ø€  4§=¡=°¸WÔ#Er   zLExpected constraint to be either a Constraint subclass or instance, but got )Ú
isinstancer   Ú
ConstraintÚtypeÚ
issubclassÚ	TypeErrorr   ©r   r   r   s   `` r   r   ÚConstraintRegistry.registerY   sƒ   ù€ ð$ ‰?ÝEÐEô �j¤+×"8Ñ"8×9Ñ9Ü˜jÓ)ˆJä˜*¤d×+Ñ+´:Øœ×.Ñ.÷4
ñ 4
ô Ø^Ð_iÐ^jÐkóð ð &-ˆ�‰�zÑ"Øˆr   c                 ó¦   •  U R                   [        U5         nU" U5      $ ! [         a$    [        S[        U5      R                   S35      Sef = f)a   
Looks up a transform to constrained space, given a constraint object.
Usage::

    constraint = Normal.arg_constraints["scale"]
    scale = transform_to(constraint)(torch.zeros(1))  # constrained
    u = transform_to(constraint).inv(scale)  # unconstrained

Args:
    constraint (:class:`~torch.distributions.constraints.Constraint`):
        A constraint object.

Returns:
    A :class:`~torch.distributions.transforms.Transform` object.

Raises:
    `NotImplementedError` if no transform has been registered.
zCannot transform z constraintsN)r   r   ÚKeyErrorÚNotImplementedErrorÚ__name__r!   s      r   Ú__call__ÚConstraintRegistry.__call__|   s`   € ð(	Ø—n‘n¤T¨*Ó%5Ñ6ˆGñ
 �zÓ"Ð"øô	 ó 	Ü%Ø#¤D¨Ó$4×$=Ñ$=Ð#>¸lÐKóàðð	ús	   ‚" ¢.A)r   r   )
r&   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r'   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r   P   s   ø† ñõô!÷F#ð #r   r   c                 ó"   • [         R                  $ r   )r   Úidentity_transform©r   s    r   Ú_transform_to_realr2   ¢   s   € ô ×(Ñ(Ð(r   c                 ól   • [        U R                  5      n[        R                  " XR                  5      $ r   )r   Úbase_constraintr   ÚIndependentTransformÚreinterpreted_batch_ndims©r   Úbase_transforms     r   Ú_biject_to_independentr9   ¨   s.   € ä˜z×9Ñ9Ó:€NÜ×*Ò*Ø×<Ñ<óð r   c                 ól   • [        U R                  5      n[        R                  " XR                  5      $ r   )r   r4   r   r5   r6   r7   s     r   Ú_transform_to_independentr;   °   s.   € ä! *×"<Ñ"<Ó=€NÜ×*Ò*Ø×<Ñ<óð r   c                 ó,   • [         R                  " 5       $ r   )r   ÚExpTransformr1   s    r   Ú_transform_to_positiver>   ¸   s   € ô
 ×"Ò"Ó$Ð$r   c                 ó–   • [         R                  " [         R                  " 5       [         R                  " U R                  S5      /5      $ )Né   )r   ÚComposeTransformr=   ÚAffineTransformÚlower_boundr1   s    r   Ú_transform_to_greater_thanrD   À   s>   € ô
 ×&Ò&ä×#Ò#Ó%Ü×&Ò& z×'=Ñ'=¸qÓAð	
óð r   c                 ó–   • [         R                  " [         R                  " 5       [         R                  " U R                  S5      /5      $ )Néÿÿÿÿ)r   rA   r=   rB   Úupper_boundr1   s    r   Ú_transform_to_less_thanrH   Í   s>   € ô ×&Ò&ä×#Ò#Ó%Ü×&Ò& z×'=Ñ'=¸rÓBð	
óð r   c                 óÐ  • [        U R                  [        5      =(       a    U R                  S:H  n[        U R                  [        5      =(       a    U R                  S:H  nU(       a  U(       a  [        R
                  " 5       $ U R                  nU R                  U R                  -
  n[        R                  " [        R
                  " 5       [        R                  " X45      /5      $ )Nr   r@   )r   rC   r   rG   r   ÚSigmoidTransformrA   rB   )r   Ú
lower_is_0Ú
upper_is_1ÚlocÚscales        r   Ú_transform_to_intervalrO   Ø   s¸   € ô 	�:×)Ñ)¬7Ó3×S¸
×8NÑ8NÐRSÑ8Sð ô 	�:×)Ñ)¬7Ó3×S¸
×8NÑ8NÐRSÑ8Sð ö –jÜ×*Ò*Ó,Ð,à
×
 Ñ
 €CØ×"Ñ" Z×%;Ñ%;Ñ;€EÜ×&Ò&Ü	×	$Ò	$Ó	&¬
×(BÒ(BÀ3Ó(NÐOóð r   c                 ó,   • [         R                  " 5       $ r   )r   ÚStickBreakingTransformr1   s    r   Ú_biject_to_simplexrR   î   ó   € ä×,Ò,Ó.Ð.r   c                 ó,   • [         R                  " 5       $ r   )r   ÚSoftmaxTransformr1   s    r   Ú_transform_to_simplexrV   ó   s   € ä×&Ò&Ó(Ð(r   c                 ó,   • [         R                  " 5       $ r   )r   ÚLowerCholeskyTransformr1   s    r   Ú_transform_to_lower_choleskyrY   ù   rS   r   c                 ó,   • [         R                  " 5       $ r   )r   ÚPositiveDefiniteTransformr1   s    r   Ú_transform_to_positive_definiter\   þ   s   € ô ×/Ò/Ó1Ð1r   c                 ó,   • [         R                  " 5       $ r   )r   ÚCorrCholeskyTransformr1   s    r   Ú_transform_to_corr_choleskyr_     s   € ô ×+Ò+Ó-Ð-r   c                 ó¬   • [         R                  " U R                   Vs/ s H  n[        U5      PM     snU R                  U R
                  5      $ s  snf r   )r   ÚCatTransformÚcseqr   ÚdimÚlengths©r   Úcs     r   Ú_biject_to_catrg   
  s@   € ä×"Ò"Ø)ŸšÓ/š˜!Œ�1Ž™Ñ/°·±À×ASÑASóð ùÚ/ó   ŸAc                 ó¬   • [         R                  " U R                   Vs/ s H  n[        U5      PM     snU R                  U R
                  5      $ s  snf r   )r   ra   rb   r   rc   rd   re   s     r   Ú_transform_to_catrj     s@   € ä×"Ò"Ø",§/¢/Ó2¢/˜QŒ�aŽ¡/Ñ2°J·N±NÀJ×DVÑDVóð ùÚ2rh   c                 ó–   • [         R                  " U R                   Vs/ s H  n[        U5      PM     snU R                  5      $ s  snf r   )r   ÚStackTransformrb   r   rc   re   s     r   Ú_biject_to_stackrm     s8   € ä×$Ò$Ø)ŸšÓ/š˜!Œ�1Ž™Ñ/°·±óð ùÚ/ó   ŸAc                 ó–   • [         R                  " U R                   Vs/ s H  n[        U5      PM     snU R                  5      $ s  snf r   )r   rl   rb   r   rc   re   s     r   Ú_transform_to_stackrp     s8   € ä×$Ò$Ø",§/¢/Ó2¢/˜QŒ�aŽ¡/Ñ2°J·N±Nóð ùÚ2rn   N)+r,   Útorch.distributionsr   r   Útorch.typesr   Ú__all__r   r   r   r   Úrealr2   Úindependentr9   r;   ÚpositiveÚnonnegativer>   Úgreater_thanÚgreater_than_eqrD   Ú	less_thanrH   ÚintervalÚhalf_open_intervalrO   ÚsimplexrR   rV   Úlower_choleskyrY   Úpositive_definiteÚpositive_semidefiniter\   Úcorr_choleskyr_   Úcatrg   rj   Ústackrm   rp   © r   r   Ú<module>r…      sË  ðñA÷F 8Ý ò€÷F#ñ F#ñR Ó €	Ù!Ó#€ð ×Ñ�K×$Ñ$Ó%Ø×Ñ�{×'Ñ'Ó(ñ)ó )ó &ð)ð ×Ñ�K×+Ñ+Ó,ñó -ðð ×Ñ�{×.Ñ.Ó/ñó 0ðð ×Ñ�K×(Ñ(Ó)Ø
×Ñ�K×+Ñ+Ó,Ø×Ñ�{×+Ñ+Ó,Ø×Ñ�{×.Ñ.Ó/ñ%ó 0ó -ó -ó *ð%ð ×Ñ�K×,Ñ,Ó-Ø
×Ñ�K×/Ñ/Ó0Ø×Ñ�{×/Ñ/Ó0Ø×Ñ�{×2Ñ2Ó3ñó 4ó 1ó 1ó .ðð ×Ñ�K×)Ñ)Ó*Ø×Ñ�{×,Ñ,Ó-ñó .ó +ðð ×Ñ�K×(Ñ(Ó)Ø
×Ñ�K×2Ñ2Ó3Ø×Ñ�{×+Ñ+Ó,Ø×Ñ�{×5Ñ5Ó6ñó 7ó -ó 4ó *ðð$ ×Ñ�K×'Ñ'Ó(ñ/ó )ð/ð ×Ñ�{×*Ñ*Ó+ñ)ó ,ð)ð
 ×Ñ�{×1Ñ1Ó2ñ/ó 3ð/ð ×Ñ�{×4Ñ4Ó5Ø×Ñ�{×8Ñ8Ó9ñ2ó :ó 6ð2ð ×Ñ�K×-Ñ-Ó.Ø×Ñ�{×0Ñ0Ó1ñ.ó 2ó /ð.ð ×Ñ�K—O‘OÓ$ñó %ðð ×Ñ�{—‘Ó'ñó (ðð ×Ñ�K×%Ñ%Ó&ñó 'ðð ×Ñ�{×(Ñ(Ó)ñó *ñr   