Ë
    P/æjY(  ã                   ó„  — d Z ddlZddlmZ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j.                  «      ej                  ej0                  «      ej                  ej.                  «      ej                  ej0                  «      d„ «       «       «       «       Zej                  ej4                  «      d„ «       Zej                  ej4                  «      d„ «       Zej                  ej:                  «      d„ «       Zej                  ej>                  «      ej                  ej@                  «      d„ «       «       Z!ej                  ejD                  «      ej                  ejD                  «      d„ «       «       Z#ej                  ejH                  «      d„ «       Z%ej                  ejH                  «      d„ «       Z&ej                  ejN                  «      d„ «       Z(ej                  ejN                  «      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.
é    N)ÚconstraintsÚ
transforms)Ú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    €új/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/torch/distributions/constraint_registry.pyr   zConstraintRegistry.__init__V   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>m   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.registerZ   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)aq  
        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   Q   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_independentr1   ©   s0   € ä˜z×9Ñ9Ó:€NÜ×*Ñ*Ø˜
×<Ñ<óð r   c                 ól   — t        | j                  «      }t        j                  || j                  «      S r
   )r   r,   r   r-   r.   r/   s     r   Ú_transform_to_independentr3   ±   s0   € ä! *×"<Ñ"<Ó=€NÜ×*Ñ*Ø˜
×<Ñ<óð r   c                 ó*   — t        j                  «       S r
   )r   ÚExpTransformr)   s    r   Ú_transform_to_positiver6   ¹   s   € ô
 ×"Ñ"Ó$Ð$r   c                 ó�   — t        j                  t        j                  «       t        j                  | j                  d«      g«      S )Né   )r   ÚComposeTransformr5   Ú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   r9   r5   r:   Úupper_boundr)   s    r   Ú_transform_to_less_thanr@   Î   s>   € ô ×&Ñ&ä×#Ñ#Ó%Ü×&Ñ& z×'=Ñ'=¸rÓBð	
óð r   c                 óÊ  — t        | j                  t        j                  «      xr | j                  dk(  }t        | j                  t        j                  «      xr | j                  dk(  }|r|rt        j                  «       S | j                  }| j                  | j                  z
  }t        j                  t        j                  «       t        j                  ||«      g«      S )Nr   r8   )	r   r;   ÚnumbersÚNumberr?   r   ÚSigmoidTransformr9   r:   )r   Ú
lower_is_0Ú
upper_is_1ÚlocÚscales        r   Ú_transform_to_intervalrI   Ù   sÆ   € ô 	�:×)Ñ)¬7¯>©>Ó:ò 	(Ø×"Ñ" aÑ'ð ô
 	�:×)Ñ)¬7¯>©>Ó:ò 	(Ø×"Ñ" aÑ'ð ñ ‘jÜ×*Ñ*Ó,Ð,à
×
 Ñ
 €CØ×"Ñ" Z×%;Ñ%;Ñ;€EÜ×&Ñ&Ü	×	$Ñ	$Ó	&¬
×(BÑ(BÀ3ÈÓ(NÐOóð r   c                 ó*   — t        j                  «       S r
   )r   ÚStickBreakingTransformr)   s    r   Ú_biject_to_simplexrL   ñ   ó   € ä×,Ñ,Ó.Ð.r   c                 ó*   — t        j                  «       S r
   )r   ÚSoftmaxTransformr)   s    r   Ú_transform_to_simplexrP   ö   s   € ä×&Ñ&Ó(Ð(r   c                 ó*   — t        j                  «       S r
   )r   ÚLowerCholeskyTransformr)   s    r   Ú_transform_to_lower_choleskyrS   ü   rM   r   c                 ó*   — t        j                  «       S r
   )r   ÚPositiveDefiniteTransformr)   s    r   Ú_transform_to_positive_definiterV     s   € ô ×/Ñ/Ó1Ð1r   c                 ó*   — t        j                  «       S r
   )r   ÚCorrCholeskyTransformr)   s    r   Ú_transform_to_corr_choleskyrY     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_catra     s<   € ä×"Ñ"Ø)Ÿ™Ö/˜!Œ�1�Ò/°·±À×ASÑASóð ùÚ/ó   žAc                 ó¤   — t        j                  | j                  D �cg c]  }t        |«      ‘Œ c}| j                  | j
                  «      S c c}w r
   )r   r[   r\   r   r]   r^   r_   s     r   Ú_transform_to_catrd     s<   € ä×"Ñ"Ø",§/¡/Ö2˜QŒ�a�Ò2°J·N±NÀJ×DVÑDVóð ùÚ2rb   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_stackrg     s4   € ä×$Ñ$Ø)Ÿ™Ö/˜!Œ�1�Ò/°·±óð ùÚ/ó   žAc                 óŽ   — t        j                  | j                  D �cg c]  }t        |«      ‘Œ c}| j                  «      S c c}w r
   )r   rf   r\   r   r]   r_   s     r   Ú_transform_to_stackrj   "  s4   € ä×$Ñ$Ø",§/¡/Ö2˜QŒ�a�Ò2°J·N±Nóð ùÚ2rh   )*r%   rB   Útorch.distributionsr   r   Ú__all__r   r   r   r   Úrealr*   Úindependentr1   r3   ÚpositiveÚnonnegativer6   Úgreater_thanÚgreater_than_eqr<   Ú	less_thanr@   ÚintervalÚhalf_open_intervalrI   ÚsimplexrL   rP   Úlower_choleskyrS   Úpositive_definiteÚpositive_semidefiniterV   Úcorr_choleskyrY   Úcatra   rd   Ústackrg   rj   © r   r   ú<module>r~      sË  ðñAóF ç 7ò€÷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   