+
    åûj©s  ã                   ó$  € R t ^ RIt^ RIHtHtHtHt ^ RIt^ RIHt ^ RI	H
t
HtHtHt ^ RIHt ^ RIHtHtHtHtHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt RR.t ! R R]P@                  4      t!R R lt"R R lt#R R lt$R R lt%RR R llt&R# )a–  Lines in any dimension as origin plus direction: distances, plane intersection and fitting.

A line is :math:`l(t) = o + t d`, with an origin ``o`` and a direction ``d`` of shape ``(D,)`` for one line or
``(B, D)`` for ``B`` lines, in any dimension ``D``. The constructor stores the direction as given; the distances and
the projection need it to be unit, which :meth:`~kornia.geometry.line.ParametrizedLine.through` and :func:`fit_line`
return. ``kornia.geometry.ray.Ray`` is the same class as :class:`ParametrizedLine`.

Which function to use:

- A line from an origin and a direction, or through two points, with the points along it, the projection and distance
  of points, and the intersection with a 3D plane: :class:`ParametrizedLine`.
- The line that best fits each of ``B`` sets of points, by total least squares, optionally weighted: :func:`fit_line`.
- A plane in 3D, and the plane that best fits 3D points: :class:`~kornia.geometry.plane.Hyperplane` and
  :func:`~kornia.geometry.plane.fit_plane`.
- The distance from 2D points to lines given as coefficients :math:`ax + by + c = 0`, without a line object:
  :func:`~kornia.geometry.linalg.point_line_distance`.
N)ÚIteratorÚOptionalÚTupleÚUnion)Únn)ÚKORNIA_CHECK_IS_TENSORÚKORNIA_CHECK_SHAPEÚKORNIA_CHECK_SIZESÚare_checks_enabled)ÚValueCheckError)Ú_deepcopy_module_stateÚ_svd_work_dtypeÚ_symmetric_eigenvectorÚ_torch_svd_castÚis_compilingÚregister_module_state)Ú_normalize_last_dim)Úbatched_dot_product)Ú
Hyperplane)ÚScalarÚParametrizedLineÚfit_linec                   ód  a a€ ] tR t^>t 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4       t]V3R lR l4       tV3R lR lt]V3R lR l4       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R!V3R lR lltR tVtV ;t# )"r   a  Represent a line o + t d in any dimension, with distances and plane intersection.

``line = ParametrizedLine(origin, direction)`` stores an origin and a direction of shape ``(D,)``, or ``(B, D)``
for ``B`` lines, in any dimension ``D``, as given; ``ParametrizedLine.through(p0, p1)`` builds the line from
``p0`` towards ``p1`` with a unit direction. ``line.point_at(t)`` returns the points :math:`o + t d`; for a unit
direction, ``line.projection(p)`` returns the closest points on the line ``(..., D)`` and ``line.distance(p)``
the distances ``(...)`` of points ``(..., D)``; ``line.intersect(plane)`` returns where a 3D line meets a
:class:`~kornia.geometry.plane.Hyperplane`. To fit the line to many points, use :func:`fit_line`; for 2D lines
given as coefficients :math:`ax + by + c = 0`, :func:`~kornia.geometry.linalg.point_line_distance`.

The line is the set

.. math::

    l(t) = o + t * d

Convention:
    - The constructor does not normalise or check ``direction``, so :meth:`point_at` steps ``t`` in units of its
      length. :meth:`through` and :func:`fit_line` return a unit direction; after :meth:`through`, ``t`` is the
      Euclidean distance from ``p0``.
    - :meth:`projection`, :meth:`squared_distance` and :meth:`distance` require a unit ``direction``.
    - Points broadcast against the lines as torch broadcasts ``(..., D)`` against ``(B, D)``: the axis before
      the coordinates pairs with the line batch. One line, or a batch of one, takes points of any leading shape;
      a batch of ``B > 1`` takes ``(B, D)``, one point per line, a single ``(D,)`` point, or ``(N, B, D)`` for
      ``N`` points per line. ``(B, N, D)`` is not ``N`` points per line: it raises unless ``N`` is ``B`` or 1.
      With ``N = B``, line ``j`` meets ``point[:, j]``; with ``N = 1``, every line meets every point and the
      result is ``(B, B)``.
    - :meth:`intersect` returns ``(lambda, point)`` with ``point = point_at(lambda)``: ``lambda`` is in units of
      the stored direction, and the plane's normal need not be unit. It takes a 3D line. A batch of ``B`` lines
      meets one plane, a batch of ``B`` planes or a batch of one, and one unbatched line or a batch of one meets a
      batch of planes of any size.
    - ``origin`` and ``direction`` are registered module state, so ``state_dict()`` and ``.to()`` include them.
      Outside graph capture, a floating-point tensor that takes no part in autograd (no ``grad_fn`` and
      ``requires_grad=False``) becomes an ``nn.Parameter``, so a line built from plain tensors, including the
      result of :meth:`through` and :func:`fit_line` on such tensors, returns points and distances that require
      grad. A caller's ``nn.Parameter`` is kept; any other floating-point tensor, such as a leaf that requires
      grad or a tensor with autograd history, is stored as a buffer and keeps its autograd link; an integer or
      bool tensor raises ``TypeCheckError``. ``copy.deepcopy`` holds an origin or a direction with autograd
      history as a new leaf that keeps ``requires_grad``, as for :class:`~kornia.geometry.quaternion.Quaternion`.

