+
    åûj2’  ã                   óÔ   € R t ^ RIHt ^ RIHtHtHtHt ^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHt ^ RIHtHtHtHtHtHtHt ^ RIHt  ! R	 R
]	P2                  4      tR R ltRR R lltR# )a—  Quaternions in ``(w, x, y, z)`` order: Hamilton product, slerp, averaging and rotation conversions.

A quaternion is stored real part first, with shape ``(*, 4)``, and ``q1 * q2`` is the Hamilton product, so
``(q1 * q2).matrix()`` is ``q1.matrix() @ q2.matrix()``: the right operand acts first, as for the Lie groups of
``kornia.geometry.liegroup``. ``q`` and ``-q`` are the same rotation. Nothing normalises the stored data; the
conversions to a rotation read only its direction :math:`q / |q|`, within the limits stated on :class:`Quaternion`.

Which function to use:

- Quaternions as objects that multiply, invert, interpolate (``slerp``) and convert to and from rotation matrices,
  rotation vectors and Euler angles: :class:`Quaternion`.
- The mean rotation of many quaternions, optionally weighted, whatever their signs: :func:`average_quaternions`.
- The same conversions on plain tensors, without an object:
  :func:`~kornia.geometry.conversions.quaternion_to_rotation_matrix` and
  :func:`~kornia.geometry.conversions.quaternion_to_axis_angle` from ``(*, 4)`` quaternions to ``(*, 3, 3)``
  matrices and ``(*, 3)`` rotation vectors, and :func:`~kornia.geometry.conversions.rotation_matrix_to_quaternion`
  and :func:`~kornia.geometry.conversions.axis_angle_to_quaternion` back;
  :func:`~kornia.geometry.conversions.euler_from_quaternion` and
  :func:`~kornia.geometry.conversions.quaternion_from_euler` for roll, pitch and yaw, with the quaternion as four
  separate ``w``, ``x``, ``y``, ``z`` tensors.
- A rotation that acts on points, with ``exp``, ``log`` and Jacobians: :class:`~kornia.geometry.liegroup.So3`; with a
  translation: :class:`~kornia.geometry.liegroup.Se3`.
)Úpi)ÚAnyÚOptionalÚTupleÚUnionN)Únn)ÚKORNIA_CHECK_TYPE)Ú_deepcopy_module_stateÚ_symmetric_eigenvector)Úaxis_angle_to_quaternionÚeuler_from_quaternionÚnormalize_quaternionÚquaternion_from_eulerÚquaternion_to_axis_angleÚquaternion_to_rotation_matrixÚrotation_matrix_to_quaternion)Úbatched_dot_productc                   ó  a a€ ] tR t^Bt oRt]tV3R lV 3R lltV3R lR ltV3R lR lt	V3R lR	 lt
V3R
 lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R  lR! ltV3R" lR# lt]V3R$ lR% l4       t]V3R& lR' l4       t]V3R( lR) l4       t]V3R* lR+ l4       t]V3R, lR- l4       t]V3R. lR/ l4       t]V3R0 lR1 l4       t]V3R2 lR3 l4       t ]V3R4 lR5 l4       t!]V3R6 lR7 l4       t"]V3R8 lR9 l4       t#]V3R: lR; l4       t$V3R< lR= lt%]&R\V3R> lR? ll4       t']&V3R@ lRA l4       t(V3RB lRC lt)]&V3RD lRE l4       t*V3RF lRG lt+]&R]V3RH lRI ll4       t,]&V3RJ lRK l4       t-]&R]V3RL lRM ll4       t.V3RN lRO lt/R\V3RP lRQ llt0V3RR lRS lt1V3RT lRU lt2V3RV lRW lt3V3RX lRY lt4V3RZ lt5R[t6Vt7V ;t8# )^Ú
