Ë
    f^(hB(  ã                   óˆ  — d Z ddlmZmZ ddlmZ g d¢Z G d„ d«      Z e«       Z e«       Z	ej                  ej                  «      e	j                  ej                  «      d„ «       «       Zej                  ej                  «      d„ «       Ze	j                  ej                  «      d	„ «       Zej                  ej                   «      ej                  ej"                  «      e	j                  ej                   «      e	j                  ej"                  «      d
„ «       «       «       «       Zej                  ej&                  «      ej                  ej(                  «      e	j                  ej&                  «      e	j                  ej(                  «      d„ «       «       «       «       Zej                  ej,                  «      e	j                  ej,                  «      d„ «       «       Zej                  ej0                  «      ej                  ej2                  «      e	j                  ej0                  «      e	j                  ej2                  «      d„ «       «       «       «       Zej                  ej6                  «      d„ «       Ze	j                  ej6                  «      d„ «       Ze	j                  ej<                  «      d„ «       Ze	j                  ej@                  «      e	j                  ejB                  «      d„ «       «       Z"ej                  ejF                  «      e	j                  ejF                  «      d„ «       «       Z$ej                  ejJ                  «      d„ «       Z&e	j                  ejJ                  «      d„ «       Z'ej                  ejP                  «      d„ «       Z)e	j                  ejP                  «      d„ «       Z*y)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                   ó0   ‡ — e Zd ZdZˆ fd„Zdd„Zd„ Zˆ xZS )r   z5
    Registry to link constraints to transforms.
    c                 ó0   •— i | _         t        ‰| �	  «        y ©N)Ú	_registryÚsuperÚ__init__)ÚselfÚ	__class__s    €úe/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/distributions/constraint_registry.pyr   zConstraintRegistry.__init__U   s   ø€ ØˆŒÜ‰ÑÕó    c                 óò   ‡ ‡— |€ˆˆ fd„S t        ‰t        j                  «      rt        ‰«      Št        ‰t        «      rt	        ‰t        j                  «      st        d‰› �«      ‚|‰ j                  ‰<   |S )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                 ó(   •— ‰j                  ‰| «      S r   )Úregister)ÚfactoryÚ