See Also:
    - :func:`fit_line`: fits the line to a set of points by total least squares, instead of taking an origin
      and a direction.
    - :class:`~kornia.geometry.plane.Hyperplane`: a plane in 3D, :math:`n \cdot x + d = 0`, the operand of
      :meth:`intersect`.
    - :func:`~kornia.geometry.linalg.point_line_distance`: the distance from 2D points to lines given as
      coefficients :math:`(a, b, c)`, without a line object.

Example:
    >>> line = ParametrizedLine.through(torch.tensor([0.0, 0.0]), torch.tensor([3.0, 4.0]))
    >>> line.point_at(10.0)
    tensor([6., 8.], grad_fn=<AddBackward0>)
    >>> line.distance(torch.tensor([[4.0, 3.0], [-3.0, -4.0]]))
    tensor([1.4000, 0.0000], grad_fn=<LinalgVectorNormBackward0>)

c                óR   <€ V ^8„  d   QhRS[ P                  RS[ P                  RR/# )é   ÚoriginÚ	directionÚreturnN©ÚtorchÚTensor)ÚformatÚ__classdict__s   "€ÚPC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\line.pyÚ__annotate__ÚParametrizedLine.__annotate__{   s*   ø€ ÷ =ñ =™uŸ|™|ð =¹¿¹ð =Èñ =ó    c                óX   <€ \         SV `  4        \        V RV4       \        V RV4       R# )aò  Initialize a parametrized line of direction and origin.

Args:
    origin: a point on the line, ``(D,)`` or ``(B, D)``, in any dimension ``D``.
    direction: the direction vector of the line, of the same shape; stored as given, neither normalised nor
        checked against ``origin``.

Raises:
    TypeCheckError: if ``origin`` or ``direction`` is an integer or bool tensor.

Example:
    >>> o = torch.tensor([0.0, 0.0])
    >>> d = torch.tensor([0.6, 0.8])
    >>> l = ParametrizedLine(o, d)

Ú_originÚ
_directionN)ÚsuperÚ__init__r   )Úselfr   r   Ú	__class__s   &&&€r#   r+   ÚParametrizedLine.__init__{   s(   ø€ ô" 	‰ÑÔÜ˜d I¨vÔ6Ü˜d L°)Ö<r&   c                ó    <€ V ^8„  d   QhRS[ /# ©r   r   ©Ústr)r!   r"   s   "€r#   r$   r%   �   s   ø€ ÷ Eñ E™ñ Er&   c                ó:   € R V P                    RV P                   2# )zOrigin: z
Direction: ©r   r   ©r,   s   &r#   Ú__str__ÚParametrizedLine.__str__�   s   € Ø˜$Ÿ+™+˜ m°D·N±NÐ3CÐDÐDr&   c                ó    <€ V ^8„  d   QhRS[ /# r0   r1   )r!   r"   s   "€r#   r$   r%   “   s   ø€ ÷ ñ ™#ñ r&   c                ó   € \        V 4      # ©Nr1   r5   s   &r#   Ú__repr__ÚParametrizedLine.__repr__“   s   € Ü�4‹yÐr&   c                ó:   <€ V ^8„  d   QhRS[ RS[P                  /# )r   Úidxr   )Úintr   r    )r!   r"   s   "€r#   r$   r%   –   s   ø€ ÷ 2ñ 2™sð 2¡u§|¡|ñ 2r&   c                ó@   € V P                   V P                  3V,          # r:   r4   )r,   r>   s   &&r#   Ú__getitem__ÚParametrizedLine.__getitem__–   s   € Ø—‘˜TŸ^™^Ð,¨SÕ1Ð1r&   c                óD   <€ V ^8„  d   QhRS[ S[P                  ,          /# r0   )r   r   r    )r!   r"   s   "€r#   r$   r%   ™   s   ø€ ÷ 1ñ 1™(¡5§<¡<Õ0ñ 1r&   c              #  óR   "  € V P                   V P                  3 R j  x€L
  R #  L5ir:   r4   r5   s   &r#   Ú__iter__ÚParametrizedLine.__iter__™   s   é € Ø—K‘K §¡Ð0×0Ô0ùs   ‚'ž%Ÿ'c                ó4   <€ V ^8„  d   QhRS[ P                  /# r0   r   )r!   r"   s   "€r#   r$   r%   �   s   ø€ ÷ ñ ™Ÿ™ñ r&   c                ó   € V P                   # )zReturn the line origin point.)r(   r5   s   &r#   r   ÚParametrizedLine.originœ   s   € ð �|‰|Ðr&   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r0   r   )r!   r"   s   "€r#   r$   r%   ¢   s   ø€ ÷ ñ ™5Ÿ<™<ñ r&   c                ó   € V P                   # )z!Return the line direction vector.)r)   r5   s   &r#   r   ÚParametrizedLine.direction¡   s   € ð �‰Ðr&   c                ó    <€ V ^8„  d   QhRS[ /# r0   )r?   )r!   r"   s   "€r#   r$   r%   ¦   s   ø€ ÷ (ñ (‘Sñ (r&   c                ó<   € V P                   P                  R,          # )zeReturn the dimension ``D`` of the space the line lies in, the size of the last axis of the direction.éÿÿÿÿ)r   Úshaper5   s   &r#   ÚdimÚParametrizedLine.dim¦   s   € à�~‰~×#Ñ# BÕ'Ð'r&   c                óR   <€ V ^8„  d   QhRS[ P                  RS[ P                  RR/# )r   Úp0Úp1r   r   r   )r!   r"   s   "€r#   r$   r%   «   s0   ø€ ÷ Kñ K™Ÿ™ð K©5¯<©<ð KÐ<Nñ Kr&   c                ó\  € W!,
          p\         P                  P                  4       '       gl   \        4       '       d\   \	        4       '       gL   \        VP                  4       P                  RR7      ^ 8„  P                  4       4      '       g   \        R4      h\        V\        VR4      4      # )a×  Construct a parametrized line going from a point :math:`p0` to :math:`p1`.