Quaterniona{  Represent (w, x, y, z) quaternions: Hamilton product, slerp and rotation conversions.

``q = Quaternion(data)`` wraps a ``(*, 4)`` tensor of quaternions, real part first, without copying it;
:meth:`from_axis_angle`, :meth:`from_matrix`, :meth:`from_euler`, :meth:`identity` and :meth:`random` build one.
``q1 * q2`` is the Hamilton product, ``q.inv()`` the inverse and ``q0.slerp(q1, t)`` the interpolation along the
shorter arc; ``q.matrix()`` returns the ``(*, 3, 3)`` rotation matrices and ``q.to_axis_angle()`` the ``(*, 3)``
rotation vectors of the direction :math:`q / |q|`. A quaternion does not act on points: for a rotation that maps
points and has ``exp``, ``log`` and Jacobians, use :class:`~kornia.geometry.liegroup.So3`; for the same
conversions on plain tensors, the functions of ``kornia.geometry.conversions``.

The general definition of a quaternion is given by:

.. math::

    Q = a + b \cdot \mathbf{i} + c \cdot \mathbf{j} + d \cdot \mathbf{k}

A unit quaternion represents a rotation in 3D; see https://en.wikipedia.org/wiki/Quaternion. The last axis of
``data`` holds:

.. math::

    Q = \begin{bmatrix} q_w & q_x & q_y & q_z \end{bmatrix}

Convention:
    - ``data`` is ``(w, x, y, z)``, real part first, with shape ``(*, 4)``; only the last axis is checked.
      Other libraries' orders, such as scipy's default ``(x, y, z, w)``, are mapped on
      :ref:`Rotations and rigid motions <rotation-conventions>`.
    - ``*`` between quaternions is the Hamilton product, so ``(q1 * q2).matrix()`` is
      ``q1.matrix() @ q2.matrix()``, ``q1 / q2`` is ``q1 * q2.inv()``, and ``q`` and ``-q`` are the same rotation.
      A batch multiplies with a batch of the same size, a batch of one or an unbatched quaternion.
      A float or tensor operand of ``+``, ``-``, ``*`` or ``/`` is the real quaternion ``[s, 0, 0, 0]``, and a
      tensor of the shape of ``q.w`` holds one such scalar per quaternion of the batch.
    - Nothing normalises the stored data or the results of ``*``, ``**`` and ``inv()``. ``matrix()``,
      ``to_axis_angle()``, ``to_euler()``, ``polar_angle`` and ``slerp`` read only the direction of ``q``:
      rescaling ``q`` by a positive factor changes their result by roundoff only, as long as its squared
      components stay within the range of the dtype and its norm stays above ``1e-12``.
    - At construction, plain tensor data is registered as a persistent buffer; an explicit ``nn.Parameter``
      remains a parameter. Both are saved and restored by ``state_dict()`` and ``load_state_dict()`` and follow
      an enclosing module's device and dtype conversions. Construction preserves the input tensor and its
      autograd history. ``Quaternion.to()`` returns a new quaternion; enclosing module conversions update the
      existing module's state.
    - ``copy.deepcopy`` holds data with autograd history as a new leaf that keeps ``requires_grad``, still a
      buffer, like ``torch.save`` and ``torch.load``: no gradient flows from the copy back to the original's
      inputs. torch cannot deep-copy such a tensor itself.
    - Below a norm of ``1e-12``, ``matrix()`` and ``slerp`` read ``q`` through the norm floor of
      :func:`~kornia.geometry.conversions.normalize_quaternion`, so they do not give the rotation of its
      direction, and the zero quaternion's ``matrix()`` is the identity.

See Also:
    - :class:`~kornia.geometry.liegroup.So3`: the rotation group stored as a quaternion, which rotates points
      and adds ``exp``, ``log`` and Jacobians.
    - :func:`average_quaternions`: the mean rotation of many quaternions, instead of interpolating two.
    - :func:`~kornia.geometry.conversions.quaternion_to_rotation_matrix`,
      :func:`~kornia.geometry.conversions.rotation_matrix_to_quaternion`: :meth:`matrix` and :meth:`from_matrix`
      on plain ``(*, 4)`` and ``(*, 3, 3)`` tensors.
    - :func:`~kornia.geometry.conversions.quaternion_to_axis_angle`,
      :func:`~kornia.geometry.conversions.axis_angle_to_quaternion`: :meth:`to_axis_angle` and
      :meth:`from_axis_angle` on plain ``(*, 4)`` and ``(*, 3)`` tensors.
    - :func:`~kornia.geometry.conversions.euler_from_quaternion`,
      :func:`~kornia.geometry.conversions.quaternion_from_euler`: :meth:`to_euler` and :meth:`from_euler` on plain
      tensors, with the quaternion as four separate ``w``, ``x``, ``y``, ``z`` tensors.

Example:
    >>> q = Quaternion.identity(batch_size=4)
    >>> q.data
    tensor([[1., 0., 0., 0.],
            [1., 0., 0., 0.],
            [1., 0., 0., 0.],
            [1., 0., 0., 0.]])
    >>> q.real
    tensor([1., 1., 1., 1.])
    >>> q.vec
    tensor([[0., 0., 0.],
            [0., 0., 0.],
            [0., 0., 0.],
            [0., 0., 0.]])

c                ób   <€ V ^8„  d   QhRS[ S[P                  S[P                  3,          RR/# )é   ÚdataÚreturnN©r   ÚtorchÚTensorr   Ú	Parameter)ÚformatÚ__classdict__s   "€ÚVC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\quaternion.pyÚ__annotate__ÚQuaternion.__annotate__—   s-   ø€ ÷ 0ñ 0™U¡5§<¡<±·±Ð#=Õ>ð 0À4ñ 0ó    c                óº  <€ \         SV `  4        \        V\        P                  \
        P                  34      '       g   \        R\        V4       24      hVP                  ^ 8X  g   VP                  R,          ^8w  d"   \        R\        VP                  4       24      h\        V\
        P                  4      '       d	   Wn        R# V P                  RV4       R# )aH  Construct a quaternion from torch.Tensor or parameter data.

Args:
    data: torch.Tensor or parameter containing the quaternion data with the shape of ``(*, 4)``.
        Stored without copying as a persistent buffer, or as a parameter if already an ``nn.Parameter``.

Example:
    >>> # Create with torch.tensor(no gradients tracked by default)
    >>> data = torch.tensor([1., 0., 0., 0.])
    >>> q1 = Quaternion(data)
    >>> # Create with parameter (gradients tracked)
    >>> param_data = torch.nn.Parameter(torch.tensor([1., 0., 0., 0.]))
    >>> q2 = Quaternion(param_data)

z+Expected torch.Tensor or nn.Parameter, got z:Quaternion input must have last dimension == 4. Got shape Ú_dataNéÿÿÿÿ)ÚsuperÚ__init__Ú
isinstancer   r   r   r   Ú	TypeErrorÚtypeÚndimÚshapeÚ
ValueErrorÚtupler$   Úregister_buffer)Úselfr   Ú	__class__s   &&€r   r'   ÚQuaternion.__init__—   s¤   ø€ ô  	‰ÑÔä˜$¤§¡¬r¯|©|Ð <×=Ò=ÜÐIÌ$ÈtË*ÈÐVÓWÐWð �9‰9˜Œ>˜TŸZ™Z¨�^¨qÔ0ÜÐYÔZ_Ð`d×`jÑ`jÓZkÐYlÐmÓnÐnÜ�dœBŸL™L×)Ò)ØŽJà× Ñ  ¨$Ö/r"   c                ó*   <€ V ^8„  d   QhRS[ RS[ RR/# )r   ÚargsÚkwargsr   r   )r   )r   r   s   "€r   r    r!   ´   s"   ø€ ÷ 
:ñ 
:™ð 
:¡sð 
:¨|ñ 
:r"   c                óL   € \        V P                  P                  ! V/ VB 4      # )zÐMove and/or cast the quaternion data.

Args:
    *args: Arguments to pass to torch.Tensor.to()
    **kwargs: Keyword arguments to pass to torch.Tensor.to()

Returns:
    A new Quaternion with converted data.
)r   r$   Úto)r0   r4   r5   s   &*,r   r7   ÚQuaternion.to´   s!   € ô ˜$Ÿ*™*Ÿ-š-¨Ð8°Ñ8Ó9Ð9r"   c                óN   <€ V ^8„  d   QhRS[ S[P                  S[3,          RR/# )r   Úvaluer   r   ©r   r   r   Úfloat)r   r   s   "€r   r    r!   À   s)   ø€ ÷ &,ñ &,©5±·±¹uÐ1DÕ+Eð &,È,ñ &,r"   c                ó@  € \        V\        \        34      '       dB   \        P                  ! WP
                  P                  V P
                  P                  R7      pM[\        V\        P                  4      '       d<   VP                  V P
                  P                  V P
                  P                  R7      p \        P                  ! V P                  P                  VP                  4      pT P                  P                  T4      TP                  T4      ,           pTP!                  4       ^ 8X  d   TP#                  T4      pM \        P$                  ! YP                  4      p\        P&                  ! T4      P)                  R4      P                  ! . TP                  O^N5!  p\        P*                  ! TP)                  R4      T.RR7      p\-        T4      #   \         d6   p\        RT P                  P                   RTP                   24      ThRp?ii ; i)a)  Convert a scalar, torch.Tensor, or numeric value to a scalar quaternion.

A scalar quaternion has the form [real, 0, 0, 0] where real is the input value.

Args:
    value: The scalar, torch.Tensor, or numeric value to convert.

Returns:
    A Quaternion object representing the scalar quaternion.
©ÚdeviceÚdtypezCannot broadcast shapes ú and N©Údimr%   )r(   Úintr<   r   Útensorr   r?   r@   r   r7   Úbroadcast_shapesÚrealr,   ÚRuntimeErrorr-   ÚexpandrC   Ú	expand_asÚbroadcast_toÚ
zeros_likeÚ	unsqueezeÚcatr   )r0   r:   Útarget_shapeÚeÚbroadcastedÚexpanded_valueÚzerosÚscalar_quat_datas   &&      r   Ú_to_scalar_quaternionÚ Quaternion._to_scalar_quaternionÀ   sŽ  € ô �eœc¤5˜\×*Ò*Ü—L’L ¯y©y×/?Ñ/?ÀtÇyÁyÇÁÔW‰EÜ˜œuŸ|™|×,Ò,Ø—H‘H D§I¡I×$4Ñ$4¸D¿I¹I¿O¹O�HÓLˆEð	dÜ ×1Ò1°$·)±)·/±/À5Ç;Á;ÓOˆLð —i‘i×&Ñ& |Ó4°u·|±|ÀLÓ7QÕQˆð �9‰9‹;˜!Ôà"Ÿ_™_¨[Ó9‰Nô #×/Ò/°×7HÑ7HÓIˆNô × Ò  Ó0×:Ñ:¸2Ó>×EÒEÐ_À~×G[ÑG[Ð_Ð]^Ó_ˆô !Ÿ9š9 n×&>Ñ&>¸rÓ&BÀEÐ%JÐPRÔSÐäÐ*Ó+Ð+øô' ô 	dÜÐ7¸¿	¹	¿¹Ð7HÈÈeÏkÉkÈ]Ð[Ó\ÐbcÐcûð	dús   Â:5G ÇHÇ(0HÈHc                ó    <€ V ^8„  d   QhRS[ /# ©r   r   )Ústr)r   r   s   "€r   r    r!   è   s   ø€ ÷ ñ ™#ñ r"   c                ó   € V P                    # ©N©r   ©r0   s   &r   Ú__repr__ÚQuaternion.__repr__è   s   € Ø—)‘)�Ðr"   c                ó:   <€ V ^8„  d   QhRS[ S[S[3,          RR/# )r   Úidxr   r   )r   rD   Úslice)r   r   s   "€r   r    r!   ë   s$   ø€ ÷ *ñ *™u¡S©% ZÕ0ð *°\ñ *r"   c                ó:   € \        V P                  V,          4      # r[   ©r   r   )r0   ra   s   &&r   Ú__getitem__ÚQuaternion.__getitem__ë   s   € Ü˜$Ÿ)™) C�.Ó)Ð)r"   c                ó   <€ V ^8„  d   QhRR/# ©r   r   r   © )r   r   s   "€r   r    r!   î   s   ø€ ÷ 	&ñ 	&˜ñ 	&r"   c                ó.   € \        V P                  ) 4      # )z‰Inverts the sign of the quaternion data.