constraintr   s    €€r   ú<lambda>z-ConstraintRegistry.register.<locals>.<lambda>l   s   ø€  4§=¡=°¸WÓ#E€ r   zLExpected constraint to be either a Constraint subclass or instance, but got )Ú
isinstancer   Ú
ConstraintÚtypeÚ
issubclassÚ	TypeErrorr   ©r   r   r   s   `` r   r   zConstraintRegistry.registerY   sx   ù€ ð$ ˆ?ÜEÐEô �j¤+×"8Ñ"8Ô9Ü˜jÓ)ˆJä˜*¤dÔ+´:Øœ×.Ñ.ô4
ô Ø^Ð_iÐ^jÐkóð ð &-ˆ�‰�zÑ"Øˆr   c                 ó¤   — 	 | j                   t        |«         } ||«      S # t        $ r$ t        dt        |«      j                  › d�«      d‚w xY w)ah  
        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__zConstraintRegistry.__call__|   s`   € ð(	Ø—n‘n¤T¨*Ó%5Ñ6ˆGñ
 �zÓ"Ð"øô	 ò 	Ü%Ø#¤D¨Ó$4×$=Ñ$=Ð#>¸lÐKóàðð	ús	   ‚" ¢-Ar   )r"   Ú
__module__Ú__qualname__Ú__doc__r   r   r#   Ú__classcell__)r   s   @r   r   r   P   s   ø„ ñôó!öF#r   r   c                 ó"   — t         j                  S r   )r   Úidentity_transform©r   s    r   Ú_transform_to_realr+   ¢   s   € ô ×(Ñ(Ð(r   c                 ól   — t        | j                  «      }t        j                  || j                  «      S r   )r   Úbase_constraintr   ÚIndependentTransformÚreinterpreted_batch_ndims©r   Úbase_transforms     r   Ú_biject_to_independentr2   ¨   s0   € ä˜z×9Ñ9Ó:€NÜ×*Ñ*Ø˜
×<Ñ<óð r   c                 ól   — t        | j                  «      }t        j                  || j                  «      S r   )r   r-   r   r.   r/   r0   s     r   Ú_transform_to_independentr4   °   s0   € ä! *×"<Ñ"<Ó=€NÜ×*Ñ*Ø˜
×<Ñ<óð r   c                 ó*   — t        j                  «       S r   )r   ÚExpTransformr*   s    r   Ú_transform_to_positiver7   ¸   s   € ô
 ×"Ñ"Ó$Ð$r   c                 ó�   — t        j                  t        j                  «       t        j                  | j                  d«      g«      S )Né   )r   ÚComposeTransformr6   ÚAffineTransformÚlower_boundr*   s    r   Ú_transform_to_greater_thanr=   À   s>   € ô
 ×&Ñ&ä×#Ñ#Ó%Ü×&Ñ& z×'=Ñ'=¸qÓAð	
óð r   c                 ó�   — t        j                  t        j                  «       t        j                  | j                  d«      g«      S )Néÿÿÿÿ)r   r:   r6   r;   Úupper_boundr*   s    r   Ú_transform_to_less_thanrA   Í   s>   € ô ×&Ñ&ä×#Ñ#Ó%Ü×&Ñ& z×'=Ñ'=¸rÓBð	
óð r   c                 ó¢  — t        | j                  t        «      xr | j                  dk(  }t        | j                  t        «      xr | j                  dk(  }|r|rt	        j
                  «       S | j                  }| j                  | j                  z
  }t	        j                  t	        j
                  «       t	        j                  ||«      g«      S )Nr   r9   )r   r<   r   r@   r   ÚSigmoidTransformr:   r;   )r   Ú
lower_is_0Ú
upper_is_1ÚlocÚscales        r   Ú_transform_to_intervalrH   Ø   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                 ó*   — t        j                  «       S r   )r   ÚStickBreakingTransformr*   s    r   Ú_biject_to_simplexrK   î   ó   € ä×,Ñ,Ó.Ð.r   c                 ó*   — t        j                  «       S r   )r   ÚSoftmaxTransformr*   s    r   Ú_transform_to_simplexrO   ó   s   € ä×&Ñ&Ó(Ð(r   c                 ó*   — t        j                  «       S r   )r   ÚLowerCholeskyTransformr*   s    r   Ú_transform_to_lower_choleskyrR   ù   rL   r   c                 ó*   — t        j                  «       S r   )r   ÚPositiveDefiniteTransformr*   s    r   Ú_transform_to_positive_definiterU   þ   s   € ô ×/Ñ/Ó1Ð1r   c                 ó*   — t        j                  «       S r   )r   ÚCorrCholeskyTransformr*   s    r   Ú_transform_to_corr_choleskyrX     s   € ô ×+Ñ+Ó-Ð-r   c                 ó¤   — t        j                  | j                  D �cg c]  }t        |«      ‘Œ c}| j                  | j
                  «      S c c}w r   )r   ÚCatTransformÚcseqr   ÚdimÚlengths©r   Úcs     r   Ú_biject_to_catr`   
  s<   € ä×"Ñ"Ø)Ÿ™Ö/˜!Œ�1�Ò/°·±À×ASÑASóð ùÚ/ó   žAc                 ó¤   — t        j                  | j                  D �cg c]  }t        |«      ‘Œ c}| j                  | j
                  «      S c c}w r   )r   rZ   r[   r   r\   r]   r^   s     r   Ú_transform_to_catrc     s<   € ä×"Ñ"Ø",§/¡/Ö2˜QŒ�a�Ò2°J·N±NÀJ×DVÑDVóð ùÚ2ra   c                 óŽ   — t        j                  | j                  D �cg c]  }t        |«      ‘Œ c}| j                  «      S c c}w r   )r   ÚStackTransformr[   r   r\   r^   s     r   Ú_biject_to_stackrf     s4   € ä×$Ñ$Ø)Ÿ™Ö/˜!Œ�1�Ò/°·±óð ùÚ/ó   žAc                 óŽ   — t        j                  | j                  D �cg c]  }t        |«      ‘Œ c}| j                  «      S c c}w r   )r   re   r[   r   r\   r^   s     r   Ú_transform_to_stackri     s4   € ä×$Ñ$Ø",§/¡/Ö2˜QŒ�a�Ò2°J·N±Nóð ùÚ2rg   N)+r&   Útorch.distributionsr   r   Útorch.typesr   Ú__all__r   r   r   r   Úrealr+   Úindependentr2   r4   ÚpositiveÚnonnegativer7   Úgreater_thanÚgreater_than_eqr=   Ú	less_thanrA   ÚintervalÚhalf_open_intervalrH   ÚsimplexrK   rO   Úlower_choleskyrR   Úpositive_definiteÚpositive_semidefiniterU   Úcorr_choleskyrX   Úcatr`   rc   Ústackrf   ri   © 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   