The origin is ``p0`` and the direction the unit vector from ``p0`` towards ``p1``, so ``point_at(t)`` is the
point at Euclidean distance ``t`` from ``p0``. The norm is floored at ``1e-12``: points closer than that pass
the check below but get a direction of length ``|p1 - p0| / 1e-12``, not a unit one, which scales
``point_at`` and the projections and distances that assume a unit direction. The check that the points differ
is skipped under ``torch.compile`` and by ``disable_checks()``, like every kornia value check.

Args:
    p0: tensor with first point ``(B, D)`` or ``(D,)``, where ``D`` is the point dimension.
    p1: tensor with second point of the same shape.

Raises:
    ValueCheckError: if ``p0`` and ``p1`` coincide in any row, so the line has no direction.

Example:
    >>> p0 = torch.tensor([0.0, 0.0])
    >>> p1 = torch.tensor([1.0, 1.0])
    >>> l = ParametrizedLine.through(p0, p1)

©rQ   zJParametrizedLine.through requires two distinct points; p0 and p1 coincide.gê-�™—q=rO   )r   ÚjitÚis_scriptingr
   r   ÚboolÚabsÚamaxÚallr   r   r   )ÚclsrT   rU   r   s   &&& r#   ÚthroughÚParametrizedLine.throughª   s|   € ð. •Gˆ	ä—	‘	×&Ñ&×(Ò(Ü"×$Ò$Ü —N’NÜ˜)Ÿ-™-›/×.Ñ.°2Ð.Ó6¸Ñ:×?Ñ?ÓA×BÒBä!Ð"nÓoÐoÜ Ô$7¸	À5Ó$IÓJÐJr&   c                óh   <€ V ^8„  d   QhRS[ S[S[P                  S[3,          RS[P                  /# )r   Útr   )r   Úfloatr   r    r   )r!   r"   s   "€r#   r$   r%   Ë   s/   ø€ ÷ 0ñ 0™%¡¡u§|¡|±VÐ ;Õ<ð 0ÁÇÁñ 0r&   c                ón  € \        V\        4      '       d   VP                  p\        V\        P                  4      '       dQ   VP
                  ^ 8”  d@   VP
                  \        V P                  P
                  ^,
          ^4      8X  d
   VR,          pV P                  V P                  V,          ,           # )aw  Get the point at :math:`t` along this line.

Args:
    t: step along the line, in units of the direction's length: a number or a 0-d tensor for every row,
        one step per row of shape ``(B,)`` or ``(B, 1)`` for a line of shape ``(B, D)``, or ``N`` steps of
        shape ``(N,)`` or ``(N, 1)`` for a line of shape ``(D,)``, giving ``(N, D)`` points.

Return:
    the points :math:`o + t d`, ``(D,)`` or ``(B, D)``, or ``(N, D)`` for an ``(N,)`` or ``(N, 1)`` step.

Example:
    >>> p0 = torch.tensor([0.0, 0.0])
    >>> p1 = torch.tensor([1.0, 1.0])
    >>> l = ParametrizedLine.through(p0, p1)
    >>> p2 = l.point_at(0.1)

©.N)	Ú
isinstancer   Údatar   r    ÚndimÚmaxr   r   )r,   rb   s   &&r#   Úpoint_atÚParametrizedLine.point_atË   sy   € ô$ �aœ× Ò Ø—‘ˆAÜ�aœŸ™×&Ò&¨1¯6©6°A¬:¸!¿&¹&ÄCÈÏÉ×H[ÑH[Ð^_ÕH_ÐabÓDcÔ:cØ�)•ˆAØ�{‰{˜TŸ^™^¨aÕ/Õ/Ð/r&   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   Úpointr   r   )r!   r"   s   "€r#   r$   r%   ã   s'   ø€ ÷ rñ r¡§¡ð r±·±ñ rr&   c                ó    € V P                   \        V P                  WP                   ,
          4      R,          V P                  ,          ,           # )aB  Return the projection of a point onto the line.