Example:
    >>> q = Quaternion.identity()
    >>> (-q).data
    tensor([-1., -0., -0., -0.])

rd   r]   s   &r   Ú__neg__ÚQuaternion.__neg__î   s   € ô ˜4Ÿ9™9˜*Ó%Ð%r"   c                óP   <€ V ^8„  d   QhRS[ RS[P                  S[3,          RR/# ©r   Úrightr   r   r;   )r   r   s   "€r   r    r!   ù   s+   ø€ ÷ 7ñ 7™U <±·±¹uÐ#DÕEð 7È,ñ 7r"   c                óè   € \        V\        4      '       d'   \        V P                  VP                  ,           4      # V P                  V4      p\        V P                  VP                  ,           4      # )a  Add a given quaternion, scalar, or torch.Tensor.

Args:
    right: the quaternion, scalar, or torch.Tensor to add.

Example:
    >>> q1 = Quaternion.identity()
    >>> q2 = Quaternion(torch.tensor([2., 0., 1., 1.]))
    >>> q3 = q1 + q2
    >>> q3.data
    tensor([3., 0., 1., 1.])

)r(   r   r   rU   )r0   ro   Ú
right_quats   && r   Ú__add__ÚQuaternion.__add__ù   sQ   € ô �eœZ×(Ò(Ü˜dŸi™i¨%¯*©*Õ4Ó5Ð5Ø×/Ñ/°Ó6ˆ
Ü˜$Ÿ)™) j§o¡oÕ5Ó6Ð6r"   c                óP   <€ V ^8„  d   QhRS[ RS[P                  S[3,          RR/# rn   r;   )r   r   s   "€r   r    r!     s+   ø€ ÷ 'ñ '™U <±·±¹uÐ#DÕEð 'È,ñ 'r"   c                óD  € \        V\        4      '       d'   \        V P                  VP                  ,
          4      # V P                  V4      pV P                  VP                  ,
          p\        V\        P
                  4      '       d   VP                  p\        V4      # )a%  Subtract a given quaternion, scalar, or torch.Tensor.

Args:
    right: the quaternion, scalar, or torch.Tensor to subtract.

Example:
    >>> q1 = Quaternion(torch.tensor([2., 0., 1., 1.]))
    >>> q2 = Quaternion.identity()
    >>> q3 = q1 - q2
    >>> q3.data
    tensor([1., 0., 1., 1.])

)r(   r   r   rU   r   r   )r0   ro   rq   Úresult_datas   &&  r   Ú__sub__ÚQuaternion.__sub__  sr   € ô �eœZ×(Ò(Ü˜dŸi™i¨%¯*©*Õ4Ó5Ð5Ø×/Ñ/°Ó6ˆ
à—i‘i *§/¡/Õ1ˆÜ�k¤2§<¡<×0Ò0Ø%×*Ñ*ˆKÜ˜+Ó&Ð&r"   c                óP   <€ V ^8„  d   QhRS[ RS[P                  S[3,          RR/# rn   r;   )r   r   s   "€r   r    r!   #  s/   ø€ ÷ Jñ J™U <±·±¹uÐ#DÕEð JÈ,ñ Jr"   c                óx   € \        V\        4      '       d   \        W4      # \        W P                  V4      4      # r[   )r(   r   Ú_hamilton_productrU   ©r0   ro   s   &&r   Ú__mul__ÚQuaternion.__mul__#  s0   € Ü�eœZ×(Ò(Ü$ TÓ1Ð1Ü  ×'AÑ'AÀ%Ó'HÓIÐIr"   c                óN   <€ V ^8„  d   QhRS[ S[P                  S[3,          RR/# ©r   Úleftr   r   r;   )r   r   s   "€r   r    r!   (  s-   ø€ ÷ Iñ I™U¡5§<¡<±Ð#6Õ7ð I¸Lñ Ir"   c                ó8   € \        V P                  V4      V 4      # )zJRight multiplication (left * self) where left is a scalar or torch.Tensor.)r{   rU   ©r0   r�   s   &&r   Ú__rmul__ÚQuaternion.__rmul__(  s   € ä  ×!;Ñ!;¸DÓ!AÀ4ÓHÐHr"   c                óP   <€ V ^8„  d   QhRS[ S[P                  RS[3,          RR/# rn   r;   )r   r   s   "€r   r    r!   ,  s+   ø€ ÷ 'ñ '™U¡5§<¡<°¹uÐ#DÕEð 'È,ñ 'r"   c                ó2  € \        V\        4      '       d   WP                  4       ,          # \        V\        \        34      '       dB   \
        P                  ! WP                  P                  V P                  P                  R 7      pM;VP                  V P                  P                  V P                  P                  R 7      pVP                  4       ^ 8X  dL   VP                  V P                  R,          4      P                  R4      P                  V P                  4      pM*VP                  R4      P                  V P                  4      pV P                  V,          p\        V\        P                  4      '       d   VP                  p\        V4      # )r>   ©.é    r%   )r(   r   ÚinvrD   r<   r   rE   r   r?   r@   r7   rC   rJ   rM   r   r   )r0   ro   Úright_tensorÚdivisorrv   s   &&   r   Ú__div__ÚQuaternion.__div__,  s  € Ü�eœZ×(Ò(ØŸ)™)›+Õ%Ð%ä�eœc¤5˜\×*Ò*Ü Ÿ<š<¨·i±i×6FÑ6FÈdÏiÉiÏoÉoÔ^‰Là Ÿ8™8¨4¯9©9×+;Ñ+;À4Ç9Á9Ç?Á?˜8ÓSˆLð ×ÑÓ Ô"Ø"×,Ñ,¨T¯Y©Y°vÕ->Ó?×IÑIÈ"ÓM×WÑWÐX\×XaÑXaÓb‰Gð #×,Ñ,¨RÓ0×:Ñ:¸4¿9¹9ÓEˆGð —i‘i 'Õ)ˆÜ�k¤2§<¡<×0Ò0Ø%×*Ñ*ˆKÜ˜+Ó&Ð&r"   c                óP   <€ V ^8„  d   QhRS[ S[P                  RS[3,          RR/# rn   r;   )r   r   s   "€r   r    r!   B  s+   ø€ ÷ #ñ #¡¡u§|¡|°\Á5Ð'HÕ!Ið #Èlñ #r"   c                ó$   € V P                  V4      # r[   )r�   r|   s   &&r   Ú__truediv__ÚQuaternion.__truediv__B  s   € Ø�|‰|˜EÓ"Ð"r"   c                óN   <€ V ^8„  d   QhRS[ S[P                  S[3,          RR/# r€   r;   )r   r   s   "€r   r    r!   E  ó)   ø€ ÷  ñ  ™U¡5§<¡<±Ð#6Õ7ð  ¸Lñ  r"   c                ó4   € V P                  V4      pW ,           # )zDRight addition (left + self) where left is a scalar or torch.Tensor.©rU   ©r0   r�   Ú	left_quats   && r   Ú__radd__ÚQuaternion.__radd__E  ó   € à×.Ñ.¨tÓ4ˆ	ØÕÐr"   c                óN   <€ V ^8„  d   QhRS[ S[P                  S[3,          RR/# r€   r;   )r   r   s   "€r   r    r!   J  r”   r"   c                ó4   € V P                  V4      pW ,
          # )zGRight subtraction (left - self) where left is a scalar or torch.Tensor.r–   r—   s   && r   Ú__rsub__ÚQuaternion.__rsub__J  r›   r"   c                óN   <€ V ^8„  d   QhRS[ S[P                  S[3,          RR/# r€   r;   )r   r   s   "€r   r    r!   O  s)   ø€ ÷  ñ  ¡¡u§|¡|±UÐ':Õ!;ð  Àñ  r"   c                ó4   € V P                  V4      pW ,          # ©zDRight division (left / self) where left is a scalar or torch.Tensor.r–   r—   s   && r   Ú__rtruediv__ÚQuaternion.__rtruediv__O  r›   r"   c                óN   <€ V ^8„  d   QhRS[ S[P                  S[3,          RR/# r€   r;   )r   r   s   "€r   r    r!   T  s)   ø€ ÷ 'ñ '™U¡5§<¡<±Ð#6Õ7ð '¸Lñ 'r"   c                ó$   € V P                  V4      # r¢   )r£   rƒ   s   &&r   Ú__rdiv__ÚQuaternion.__rdiv__T  s   € à× Ñ  Ó&Ð&r"   c                óN   <€ V ^8„  d   QhRS[ S[S[P                  3,          RR/# )r   Útr   r   ©r   r<   r   r   )r   r   s   "€r   r    r!   X  s-   ø€ ÷ )Kñ )K™™u¡e§l¡lÐ2Õ3ð )K¸ñ )Kr"   c                ó¾  € V P                   R,          pV P                  P                  RRR7      p\        P                  ! W24      pV^ 8H  p\        P
                  ! V\        P                  ! V4      V4      p\        P
                  ! V^ 8H  \        P                  ! V4      V4      p\        P
                  ! WQW,          P                  4       ,          V,          W,          P                  4       V,          4      pV P                  RR7      V,          p	W˜,          V P                  ,          p
\        P                  ! WP                  V	P                  R7      pVP                  4       P                  4       pRRVP                  R4      ,          ,
          \        P                  ! \        W¼,
          ,          4      ,          pWR^ 8  ,          V^ 8g  ,          pV
R	,          p\        P                   ! \        P
                  ! WïW�,          ,           V4      V
R
,          3R4      p
\#        \        P                   ! W‘V,          P                  4       ,          V
3R4      4      # )a$  Return the power of a quaternion raised to exponent t.

For :math:`q = \|q\| (\cos\theta + n \sin\theta)` this is
:math:`q^t = \|q\|^t (\cos t\theta + n \sin t\theta)`, so ``q**2 == q * q`` and ``q**-1 == q.inv()``.

On the negative real axis (``w < 0`` and a zero vector part) :math:`\theta = \pi` and the axis :math:`n` is
undefined: for a non-integer ``t`` every unit vector gives a valid power. This method takes :math:`n = e_x`
there, so ``q**t`` has norm :math:`\|q\|^t` and angle :math:`t\pi`, ``(q**0.5)**2 == q``, and the result is
the limit from the ``+x`` side of the axis. An integer ``t`` keeps a zero vector part.

Args:
    t: raised exponent, a float or a tensor that broadcasts against ``(..., 1)``.

Example:
    >>> q = Quaternion(torch.tensor([1., .5, 0., 0.]))
    >>> q_pow = q**2

T)rC   Úkeepdim)r­   )r@   r?   ç      ð?g       @©.Nr%   ).:Né   N©.:r°   NN)ÚscalarÚvecÚnormr   Úatan2ÚwhereÚ	ones_likeÚcosÚsinÚ	as_tensorr@   r?   ÚdetachÚroundÚ	remainderr   rN   r   )r0   rª   ÚwÚvec_normÚthetaÚis_realÚsafe_vec_normÚsafe_wÚ	sin_ratioÚscaler³   Út_ÚkÚsin_t_piÚon_cutÚvec_xs   &&              r   Ú__pow__ÚQuaternion.__pow__X  s¢  € ð& �K‰K˜	Õ"ˆØ—8‘8—=‘= R°�=Ó6ˆÜ—’˜HÓ(ˆð ˜a‘-ˆÜŸš G¬U¯_ª_¸XÓ-FÈÓQˆÜ—’˜Q !™V¤U§_¢_°QÓ%7¸Ó;ˆÜ—K’K ¨a­i¯_©_Ó->Õ)>ÀÕ)GÈ!Í)ÏÉÓIZÐ]jÕIjÓkˆ	Ø—	‘	 $�	Ó'¨1Õ,ˆØÕ $§(¡(Õ*ˆô �_Š_˜Q§k¡k¸%¿,¹,ÔGˆØ�I‰I‹K×ÑÓˆØ˜# §¡¨CÓ 0Õ0Õ0´E·I²I¼bÀBÅF½mÓ4LÕLˆØ ™EÕ" h°!¡mÕ4ˆØ�G•ˆÜ�iŠiœŸš V°UÕ5EÕ-EÀuÓMÈsÐSZÍ|Ð\Ð^`ÓaˆÜœ%Ÿ)š) U°%­i¯_©_Ó->Õ%>ÀÐ$DÀbÓIÓJÐJr"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   ©r   r   )r   r   s   "€r   r    r!   „  s   ø€ ÷ ñ ‘e—l‘lñ r"   c                ó   € V P                   # )z1Return the underlying data with shape ``(*, 4)``.©r$   r]   s   &r   r   ÚQuaternion.dataƒ  s   € ð �z‰zÐr"   c                óŽ   <€ V ^8„  d   QhRS[ S[P                  S[P                  S[P                  S[P                  3,          /# rX   ©r   r   r   )r   r   s   "€r   r    r!   ‰  s2   ø€ ÷ .ñ .™™eŸl™l©E¯L©L¹%¿,¹,ÉÏÉÐTÕUñ .r"   c                ó^   € V P                   V P                  V P                  V P                  3# )z>Return a tuple with the underlying coefficients in WXYZ order.)r¾   ÚxÚyÚzr]   s   &r   ÚcoeffsÚQuaternion.coeffsˆ  s#   € ð �v‰v�t—v‘v˜tŸv™v t§v¡vÐ-Ð-r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   Ž  s   ø€ ÷ ñ ‘e—l‘lñ r"   c                ó   € V P                   # )zgReturn the real part with shape ``(*,)``.

Alias for :attr:`~kornia.geometry.quaternion.Quaternion.w`.
)r¾   r]   s   &r   rG   ÚQuaternion.real�  s   € ð �v‰vˆr"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   –  s   ø€ ÷ "ñ "‘U—\‘\ñ "r"   c                ó(   € V P                   R,          # )z@Return the vector with the imaginary part with shape ``(*, 3)``.r±   r\   r]   s   &r   r³   ÚQuaternion.vec•  s   € ð �y‰y˜Õ!Ð!r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   ›  s   ø€ ÷ ñ ‘5—<‘<ñ r"   c                ó   € V P                   # )zrReturn the underlying data with shape ``(*, 4)``.

Alias for :attr:`~kornia.geometry.quaternion.Quaternion.data`.
r\   r]   s   &r   ÚqÚQuaternion.qš  ó   € ð �y‰yÐr"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   £  s   ø€ ÷ ñ ™Ÿ™ñ r"   c                ó   € V P                   # )zpReturn a scalar with the real with shape ``(*,)``.

Alias for :attr:`~kornia.geometry.quaternion.Quaternion.w`.
)rG   r]   s   &r   r²   ÚQuaternion.scalar¢  rä   r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   «  ó   ø€ ÷ !ñ !‘5—<‘<ñ !r"   c                ó(   € V P                   R,          # )z+Return the :math:`q_w` with shape ``(*,)``.rˆ   r\   r]   s   &r   r¾   ÚQuaternion.wª  ó   € ð �y‰y˜Õ Ð r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   °  ré   r"   c                ó(   € V P                   R,          # )z+Return the :math:`q_x` with shape ``(*,)``.).r°   r\   r]   s   &r   rÕ   ÚQuaternion.x¯  rì   r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   µ  ré   r"   c                ó(   € V P                   R,          # )z+Return the :math:`q_y` with shape ``(*,)``.).r   r\   r]   s   &r   rÖ   ÚQuaternion.y´  rì   r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   º  ré   r"   c                ó(   € V P                   R,          # )z+Return the :math:`q_z` with shape ``(*,)``.).é   r\   r]   s   &r   r×   ÚQuaternion.z¹  rì   r"   c                ó4   <€ V ^8„  d   QhRS[ S[R3,          /# )r   r   .)r   rD   )r   r   s   "€r   r    r!   ¿  s   ø€ ÷ &ñ &‘u™S #˜X•ñ &r"   c                ó@   € \        V P                  P                  4      # )z4Return the shape of the underlying data, ``(*, 4)``.)r.   r   r,   r]   s   &r   r,   ÚQuaternion.shape¾  s   € ô �T—Y‘Y—_‘_Ó%Ð%r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   Ä  s   ø€ ÷ ?ñ ?™UŸ\™\ñ ?r"   c                óx   € \         P                  ! V P                  P                  RR7      V P                  4      # )zçReturn the polar angle :math:`\arccos(w / |q|)` in :math:`[0, \pi]`, with shape ``(*,)``.

``q`` rotates by twice this angle about the axis ``vec``.

Example:
    >>> q = Quaternion.identity()
    >>> q.polar_angle
    tensor(0.)

rB   r%   )r   rµ   r³   r´   r²   r]   s   &r   Úpolar_angleÚQuaternion.polar_angleÃ  s(   € ô �{Š{˜4Ÿ8™8Ÿ=™=¨R˜=Ó0°$·+±+Ó>Ð>r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   Ó  s   ø€ ÷ 8ñ 8™Ÿ™ñ 8r"   c                ó,   € \        V P                  4      # )záConvert the quaternion to a rotation matrix of shape ``(*, 3, 3)``.

Example:
    >>> q = Quaternion.identity()
    >>> m = q.matrix()
    >>> m
    tensor([[1., 0., 0.],
            [0., 1., 0.],
            [0., 0., 1.]])

)r   r   r]   s   &r   ÚmatrixÚQuaternion.matrixÓ  s   € ô -¨T¯Y©YÓ7Ð7r"   c                ó>   <€ V ^8„  d   QhRS[ P                  RS[RR/# )r   r   Úcheck_rotationr   r   )r   r   Úbool)r   r   s   "€r   r    r!   â  s,   ø€ ÷ Yñ Y¡§¡ð Y¹tð YÐP\ñ Yr"   c                ó&   € V ! \        WR7      4      # )a!  Create a quaternion from a rotation matrix.

Args:
    matrix: the rotation matrix to convert of shape ``(*, 3, 3)``.
    check_rotation: if ``True``, raise ``ValueError`` unless every input
        is a rotation matrix. The default ``False`` keeps the unchecked
        behaviour, under which a reflection such as
        ``diag(-1, 1, 1)`` returns a non-unit quaternion rather than
        being reported as invalid.

Example:
    >>> m = torch.eye(3)[None]
    >>> q = Quaternion.from_matrix(m)
    >>> q.data
    tensor([[1., 0., 0., 0.]])

)r  )r   )Úclsr   r  s   &&&r   Úfrom_matrixÚQuaternion.from_matrixá  s   € ñ& Ô0°ÔWÓXÐXr"   c                ól   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RR/# )r   ÚrollÚpitchÚyawr   r   rÎ   )r   r   s   "€r   r    r!   ÷  s6   ø€ ÷ ñ ™eŸl™lð ±5·<±<ð ÁeÇlÁlð ÐWcñ r"   c                ód   € \        WVR7      w  rErg\        P                  ! WEWg3R4      pV ! V4      # )aV  Create a quaternion from Euler angles.

Args:
    roll: the roll euler angle.
    pitch: the pitch euler angle.
    yaw: the yaw euler angle.

Example:
    >>> roll, pitch, yaw = torch.tensor(0), torch.tensor(1), torch.tensor(0)
    >>> q = Quaternion.from_euler(roll, pitch, yaw)
    >>> q.data
    tensor([0.8776, 0.0000, 0.4794, 0.0000])

)r
  r  r  r%   )r   r   Ústack)	r  r
  r  r  r¾   rÕ   rÖ   r×   râ   s	   &&&&     r   Ú
from_eulerÚQuaternion.from_eulerö  s1   € ô  +°ÀsÔK‰
ˆˆaÜ�KŠK˜˜q˜ bÓ)ˆÙ�1‹vˆr"   c                óv   <€ V ^8„  d   QhRS[ S[P                  S[P                  S[P                  3,          /# rX   rÓ   )r   r   s   "€r   r    r!   
  s/   ø€ ÷ Eñ E™%¡§¡©e¯l©l¹E¿L¹LÐ HÕIñ Er"   c                ón   € \        V P                  V P                  V P                  V P                  4      # )a5  Convert the quaternion to a triple of Euler angles (roll, pitch, yaw).

Example:
    >>> q = Quaternion.from_euler(torch.tensor(0.3), torch.tensor(0.2), torch.tensor(0.1))
    >>> roll, pitch, yaw = q.to_euler()
    >>> roll
    tensor(0.3000)
    >>> pitch
    tensor(0.2000)
    >>> yaw
    tensor(0.1000)

)r   r¾   rÕ   rÖ   r×   r]   s   &r   Úto_eulerÚQuaternion.to_euler
  s%   € ô % T§V¡V¨T¯V©V°T·V±V¸T¿V¹VÓDÐDr"   c                ó8   <€ V ^8„  d   QhRS[ P                  RR/# )r   Ú
axis_angler   r   rÎ   )r   r   s   "€r   r    r!     s   ø€ ÷ 9ñ 9©¯©ð 9¸,ñ 9r"   c                ó$   € V ! \        V4      4      # )a  Create a quaternion from axis-angle representation.

Args:
    axis_angle: rotation vector of shape ``(*, 3)``.

Example:
    >>> axis_angle = torch.tensor([[1., 0., 0.]])
    >>> q = Quaternion.from_axis_angle(axis_angle)
    >>> q.data
    tensor([[0.8776, 0.4794, 0.0000, 0.0000]])

)r   )r  r  s   &&r   Úfrom_axis_angleÚQuaternion.from_axis_angle  s   € ñ Ô+¨JÓ7Ó8Ð8r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   *  s   ø€ ÷ 
3ñ 
3™uŸ|™|ñ 
3r"   c                ó,   € \        V P                  4      # )z¸Convert the quaternion to an axis-angle representation.

Example:
    >>> q = Quaternion.identity()
    >>> axis_angle = q.to_axis_angle()
    >>> axis_angle
    tensor([0., 0., 0.])

)r   r   r]   s   &r   Úto_axis_angleÚQuaternion.to_axis_angle*  s   € ô (¨¯	©	Ó2Ð2r"   c                ó”   <€ V ^8„  d   QhRS[ S[,          RS[S[S[P
                  R3,          RS[S[P                  R3,          RR/# ©r   Ú
batch_sizer?   Nr@   r   r   ©r   rD   r   rY   r   r?   r@   )r   r   s   "€r   r    r!   7  sU   ø€ ÷ ñ á™S•Mðñ ‘c™5Ÿ<™<¨Ð-Õ.ðñ ‘U—[‘[ $Ð&Õ'ð	ð
 
ñr"   c                ór   € \         P                  ! . ROW#R7      pVe   VP                  V^4      pV ! V4      # )a  Create a quaternion representing an identity rotation.

Args:
    batch_size: the batch size of the underlying data.
    device: device to place the result on.
    dtype: dtype of the result.

Example:
    >>> q = Quaternion.identity()
    >>> q.data
    tensor([1., 0., 0., 0.])

r>   )r®   ç        r#  r#  )r   rE   Úrepeat)r  r   r?   r@   r   s   &&&& r   ÚidentityÚQuaternion.identity6  s5   € ô( �|Š|Ò0¸ÔMˆØÒ!Ø—;‘;˜z¨1Ó-ˆDÙ�4‹yÐr"   c          
      ó6   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RR/# )r   r¾   rÕ   rÖ   r×   r   r   )r<   )r   r   s   "€r   r    r!   P  s0   ø€ ÷ ñ ™Eð ¡eð ±ð ¹%ð ÀLñ r"   c                ó¸  € WW43pV Fw  p\        V\        4      '       d   \        RV 24      h\        V\        P                  4      '       g   KI  VP                  4       '       g   Ka  \        RVP                   24      h	  \        P                  ! WW4.4      pVP                  4       '       g%   VP                  \        P                  ! 4       4      pV ! V4      # )a}  Create a quaternion from the data coefficients.

Args:
    w: a float representing the :math:`q_w` component.
    x: a float representing the :math:`q_x` component.
    y: a float representing the :math:`q_y` component.
    z: a float representing the :math:`q_z` component.

Example:
    >>> q = Quaternion.from_coeffs(1., 0., 0., 0.)
    >>> q.data
    tensor([1., 0., 0., 0.])

z@Quaternion coefficients must be real-valued, got complex scalar zKQuaternion coefficients must be real-valued, got complex tensor with dtype )r(   Úcomplexr-   r   r   Ú
is_complexr@   rE   Úis_floating_pointr7   Úget_default_dtype)r  r¾   rÕ   rÖ   r×   rØ   Úcr   s   &&&&&   r   Úfrom_coeffsÚQuaternion.from_coeffsO  s·   € ð  ˜�ˆÛˆAÜ˜!œW×%Ò%Ü Ð#cÐdeÐcfÐ!gÓhÐhÜ˜!œUŸ\™\×*Ô*¨q¯|©|¯~¬~Ü ØaÐbc×biÑbiÐajÐkóð ñ	 ô �|Š|˜Q 1˜LÓ)ˆØ×%Ñ%×'Ò'Ø—7‘7œ5×2Ò2Ó4Ó5ˆDÙ�4‹yÐr"   c                ó”   <€ V ^8„  d   QhRS[ S[,          RS[S[S[P
                  R3,          RS[S[P                  R3,          RR/# r  r!  )r   r   s   "€r   r    r!   p  sU   ø€ ÷ 6ñ 6á™S•Mð6ñ ‘c™5Ÿ<™<¨Ð-Õ.ð6ñ ‘U—[‘[ $Ð&Õ'ð	6ð
 
ñ6r"   c                ód  € Ve   V3MRp\         P                  ! ^.VO5W#R7      w  rVpRV,
          P                  4       ^\        ,          V,          P	                  4       ,          pRV,
          P                  4       ^\        ,          V,          P                  4       ,          p	VP                  4       ^\        ,          V,          P	                  4       ,          p
VP                  4       ^\        ,          V,          P                  4       ,          pV ! \         P                  ! W‰W«3R4      4      # )a�  Create a random unit quaternion of shape ``(B, 4)``, or ``(4,)`` without a ``batch_size``.

Uniformly distributed across the rotation space as per: http://planning.cs.uiuc.edu/node198.html

Args:
    batch_size: the batch size of the underlying data.
    device: device to place the result on.
    dtype: dtype of the result.

Example:
    >>> q = Quaternion.random()
    >>> q = Quaternion.random(batch_size=2)

r>   r®   ri   r%   )r   ÚrandÚsqrtr   r¹   r¸   r  )r  r   r?   r@   Ú
rand_shapeÚr1Úr2Úr3Úq1Úq2Úq3Úq4s   &&&&        r   ÚrandomÚQuaternion.randomo  s×   € ð* '1Ò&<�j‘]À"ˆ
ä—Z’Z Ð 0 ZÑ 0¸ÔM‰
ˆ�Ø�B�h�_‰_Ó 1¤r¥6¨B¥;×"3Ñ"3Ó"5Õ6ˆØ�B�h�_‰_Ó 1¤r¥6¨B¥;×"3Ñ"3Ó"5Õ6ˆØ�W‰W‹Y˜!œb�& 2�+×*Ñ*Ó,Õ,ˆØ�W‰W‹Y˜!œb�& 2�+×*Ñ*Ó,Õ,ˆÙ”5—;’; ¨Ð/°Ó4Ó5Ð5r"   c                óR   <€ V ^8„  d   QhRRRS[ S[S[P                  3,          RR/# )r   r8  r   rª   r   r«   )r   r   s   "€r   r    r!   �  s5   ø€ ÷ "Bñ "B˜ð "B©©u±e·l±lÐ/BÕ)Cð "BÈñ "Br"   c                óÈ  € \        V\        4       V P                  4       pVP                  4       p\        VP	                  4       V,          P
                  4      p\        V\        P                  4      '       dI   VP                  4       ^ 8”  d4   VP                  4       VP                  4       ^,
          8X  d
   VR,          pV\        \        W$,          4      4      ,          # )aP  Return a unit quaternion spherically interpolated between quaternions self.q and q1.

The interpolation follows the shorter arc between the two rotations, whatever the signs of the stored
quaternions: ``q1`` and ``-q1`` give the same result, and at ``t = 1`` the output is ``q1`` or ``-q1``.
The exception is a half turn whose relative quaternion ``self.inv() * q1`` has a real part of exactly zero:
both arcs are then equally short and the path is not unique. The arc taken follows the sign of the vector
part of ``self.inv() * q1``, so ``q1`` and ``-q1`` take opposite arcs, and the result is not continuous in
``q1`` there.

See more: https://en.wikipedia.org/wiki/Slerp

Args:
    q1: second quaternion to be interpolated between.
    t: interpolation ratio, ``0`` at ``self`` and ``1`` at ``q1``. It is not validated: values outside
        ``[0, 1]`` extrapolate along the same arc. A per-quaternion ratio has shape ``(*,)``, like
        ``self.w``, or ``(*, 1)``.

Example:
    >>> q0 = Quaternion.identity()
    >>> q1 = Quaternion(torch.tensor([1., .5, 0., 0.]))
    >>> q2 = q0.slerp(q1, .3)

r¯   )r   r   Ú	normalizer   rŠ   r   r(   r   r   rC   r   )r0   r8  rª   Úq0Úrels   &&&  r   ÚslerpÚQuaternion.slerp�  s™   € ô0 	˜"œjÔ)Ø�^‰^ÓˆØ�\‰\‹^ˆô '¨¯©«°2­×';Ñ';Ó<ˆÜ�aœŸ™×&Ò&¨1¯5©5«7°Q¬;¸1¿5¹5»7ÀcÇgÁgÃiÐRSÅmÔ;Sð �)•ˆAØ”JÔ7¸½Ó@ÓAÕAÐAr"   c                ó:   <€ V ^8„  d   QhRS[ RS[P                  /# )r   r­   r   )r  r   r   )r   r   s   "€r   r    r!   ±  s   ø€ ÷ .ñ .™Dð .©U¯\©\ñ .r"   c                ó<   € V P                   P                  ^RV4      # )zöCompute the norm (magnitude) of the quaternion.

Args:
    keepdim: whether to retain the last dimension.

Returns:
    The norm of the quaternion(s) as a torch.Tensor.

Example:
    >>> q = Quaternion.identity()
    >>> q.norm()
    tensor(1.)

r%   )r   r´   )r0   r­   s   &&r   r´   ÚQuaternion.norm±  s   € ð  �y‰y�~‰~˜a  WÓ-Ð-r"   c                ó   <€ V ^8„  d   QhRR/# rh   ri   )r   r   s   "€r   r    r!   Ã  s   ø€ ÷ ;ñ ;˜<ñ ;r"   c                ó>   € \        \        V P                  4      4      # )z±Return a normalized (unit) quaternion.

Returns:
    The normalized quaternion.

Example:
    >>> q = Quaternion(torch.tensor([2., 1., 0., 0.]))
    >>> q_norm = q.normalize()

)r   r   r   r]   s   &r   r@  ÚQuaternion.normalizeÃ  s   € ô Ô.¨t¯y©yÓ9Ó:Ð:r"   c                ó   <€ V ^8„  d   QhRR/# rh   ri   )r   r   s   "€r   r    r!   Ð  s   ø€ ÷ Lñ L�lñ Lr"   c                ó~   € \        \        P                  ! V P                  R,          V P                  ) 3R4      4      # )zËCompute the conjugate of the quaternion.

Returns:
    The conjugate quaternion, with the vector part negated.

Example:
    >>> q = Quaternion(torch.tensor([1., 2., 3., 4.]))
    >>> q_conj = q.conj()

r¯   r%   )r   r   rN   rG   r³   r]   s   &r   ÚconjÚQuaternion.conjÐ  s.   € ô œ%Ÿ)š) T§Y¡Y¨yÕ%9¸D¿H¹H¸9Ð$EÀrÓJÓKÐKr"   c                ó   <€ V ^8„  d   QhRR/# rh   ri   )r   r   s   "€r   r    r!   Ý  s   ø€ ÷ 1ñ 1�\ñ 1r"   c                óL   € V P                  4       V P                  4       ,          # )z’Compute the inverse of the quaternion.

Returns:
    The inverse quaternion.

Example:
    >>> q = Quaternion.identity()
    >>> q_inv = q.inv()

)rM  Úsquared_normr]   s   &r   rŠ   ÚQuaternion.invÝ  s   € ð �y‰y‹{˜T×.Ñ.Ó0Õ0Ð0r"   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rX   rÎ   )r   r   s   "€r   r    r!   ê  s   ø€ ÷ Fñ F™eŸl™lñ Fr"   c                ór   € \        V P                  V P                  4      V P                  ^,          ,           # )zÔCompute the squared norm (magnitude) of the quaternion.

Returns:
    The squared norm of the quaternion(s) as a torch.Tensor.

Example:
    >>> q = Quaternion.identity()
    >>> q.squared_norm()
    tensor(1.)

)r   r³   rG   r]   s   &r   rQ  ÚQuaternion.squared_normê  s&   € ô # 4§8¡8¨T¯X©XÓ6¸¿¹ÀA½ÕEÐEr"   c                ód   <€ V ^8„  d   Qh/ S[ S[P                  S[P                  3,          ;R&   # )r   r$   r   )r   r   s   "€r   r    r!   B   s&   ø‡ ‚ ñf ‘—‘™rŸ|™|Ð+Õ,Ñ,òg r"   rÐ   )F)NNN)9Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r	   Ú__deepcopy__r'   r7   rU   r^   re   rk   rr   rw   r}   r„   r�   r‘   r™   rž   r£   r§   rË   Úpropertyr   rØ   rG   r³   râ   r²   r¾   rÕ   rÖ   r×   r,   rü   r   Úclassmethodr  r  r  r  r  r%  r.  r<  rC  r´   r@  rM  rŠ   rQ  Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r1   r   s   @@r   r   r   B   sª  ù‡ € ñMð` *€L÷0ó 0÷:
:ð 
:÷&,ð &,÷Pð ÷*ð *÷	&ð 	&÷7ð 7÷&'ð '÷.Jð J÷
Ið I÷'ð '÷,#ð #÷ ð  ÷
 ð  ÷
 ð  ÷