The projection is the closest point on the line only for a unit direction.

Args:
    point: the point to be projected, ``(..., D)``, broadcast against the lines as the class conventions
        say.

Return:
    the projected points, of the broadcast shape ``(..., D)``.

re   )r   r   r   ©r,   rn   s   &&r#   Ú
projectionÚParametrizedLine.projectionã   s8   € ð �{‰{Ô0°·±ÀÏÉÕATÓUÐV_Õ`Ðcg×cqÑcqÕqÕqÐqr&   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rm   r   )r!   r"   s   "€r#   r$   r%   ò   s#   ø€ ÷ .ñ .¡e§l¡lð .±u·|±|ñ .r&   c                ó`   € V P                  V4      p\        P                  ! W",          RR7      # )a6  Return the squared distance of a point to its projection onto the line.

It is the squared Euclidean distance to the line only for a unit direction.

Args:
    point: the point to calculate the distance onto the line, ``(..., D)``.

Return:
    the squared distances, of the broadcast leading shape ``(...)``.
rW   rO   )Ú_perpendicularr   Úsum)r,   rn   Úperps   && r#   Úsquared_distanceÚ!ParametrizedLine.squared_distanceò   s'   € ð ×"Ñ" 5Ó)ˆÜ�yŠy˜�¨"Ô-Ð-r&   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rm   r   )r!   r"   s   "€r#   r$   r%      s'   ø€ ÷ Lñ L™eŸl™lð L©u¯|©|ñ Lr&   c                ób   € \         P                  P                  V P                  V4      RR7      # )a  Return the distance of a point to its projection onto the line.

It is the Euclidean distance to the line only for a unit direction.

Args:
    point: the point to calculate the distance onto the line, ``(..., D)``.

Return:
    the distances, of the broadcast leading shape ``(...)``.
rW   rO   )r   ÚlinalgÚvector_normru   rp   s   &&r#   ÚdistanceÚParametrizedLine.distance   s)   € ô �|‰|×'Ñ'¨×(;Ñ(;¸EÓ(BÈÐ'ÓKÐKr&   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rm   r   )r!   r"   s   "€r#   r$   r%     s'   ø€ ÷ Xñ X¡E§L¡Lð X±U·\±\ñ Xr&   c                ó¨   € WP                   ,
          pV\        P                  ! W P                  ,          RRR7      V P                  ,          ,
          # )é   T©rQ   ÚkeepdimrO   )r   r   rv   r   )r,   rn   Úds   && r#   ru   ÚParametrizedLine._perpendicular  s8   € ð —K‘KÕˆØ”5—9’9˜Q§¡Õ/°RÀÔFÈÏÉÕWÕWÐWr&   c                ój   <€ V ^8„  d   QhRS[ RS[RS[S[P                  S[P                  3,          /# )r   ÚplaneÚepsr   )r   rc   r   r   r    )r!   r"   s   "€r#   r$   r%     s7   ø€ ÷ #%ñ #%™zð #%±ð #%ÁÁuÇ|Á|ÑUZ×UaÑUaÐGaÕAbñ #%r&   c                óF  € \        VP                  P                  V P                  4      pVP	                  4       V8¬  p\
        P                  ! WC\
        P                  ! V4      4      p\
        P                  ! VVP                  P                  \        VP                  P                  V P                  4      ,           ) V,          \
        P                  ! V4      4      pVP                  ^ 8X  d   TMVR,          pV P                  V P                  V,          ,           pWh3# )aÐ  Return the intersection point between the line and a given plane.

Args:
    plane: the plane to compute the intersection point.
    eps: absolute threshold on ``|normal . direction|`` below which the line counts as parallel to the plane.

Return:
    The pair ``(lambda, point)``. ``lambda`` is the line parameter of the intersection in units of the stored
    direction, ``()`` for one unbatched line and one unbatched plane, and otherwise the broadcast batch
    ``(...)``, which for one unbatched line is the batch of the planes, over any number of axes. ``point`` is
    the intersection ``origin + lambda * direction``, one per plane, of shape ``(..., 3)`` with the same batch.

Note:
    If the line is parallel to the plane (``|normal . direction| < eps``) there is no unique
    intersection; the function returns lambda ``0`` and the line origin as the point.
    Within this fallback branch, lambda has zero derivatives and the point differentiates as the origin.