'ð '÷)Kð )KðV ÷ó ðð ÷.ó ð.ð ÷ó ðð ÷"ó ð"ð ÷ó ðð ÷ó ðð ÷!ó ð!ð ÷!ó ð!ð ÷!ó ð!ð ÷!ó ð!ð ÷&ó ð&ð ÷?ó ð?÷8ð 8ð ÷Yñ Yó ðYð( ÷ó ð÷&Eð Eð  ÷9ó ð9÷
3ð 
3ð ÷ñ ó ðð0 ÷ó ðð> ÷6ñ 6ó ð6÷:"Bð "B÷H.ò .÷$;ð ;÷Lð L÷1ð 1÷Fð F÷Q … r"   r   c                ó$   € V ^8„  d   QhRRRRRR/# )r   r�   r   ro   r   ri   )r   s   "r   r    r    ù  s&   € ÷ Eñ E˜Lð E°ð EÀ,ñ Er"   c                óž  € V P                   P                  RR VP                   P                  RR r2Rp\        V4      ^ 8X  g*   \        V4      ^ 8X  g   \        V4      \        V4      8X  dA    \        P                  ! V P                   P                  VP                   P                  4      pVf%   \        R\        V4       R\        V4       R24      hV P                   P                  V4      VP                   P                  V4      reVR,          VR,          VR,          VR,          3w  rxršWy,          \        WŠ4      ,
          pVR	,          V
,          V	R	,          V,          ,           \        P                  P                  WŠRR7      ,           p\        \        P                  ! VR	,          V3R4      4      #   \
         d    Rp ELi ; i)
zmReturn ``left * right``, broadcasting an unbatched operand, or batch shapes of equal rank, against the other.Nz,Cannot multiply quaternions of batch shapes rA   zb. One must be unbatched, or both must have the same number of batch axes, each equal or of size 1.rB   r%   rˆ   r±   r¯   )r   r,   Úlenr   rF   rH   r-   r.   rI   r   ÚlinalgÚcrossr   rN   )r�   ro   Ú
left_batchÚright_batchr,   ÚaÚbÚa_realÚa_vecÚb_realÚb_vecÚnew_realÚnew_vecs   &&           r   r{   r{   ù  s†  € à"Ÿi™iŸo™o¨c¨rÐ2°E·J±J×4DÑ4DÀSÀbÐ4I�Ø"&€EÜ
ˆ:ƒ˜!Ôœs ;Ó/°1Ô4¼¸J»Ì3È{ÓK[Ô8[ð	Ü×*Ò*¨4¯9©9¯?©?¸E¿J¹J×<LÑ<LÓMˆEð ‚}ÜØ:¼5ÀÓ;LÐ:MÈUÔSXÐYdÓSeÐRfð gcð có
ð 	
ð �9‰9×Ñ˜EÓ" E§J¡J×$5Ñ$5°eÓ$<€qØ#$ V¥9¨a°­j¸!¸F½)ÀQÀwÅZÐ#OÑ €F�6Ø�Ô!4°UÓ!BÕB€HØ�YÕ %Õ'¨&°Õ*;¸eÕ*CÕCÄeÇlÁl×FXÑFXÐY^ÐkmÐFXÓFnÕn€GÜ”e—i’i ¨)Õ!4°gÐ >ÀÓCÓDÐDøô ô 	Ø‹Eð	ús   Á.?F; Æ;GÇGc                óV   € V ^8„  d   QhRRR\         \        P                  ,          RR/# )r   ÚQr   r¾   r   )r   r   r   )r   s   "r   r    r      s/   € ÷ J*ñ J*˜<ð J*¬H´U·\±\Õ,Bð J*Èlñ J*r"   c           	     óÀ  € \        V \        4       V P                  4       P                  pVP                  ^ ,          pVf   VP
                  V,          V,          pEMVP                  V^38X  d   VP                  R4      pM:VP                  V38w  d)   \        R\        VP                  4       RV RV R24      hVP                  VP                  VP                  R7      p\        V^ 8  P                  4       4      '       d   \        R4      hVP                  4       p\        V^ 8H  4      '       d   \        R4      hW,          pVP
                  \        P                   ! V4      ,          V,          pVP                  pVP                  \        P"                  \        P$                  39   d   VP'                  4       p\        P(                  P+                  VP-                  4       4      w  rx\        P.                  ! V4      p	\1        WGW‰P3                  ^4      4      P                  V4      p
WªP5                  4       ,          p
\        V
P7                  ^ 4      4      # )	a¸  Average quaternions as their weighted chordal mean rotation, whatever their signs.

``q_mean = average_quaternions(Q, w)`` takes a :class:`Quaternion` of ``M`` quaternions, ``(M, 4)``, and optional
non-negative weights ``w`` of shape ``(M,)`` or ``(M, 1)``, uniform by default, and returns their mean rotation as
a unit :class:`Quaternion` of shape ``(1, 4)``. To interpolate between two rotations instead, use
:meth:`Quaternion.slerp`.

Convention:
    - The chordal mean of scipy's ``Rotation.mean``: the eigenvector of
      :math:`\sum_i w_i q_i q_i^\top / \sum_i w_i` with the largest eigenvalue. ``q_i`` and ``-q_i`` count the
      same, and the sign of the result is arbitrary.
    - ``w`` need not sum to one: scaling it by a positive factor does not change the result.
    - The members are normalised first, so only their directions count: a member stored as ``3 * q`` weighs
      the same as ``q``.

Args:
    Q: quaternions of shape ``(M, 4)``.
    w: weights of shape ``(M,)`` or ``(M, 1)``. If None, uniform weights are used.

Returns:
    the averaged quaternion, of unit norm and shape ``(1, 4)``.

Raises:
    TypeCheckError: if ``Q`` is not a :class:`Quaternion`.
    ValueError: if ``w`` does not have ``M`` elements, has a negative entry, or sums to zero.

See Also:
    - :class:`Quaternion`: holds ``Q`` and the result; it composes, inverts and converts quaternions one at a
      time rather than averaging them.
    - :meth:`Quaternion.slerp`: interpolates between two rotations along the shorter arc instead of averaging
      many.

Example:
    >>> Q = Quaternion(torch.tensor([[1., 0., 0., 0.], [-1., 0., 0., 0.]]))
    >>> average_quaternions(Q).data.abs()
    tensor([[1., 0., 0., 0.]])

zweights shape z
 must be (z,) or (z, 1))r@   zweights must be non-negativezweights must not all be zeror%   )r   r   r@  r   r,   ÚTÚsqueezer-   r.   r7   r?   r@   r  ÚanyÚsumr   ÚdiagÚfloat16Úbfloat16r<   rf  Úeighr»   Úargmaxr
   Úreshaper´   rM   )rs  r¾   r   ÚMÚAÚw_sumÚ