re   )r   Únormalrg   r   r[   r   ÚwhereÚ	ones_likeÚoffsetr   Ú
zeros_likerh   )	r,   rˆ   r‰   Údot_prodÚdot_prod_maskÚdot_prod_safeÚ
res_lambdaÚstepÚ	res_points	   &&&      r#   Ú	intersectÚParametrizedLine.intersect  sÒ   € ô& ' u§|¡|×'8Ñ'8¸$¿.¹.ÓIˆØ Ÿ™›¨#Ñ-ˆô Ÿš M¼U¿_º_ÈXÓ=VÓWˆÜ—[’[ØØ�l‰l×ÑÔ"5°e·l±l×6GÑ6GÈÏÉÓ"UÕUÐVÐYfÕfÜ×Ò˜XÓ&ó
ˆ
ð (Ÿ_™_°Ô1‰z°zÀ)Õ7LˆØ—K‘K $§.¡.°4Õ"7Õ7ˆ	ØÐ$Ð$r&   © )g�íµ ÷Æ°>)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__deepcopy__r+   r6   r;   rA   rE   Úpropertyr   r   rQ   Úclassmethodr_   rj   rq   rx   r~   ru   r–   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r-   r"   s   @@r#   r   r   >   sÖ   ù‡ € ñ7ðt *€L÷=ó =÷*Eð E÷ð ÷2ð 2÷1ð 1ð ÷ó ðð ÷ó ð÷(ð (ð ÷Kó ðK÷@0ð 0÷0rð r÷.ð .÷Lð L÷Xð X÷#%÷ #%ò #%r&   c                ó®   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\         P                  /# )r   ÚdxÚdyÚweightsr   ©r   r    r   )r!   s   "r#   r$   r$   ?  sF   € ÷ \ñ \œ%Ÿ,™,ð \¬E¯L©Lð \Ä8ÌEÏLÉLÕCYð \Ô^c×^jÑ^jñ \r&   c                óø  € \         P                  ! V P                  4       P                  RRR7      VP                  4       P                  RRR7      4      p\         P                  ! V^ 8„  V\         P
                  ! V4      4      pW,          p W,          pVf   T MW ,          pVf   TMW!,          pW@,          P                  RRR7      pWQ,          P                  RRR7      pWA,          P                  RRR7      pVP                  p	V	\         P                  \         P                  39   d0   VP                  4       VP                  4       VP                  4       r‡pR\         P                  ! RV,          Wg,
          4      ,          p
\         P                  ! \         P                  ! \        P                  ^,          V
P                  4       ,
          4      V
P                  4       .RR7      P!                  V	4      # )aA  Return the unit direction of the total least squares line through centred 2-D points (#5040).

The direction is the principal axis of the (weighted) scatter of ``(dx, dy)``, in closed form:
``theta = 0.5 * atan2(2 * sxy, sxx - syy)`` lies in ``[-pi / 2, pi / 2]`` and the direction is
``(cos(theta), sin(theta))``, so its x component is non-negative. ``theta`` does not change when the points are
scaled, so they are first divided by their largest magnitude: the second moments then cannot overflow (float16
does past 65504) or underflow, whatever the unit of the coordinates.
Trƒ   rW   rO   g      à¿éþÿÿÿ)r   Úmaximumr[   r\   rŒ   r�   rv   ÚdtypeÚfloat16Úbfloat16rc   Úatan2ÚcatÚsinÚmathÚpiÚto)r¥   r¦   r§   ÚscaleÚwdxÚwdyÚsxxÚsyyÚsxyr¬   Úthetas   &&&        r#   Ú_tls_direction_2dr¼   ?  s_  € ô �MŠM˜"Ÿ&™&›(Ÿ-™-¨B¸˜-Ó=¸r¿v¹v»x¿}¹}ÐQSÐ]a¸}Ó?bÓc€EÜ�KŠK˜ ™	 5¬%¯/ª/¸%Ó*@ÓA€EØ	�€BØ	�€BØ’‰" W¥\€CØ’‰" W¥\€CØ�8�.‰.˜R¨ˆ.Ó
.€CØ�8�.‰.˜R¨ˆ.Ó
.€CØ�8�.‰.˜R¨ˆ.Ó
.€Cð �I‰I€EØ”—‘¤§¡Ð/Ô/ØŸ	™	› S§Y¡Y£[°#·)±)³+�#ˆð ”5—;’;˜r C�x¨­Ó3Õ3€Eô �9Š9”e—i’i¤§¡¨!¥¨e¯i©i«kÕ 9Ó:¸E¿I¹I»KÐHÈbÔQ×TÑTÐUZÓ[Ð[r&   c                óD   € V ^8„  d   QhR\         P                  R\        /# )r   Úpointsr   ©r   r    r   )r!   s   "r#   r$   r$   `  s#   € ÷ Cñ CœUŸ\™\ð CÔ.>ñ Cr&   c                ó  € V P                   pV\        P                  \        P                  39   d   V P	                  4       p V R,          pV R,          pV R,          V,
          pV R,          V,
          pVP                  R	RR7      pVP                  R	RR7      p\        WF,
          WW,
          R4      p\        P                  ! W&,           W7,           .R	R7      p	\        V	P                  V4      VP                  V4      4      # )
ah  Fit a 2-D line by total least squares (#5040).

The points are centred relative to the first one, so a coordinate that equals the first point's is exactly 0
after centring, whatever the rounding of the mean. An exactly vertical set then has ``sxy = +0`` and gets the
direction ``(0, 1)``; the float32 rounding of ``pi / 2`` can leave an x component of 1.2e-7.
Trƒ   NrW   ©.ºNr‚   Né    ©.rÂ   r‚   ©.rÃ   ©.r‚   rO   )
r¬   r   r­   r®   rc   Úmeanr¼   r°   r   r´   )
r¾   r¬   Úx0Úy0ÚxÚyÚx_meanÚy_meanr   r   s
   &         r#   Ú_fit_line_tls_2drÎ   `  sÍ   € ð �L‰L€Eð ”—‘¤§¡Ð/Ô/Ø—‘“ˆØ	�
Õ	€BØ	�
Õ	€BØˆv�˜Õ€AØˆv�˜Õ€AØ�V‰V˜ DˆVÓ)€FØ�V‰V˜ DˆVÓ)€Fä! !¥*¨a­j¸$Ó?€IÜ�YŠY˜� R¥[Ð1°rÔ:€FÜ˜FŸI™I eÓ,¨i¯l©l¸5Ó.AÓBÐBr&   c                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# ©r   r¾   r§   r   r¿   )r!   s   "r#   r$   r$   x  s/   € ÷ Kñ K¤e§l¡lð K¼U¿\¹\ð KÔN^ñ Kr&   c                ó’  € \         P                  ! V P                  VP                  4      pV\         P                  \         P                  39   d   \         P
                  MTpV P                  V4      VP                  V4      rVP                  4       P                  RRR7      pV\         P                  ! V^ 8„  V\         P                  ! V4      4      ,          pV R,          pV R,          pV R,          V,
          pV R,          V,
          pVP                  RRR7      p	W,          P                  RRR7      V	,          p
W,          P                  RRR7      V	,          p\        Wz,
          W‹,
          V4      p\         P                  ! WZ,           Wk,           .RR7      p\        VP                  V4      VP                  V4      4      # )	z¥Fit a 2-D line by weighted total least squares: weighted centroid and weighted moments (#5040).

Centred relative to the first point, like :func:`_fit_line_tls_2d`.
Trƒ   rW   rO   rÁ   rÄ   rÅ   rÆ   )r   Úpromote_typesr¬   r­   r®   Úfloat32r´   r[   r\   rŒ   r�   rv   r¼   r°   r   )r¾   r§   Ú	out_dtypeÚcompute_dtypeÚweight_scalerÈ   rÉ   rÊ   rË   Úw_sumrÌ   rÍ   r   r   s   &&            r#   Ú_fit_line_weighted_tls_2drØ   x  s^  € ô
 ×#Ò# F§L¡L°'·-±-Ó@€IØ%.´5·=±=Ä%Ç.Á.Ð2QÔ%Q”E—M’MÐW`€MØ—i‘i Ó.°·
±
¸=Ó0IˆGð —;‘;“=×%Ñ%¨"°dÐ%Ó;€LØœŸš L°1Ñ$4°lÄEÇOÂOÐT`ÓDaÓbÕb€Gà	�
Õ	€BØ	�
Õ	€BØˆv�˜Õ€AØˆv�˜Õ€AØ�K‰K˜B¨ˆKÓ-€EØ�k×Ñ 2¨tÐÓ4°uÕ<€FØ�k×Ñ 2¨tÐÓ4°uÕ<€Fä! !¥*¨a­j¸'ÓB€IÜ�YŠY˜� R¥[Ð1°rÔ:€FÜ˜FŸI™I iÓ0°)·,±,¸yÓ2IÓJÐJr&   c                ór   € V ^8„  d   QhR\         P                  R\        \         P                  ,          RR/# )r   r¾   r§   r   Nr¨   )r!   s   "r#   r$   r$   ’  s/   € ÷ 'ñ '¤E§L¡Lð '¼8ÄEÇLÁLÕ;Qð 'ÐVZñ 'r&   c           	     ó$  € \         P                  P                  4       '       g!   \        4       '       g   \	        4       '       g   R# V P
                  R	,          pV^8  d   \        RV R24      h\        W R
,          8g  P                  R	4      P                  R4      P                  4       4      '       g   \        R4      h\        V\         P                  4      '       Ed/   VP
                  V P
                  R,          8X  Ed
   \        VP                  R4      ^ 8„  P                  4       4      '       g   \        R4      hV P                  R	VP                  R4      R,          P!                  R^V P
                  R,          4      4      p\        W8g  P                  R4      V^ 8„  ,          P                  R4      P                  4       4      '       g   \        R4      h\        V^ 8  P                  4       4      '       d   \        R4      hR# R# R# )at  Raise ``ValueCheckError`` when the point set cannot determine a line.