orig_dtypeÚeigenvaluesÚeigenvectorsÚmax_idxÚq_avgs   &&         r   Úaverage_quaternionsr‡    s¿  € ôN �aœÔ$ð �;‰;‹=×Ñ€Dà�
‰
�1�€AØ‚yØ�V‰V�d�]˜aÕŠà�7‰7�q˜!�fÔØ—	‘	˜"“‰AØ�W‰W˜˜Œ_Ü˜~¬e°A·G±G«nÐ-=¸ZÈÀsÈ'ÐRSÐQTÐTXÐYÓZÐZØ�D‰D�—‘ D§J¡JˆDÓ/ˆÜ��Q‘—‘“×ÒÜÐ;Ó<Ð<Ø—‘“ˆÜ�˜‘
×ÒÜÐ;Ó<Ð<Ø�IˆØ�F‰F”U—Z’Z “]Õ" TÕ)ˆà—‘€JØ‡w�w”5—=‘=¤%§.¡.Ð1Ô1Ø�G‰G‹Iˆô !&§¡× 1Ñ 1°!·(±(³*Ó =Ñ€Kô �lŠl˜;Ó'€GÜ" 1°<ÇÁÐQRÓASÓT×WÑWÐXbÓc€EØ—J‘J“LÕ €Eä�e—o‘o aÓ(Ó)Ð)r"   r[   )r[  Úmathr   Útypingr   r   r   r   r   r   Úkornia.core.checkr   Úkornia.core.utilsr	   r
   Úkornia.geometry.conversionsr   r   r   r   r   r   r   Úkornia.geometry.linalgr   ÚModuler   r{   r‡  ri   r"   r   Ú<module>r�     s\   ðñ$õ8 ß .Ó .ã Ý å /ß L÷÷ ñ õ 7ôt
F�—‘ô t
FõnE÷*J*ñ J*r"   