A line needs at least two points that are not all identical. Comparing every point with
the first one is exact at any scale; comparing with the mean is not, because its rounding
leaves a nonzero residual for identical points such as three copies of (0.1, 0.7). With
weights, the weighted mean is undefined unless the weight sum of every row is positive,
and a point with weight 0 does not count, so the same rule applies to the points with
positive weight, compared with the point of largest weight. Every weight must be
non-negative: a negative weight can make the weighted scatter indefinite, and then the
2-D and the D >= 3 branches disagree.

The value checks are skipped under ``torch.compile``/export, where they would be a
data-dependent branch, and by ``disable_checks()``, like every kornia value check.
NzHfit_line requires at least two points to determine a line; got a set of z
 point(s).zSfit_line requires at least two distinct points; the given points are all identical.:Nr   Nz^fit_line requires a positive sum of weights; the given weights do not sum to a positive value.zwfit_line requires at least two distinct points with positive weight; the points with positive weight are all identical.zcfit_line requires non-negative weights; a negative weight can make the weighted scatter indefinite.rª   ).rÂ   ºNNNrO   )rÛ   NN)r   rX   rY   r   r
   rP   r   rZ   ÚflattenÚanyr]   rf   r    rv   ÚgatherÚargmaxÚexpand)r¾   r§   ÚnÚrefs   &&  r#   Ú_reject_degenerate_linerã   ’  s¥  € ô ‡y�y×Ñ×Ò¤<§>¢>Ô9K×9MÒ9MÙØ�‰�RÕ€AØˆ1„uÜÐ hÐijÐhkÐkuÐvÓwÐwÜ� *Õ-Ñ-×6Ñ6°rÓ:×>Ñ>¸rÓB×FÑFÓH×IÒIÜÐsÓtÐtä�'œ5Ÿ<™<×(Ó(¨W¯]©]¸f¿l¹lÈ2Õ>NÕ-NÜ�W—[‘[ “_ qÑ(×-Ñ-Ó/×0Ò0Ü!Øpóð ð
 �m‰m˜B §¡¨rÓ 2°=Õ A× HÑ HÈÈQÐPV×P\ÑP\Ð]_ÕP`Ó aÓbˆÜ�f‘m×(Ñ(¨Ó,°¸!±Õ<×AÑAÀ"ÓE×IÑIÓK×LÒLÜ!ð,óð ô �˜1‘×!Ñ!Ó#×$Ò$Ü!Øuóð ñ %ñ .OÑ(r&   c                óz   € V ^8„  d   QhR\         P                  R\        \         P                  ,          R\        /# rÐ   )r   r    r   r   )r!   s   "r#   r$   r$   ¼  s4   € ÷ p/ñ p/”U—\‘\ð p/¬H´U·\±\Õ,Bð p/ÔN^ñ p/r&   c                ól  € \        V R4       \        V . RO4       V P                  w  r#pVe   \        VR4       \        WV.4       \	        W4       V^8X  d   Ve   \        W4      # \        V 4      # Vf   V P                  M*\        P                  ! V P                  VP                  4      pV\        P                  \        P                  39   d   \        P                  MTpV P                  V4      pVEe    VP                  V4      pVP                  4       P                  RRR7      p	V\        P                   ! V	^ 8„  V	\        P"                  ! V	4      4      ,          pVP%                  R4      R,          p
V
^ 8g  p\        P                   ! Wº\        P"                  ! V
4      4      p
\        P                   ! VVR	,          V,          P%                  R
RR7      V
,          VP'                  R
R4      4      pMVP'                  R
R4      pW|,
          pVP                  4       P                  RRR7      pV\        P                   ! V^ 8„  V\        P"                  ! V4      4      ,          pVe(   VP)                  R
R4      XR,          ,          V,          MVP)                  R
R4      V,          pVP+                  4       P                  \-        V4      4      p\/        V4      w  ppp\1        VVV^ 4      P                  V4      P                  V4      pVR,          P                  V4      p\3        VV4      # )u¢  Fit a line to each of B point sets in any dimension by weighted total least squares.

``line = fit_line(points, weights)`` takes ``B`` sets of ``N`` points ``(B, N, D)`` in any dimension ``D``, and
optional non-negative per-point weights ``(B, N)``, and returns a :class:`ParametrizedLine` whose origin and unit
direction are ``(B, D)``: for each set, the line through the centroid that minimises the sum of squared
perpendicular distances, both weighted when ``weights`` are given. A single set ``(N, D)`` raises ``ShapeError``:
pass ``points[None]``. Every point with a positive weight pulls on the fit, so down-weight outliers or remove them
first. For a plane through 3D points, use :func:`~kornia.geometry.plane.fit_plane` instead.

Convention:
    - Returns a :class:`ParametrizedLine` (see its conventions) through the centroid of the points, weighted
      when ``weights`` are given, whose unit direction minimises the (weighted) sum of squared perpendicular
      distances to the points, for every dimensionality. Each batch row is fitted on its own.
    - For 2-D points the direction is computed in closed form and has a non-negative x component, so an exactly
      vertical line gets the direction ``(0, 1)`` up to rounding. For :math:`D \ge 3` it is the principal
      direction of the scatter matrix, whose sign is not specified.
    - The output has the promoted dtype of ``points`` and ``weights``; float16 and bfloat16 inputs are fitted in
      float32 and the line is cast back.

Args:
    points: tensor containing a batch of sets of n-dimensional points. The expected
        shape of the tensor is ``(B, N, D)``.
    weights: per-point weights, used in the centroid and in the fit. The expected
        shape of the tensor is ``(B, N)``, with the same ``B`` and ``N`` as ``points``.

Return:
    The fitted line, with origin and direction of shape ``(B, D)``.

Raises:
    TypeCheckError: if ``points`` or ``weights`` is not a tensor.
    ShapeError: if ``points`` is not of shape ``(B, N, D)``, or ``weights`` is not of shape ``(B, N)`` with the
        same ``B`` and ``N`` as ``points``, a ``(B, 1)`` tensor included.
    ValueCheckError: if the points do not determine a line â€” fewer than two points,
        all points identical, or (with weights) a zero weight sum, a negative weight, or all
        points with positive weight identical. Like every kornia value check, these are skipped under
        ``torch.compile`` and by ``disable_checks()``.

See Also:
    - :class:`ParametrizedLine`: the returned line, which can also be built from an origin and a direction or
      through two points.
    - :func:`~kornia.geometry.plane.fit_plane`: the same total least squares for a plane through 3D points,
      unweighted, and for a set ``(N, 3)`` as well as a batch.

Example:
    >>> points = torch.rand(2, 10, 3)
    >>> weights = torch.ones(2, 10)
    >>> line = fit_line(points, weights)
    >>> line.direction.shape
    torch.Size([2, 3])
zpoints must be a tensorzweights must be a tensorTrƒ   )r„   )ÚBÚNÚDrO   ).NNre   rª   )rª   rO   ).NrÛ   ).rÃ   rÛ   )r   r   rP   r	   rã   rØ   rÎ   r¬   r   rÒ   r­   r®   rÓ   r´   r[   r\   rŒ   r�   rv   rÇ   Ú	transposeÚdetachr   r   r   r   )r¾   r§   ræ   rç   rè   rÔ   rÕ   Úwork_pointsÚwork_weightsrÖ   r×   Ú
has_weightrÇ   ÚArµ   ÚworkÚ_ÚSÚVr   r   s   &&                   r#   r   r   ¼  s©  € ôf ˜6Ð#<Ô=Ü�všÔ/à�l‰l�G€Aˆ!ð
 ÒÜ˜wÐ(BÔCÜ˜7¨ FÔ+ä˜FÔ,ð 	ˆA„vØÒÜ,¨VÓ=Ð=Ü Ó'Ð'ð
 !(¢�—’´U×5HÒ5HÈÏÉÐW^×WdÑWdÓ5e€IØ%.´5·=±=Ä%Ç.Á.Ð2QÔ%Q”E—M’MÐW`€MØ—)‘)˜MÓ*€KàÓØ—z‘z -Ó0ˆØ#×'Ñ'Ó)×.Ñ.°2¸tÐ.ÓDˆØ#¤e§k¢k°,ÀÑ2BÀLÔRW×RaÒRaÐbnÓRoÓ&pÕpˆð × Ñ  Ó$ _Õ5ˆØ˜a‘Zˆ
Ü—’˜J¬u¯ª¸uÓ/EÓFˆÜ�{Š{ØØ˜)Õ$ {Õ2×7Ñ7¸ÀDÐ7ÓIÈEÕQØ×Ñ˜R Ó&ó
‰ð ×Ñ  DÓ)ˆàÕ€AØ�E‰E‹G�L‰L˜X¨tˆLÓ4€EØ	ŒE�KŠK˜ ™	 5¬%¯/ª/¸%Ó*@ÓAÕA€AàBIÒBUˆ�‰�R˜Ó	˜|¨LÕ9Õ	9¸QÖ>Ð[\×[fÑ[fÐgiÐkmÓ[nÐqrÕ[r€Að �8‰8‹:�=‰=œ¨Ó+Ó,€DÜ˜dÓ#�G€A€qˆ!ô ' q¨!¨Q°Ó2×5Ñ5°mÓD×GÑGÈ	ÓR€IØ�)�_×Ñ 	Ó*€Fä˜F IÓ.Ð.r&   r:   )'r�   r²   Útypingr   r   r   r   r   r   Úkornia.core.checkr   r   r	   r
   Úkornia.core.exceptionsr   Úkornia.core.utilsr   r   r   r   r   r   Úkornia.geometry.conversionsr   Úkornia.geometry.linalgr   Úkornia.geometry.planer   Úkornia.geometry.vectorr   Ú__all__ÚModuler   r¼   rÎ   rØ   rã   r   r˜   r&   r#   Ú<module>rý      s~   ðñ$ó( ß 3Ó 3ã Ý ç pÓ pÝ 2÷÷ õ <Ý 6Ý ,Ý )à˜zÐ
*€ô~%�r—y‘yô ~%õB\õBCõ0Kõ4'÷Tp/ñ p/r&   