+
    åûj0J  ã                   ó  € ^ RI t ^ RIHtHtHtHtHtHt ^ RIt^ RI	H
u Ht ^ RIH
t
 ^ RIHt ^ RIHt ^ RIHtHt ^ RIHtHt ^RIHt ^R	IHtHtHtHt  ! R
 R]
P<                  4      t ! R R]
P<                  4      t R R lt!R R lt"R# )é    N)ÚAnyÚDictÚOptionalÚTupleÚUnionÚcast)Únn)ÚKORNIA_CHECK_SHAPE)Úload_state_dict_from_url)Údataclass_to_dictÚdict_to_dataclass)ÚDetectorCfgÚLineMatcherCfg)ÚSOLD2Net)ÚLineSegmentDetectionModuleÚline_map_to_segmentsÚprob_to_junctionsÚurlsc                   ó|   a a€ ] tR t^"t oRtRV3R lV 3R llltV3R lR ltV3R lR ltV3R lR	 ltR
t	Vt
V ;t# )ÚSOLD2uÆ  Detect, describe and match line segments in grayscale images with SOLD2.

``sold2 = SOLD2()`` builds the network with its pretrained weights, in eval mode, and ``outputs = sold2(images)``
takes grayscale images ``(B, 1, H, W)`` in :math:`[0, 1]`, with ``H`` and ``W`` multiples of 8, and returns a dict:
``"line_segments"``, one ``(N, 2, 2)`` tensor of ``(row, col)`` endpoints in pixels per image, the
``"junction_heatmap"`` and ``"line_heatmap"``, ``(B, H, W)`` each, and the ``"dense_desc"`` map
``(B, 128, H / 4, W / 4)``. ``matches = sold2.match(line_seg1, line_seg2, desc1, desc2)`` then matches the
segments of two images by their descriptors sampled along each segment, with ``desc1`` and ``desc2`` the
``(1, 128, H / 4, W / 4)`` maps of one image each, and returns for each segment of ``line_seg1`` the index of its
match in ``line_seg2``, or ``-1``. To detect segments only, use :class:`SOLD2_detector` instead, which builds no
descriptor head. This is based on the original code from the paper "SOLDÂ²: Self-supervised Occlusion-aware Line
Detector and Descriptor". See :cite:`SOLD22021` for more details.

Convention:
    - :meth:`forward` takes the input and returns the heatmaps and the ``(row, col)`` line segments of
      :class:`~kornia.feature.SOLD2_detector`, whose Convention block gives their frame and order, and also
      ``dense_desc``, ``(B, 128, H / 4, W / 4)``, which is not normalized.
    - ``match`` takes segments as :meth:`forward` returns them and the descriptor map of one image each. It
      returns an int64 tensor ``(N_1,)``: for each segment of ``line_seg1``, the index of its match in
      ``line_seg2``, or ``-1``. It is int64 also when either set of segments is empty: an empty tensor when
      ``line_seg1`` is, ``-1`` for every segment of ``line_seg1`` when ``line_seg2`` is.
    - Known defects: on CPU, ``match`` passes float16 and bfloat16 descriptor maps to torch's ``grid_sample``
      without an upcast: the half-precision kernel can return wrong values, NaN or overflow, and where torch has
      none the call raises (`#5810 <https://github.com/kornia/kornia/issues/5810>`_).

Args:
    pretrained: If True, download and set pretrained weights to the model, and return it in eval mode; otherwise
        the weights are random and the model is in training mode.
    config: a ``kornia.feature.sold2.structures.DetectorCfg``, or a dict of its fields, specifying parameters.
        None will load the default parameters, which are tuned for images in the range 400~800 px.
        The model works on a copy with ``use_descriptor`` set to True; the object passed in is not modified.

Returns:
    The raw junction and line heatmaps, the semi-dense descriptor map,
    as well as the list of detected line segments (ij coordinates convention).

See Also:
    - :class:`SOLD2_detector`: the same line detection, without the descriptor map or matching.

Example:
    >>> images = torch.rand(2, 1, 64, 64)
    >>> sold2 = SOLD2()
    >>> outputs = sold2(images)
    >>> line_seg1 = outputs["line_segments"][0]
    >>> line_seg2 = outputs["line_segments"][1]
    >>> desc1 = outputs["dense_desc"][0]
    >>> desc2 = outputs["dense_desc"][1]
    >>> matches = sold2.match(line_seg1, line_seg2, desc1[None], desc2[None])

c          	      óf   <€ V ^8„  d   QhRS[ RS[S[S[S[S[S[3,          3,          ,          RR/# )é   Ú
pretrainedÚconfigÚreturnN)Úboolr   r   r   r   Ústrr   )ÚformatÚ__classdict__s   "€ÚVC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\sold2\sold2.pyÚ__annotate__ÚSOLD2.__annotate__V   s?   ø€ ÷ ñ ¡4ð ¹ÁÁ{ÑTXÑY\Ñ^aÐYaÕTbÐGbÕAcÕ8dð Ðptñ ó    c                óœ  <€ \        V\        4      '       d0   \        \        \        \
        \        3,          V4      \        4      p\        SV `%  4        Ve   \        P                  ! V4      M	\        4       V n        RV P                  n        V P                  P                  V n        V P                  P                  V n        V P                  P"                  V n        \%        \'        V P                  4      4      V n        V'       d`   \+        \,        R,          \.        P0                  ! R4      R7      pV P3                  VR,          4      pV P(                  P5                  V4       \7        V P                  P8                  4      V n        \=        V P                  P>                  4      V n         V'       d   V PC                  4        R # R # )NTÚ	wireframeÚcpu)Úmap_locationÚmodel_state_dict)"Ú
isinstanceÚdictr   r   r   r   r   r   ÚsuperÚ__init__ÚcopyÚdeepcopyr   Úuse_descriptorÚ	grid_sizeÚdetection_threshÚjunc_detect_threshÚmax_num_junctionsr   r   Úmodelr   r   ÚtorchÚdeviceÚadapt_state_dictÚload_state_dictr   Úline_detector_cfgÚline_detectorÚWunschLineMatcherÚline_matcher_cfgÚline_matcherÚeval)Úselfr   r   Úpretrained_dictÚ
state_dictÚ	__class__s   &&&  €r    r,   ÚSOLD2.__init__V   s6  ø€ Ü�fœd×#Ò#Ü&¤t¬D´´c°­N¸FÓ'CÄ[ÓQˆFÜ‰ÑÔð 06Ò/A”d—m’m FÔ+Ä{Ã}ˆŒØ%)ˆ�‰Ô"ØŸ™×.Ñ.ˆŒØ"&§+¡+×">Ñ">ˆÔØ!%§¡×!>Ñ!>ˆÔô Ô/°·±Ó<Ó=ˆŒ
ßÜ6´t¸KÕ7HÔW\×WcÒWcÐdiÓWjÔkˆOØ×.Ñ.¨Ð?QÕ/RÓSˆJØ�J‰J×&Ñ& zÔ2ô 8¸¿¹×8UÑ8UÓVˆÔô .¨d¯k©k×.JÑ.JÓKˆÔßØ�I‰IŽKñ r#   c                óP   <€ V ^8„  d   QhRS[ P                  RS[S[S[3,          /# )r   Úimgr   )r5   ÚTensorr   r   r   )r   r   s   "€r    r!   r"   q   s'   ø€ ÷ !ñ !™5Ÿ<™<ð !©D±±c°­Nñ !r#   c                ó¨  € \        V. RO4       / pV P                  V4      pVR,          VR&   VR,          VR&   VR,          VR&   . p\        VR,          VR,          4       Fh  w  rV\        WPP                  V P
                  V P                  4      pV P                  P                  Wv4      w  r‡p	VP                  \        Wx4      4       Kj  	  WBR&   V# )	a~  Run forward.

Args:
    img: batched images with shape ``(B, 1, H, W)``.

Returns:
    line_segments: a list of ``B`` tensors ``(N, 2, 2)``, the N line segments of each image.
    junction_heatmap: raw junction heatmap of shape ``(B, H, W)``.
    line_heatmap: raw line heatmap of shape ``(B, H, W)``.
    dense_desc: the semi-dense descriptor map of shape ``(B, 128, H/4, W/4)``.

Ú	junctionsÚjunction_heatmapÚheatmapÚline_heatmapÚdescriptorsÚ
dense_descÚline_segments)ÚBÚ1ÚHÚW)r
   r4   Úzipr   r0   r2   r3   r:   ÚdetectÚappendr   )
r?   rE   ÚoutputsÚnet_outputsÚlinesÚ	junc_probrJ   rH   Úline_mapÚ_s
   &&        r    ÚforwardÚSOLD2.forwardq   sÔ   € ô 	˜3Ò 4Ô5Øˆð —j‘j “oˆØ&1°+Õ&>ˆÐ"Ñ#Ø"-¨iÕ"8ˆ�ÑØ +¨MÕ :ˆ�Ñð ˆÜ"% k°+Õ&>ÀÈIÕ@VÖ"WÑˆIä)¨)·^±^ÀT×E\ÑE\Ð^b×^tÑ^tÓuˆIð &*×%7Ñ%7×%>Ñ%>¸yÓ%RÑ"ˆH Ø�L‰LÔ-¨iÓBÖCñ #Xð $)�Ñ àˆr#   c          
      óœ   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[ P                  RS[ P                  /# ©r   Ú	line_seg1Ú	line_seg2Údesc1Údesc2r   ©r5   rF   )r   r   s   "€r    r!   r"   ”   sR   ø€ ÷ Eñ EÙŸ™ðEÙ27·,±,ðEÙGLÇ|Á|ðEÙ\a×\hÑ\hðEá	�‰ñEr#   c                ó&   € V P                  WW44      # )aÀ  Find the best matches between two sets of line segments and their corresponding descriptors.

Each descriptor map is sampled in its own dtype, so the segments may be in another floating-point dtype.

Args:
    line_seg1: list of line segments in image 1, with shape [num_lines, 2, 2].
    line_seg2: list of line segments in image 2, with shape [num_lines, 2, 2].
    desc1: semi-dense descriptor map of image 1, with shape [1, 128, H/4, W/4].
    desc2: semi-dense descriptor map of image 2, with shape [1, 128, H/4, W/4].

Returns:
    An integer tensor of size [num_lines1] indicating the index in line_seg2 of the matched line,
    for each line in line_seg1. -1 means that the line is not matched.

)r=   )r?   r`   ra   rb   rc   s   &&&&&r    ÚmatchÚSOLD2.match”   s   € ð$ × Ñ  °uÓDÐDr#   c                óR   <€ V ^8„  d   QhRS[ S[S[3,          RS[ S[S[3,          /# )r   rA   r   )r   r   r   )r   r   s   "€r    r!   r"   ¨   s+   ø€ ÷ ñ ©4±±S°­>ð ¹dÁ3ÉÀ8½nñ r#   c                óT   € VR VR VR VR,          VR&   VR,          VR&   VR VR V# )a  Adapt pretrained checkpoint keys to this module implementation.

Args:
    state_dict: Checkpoint state dictionary whose keys are adapted to this module layout.

Returns:
    State dictionary with checkpoint keys renamed or removed so it can be loaded by the current module.
Úw_juncÚ	w_heatmapÚw_descz'heatmap_decoder.conv_block_lst.2.weightz)heatmap_decoder.conv_block_lst.2.0.weightz%heatmap_decoder.conv_block_lst.2.biasz'heatmap_decoder.conv_block_lst.2.0.bias© )r?   rA   s   &&r    r7   ÚSOLD2.adapt_state_dict¨   sV   € ð �xÐ Ø�{Ð#Ø�xÐ ØBLÐMvÕBwˆ
Ð>Ñ?Ø@JÐKrÕ@sˆ
Ð<Ñ=ØÐ@ÐAØÐ>Ð?ØÐr#   )r   r0   r2   r:   r=   r3   r4   )TN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r,   r\   rf   r7   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©rB   r   s   @@r    r   r   "   s;   ù‡ € ñ1÷fõ ÷6!ð !÷FEð E÷(÷ ð r#   r   c                   óŽ   a a€ ] tR t^»t oRtRV3R lV 3R l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	Rt
VtV ;t# )r;   z~Class matching two sets of line segments with the Needleman-Wunsch algorithm.

TODO: move it later in kornia.feature.matching
c                ó4   <€ V ^8„  d   QhRS[ S[,          RR/# )r   r   r   N)r   r   )r   r   s   "€r    r!   ÚWunschLineMatcher.__annotate__Á   s    ø€ ÷ 1ñ 1™x©Õ7ð 1À4ñ 1r#   c                ó�  <€ \         SV `  4        Vf   \        4       pWn        V P                  P                  V n        V P                  P
                  V n        V P                  P                  V n        V P                  P                  V n        V P                  P                  V n        V P                  P                  V n	        R # ©N)
r+   r,   r   r   Úcross_checkÚnum_samplesÚmin_dist_ptsÚtop_k_candidatesr0   Ú
line_score)r?   r   rB   s   &&€r    r,   ÚWunschLineMatcher.__init__Á   sŠ   ø€ Ü‰ÑÔàŠ>Ü#Ó%ˆFØŒØŸ;™;×2Ñ2ˆÔØŸ;™;×2Ñ2ˆÔØ ŸK™K×4Ñ4ˆÔØ $§¡× <Ñ <ˆÔØŸ™×.Ñ.ˆŒØŸ+™+×0Ñ0ˆŽr#   c          
      óœ   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[ P                  RS[ P                  /# r_   rd   )r   r   s   "€r    r!   rz   Î   sK   ø€ ÷ 1ñ 1ÙŸ™ð1Ù27·,±,ð1ÙGLÇ|Á|ð1Ù\a×\hÑ\hð1á	�‰ñ1r#   c                ó   € \        V. RO4       \        V. RO4       \        V. RO4       \        V. RO4       VP                  pVP                  ^,          V P                  ,          VP                  ^,          V P                  ,          3pVP                  ^,          V P                  ,          VP                  ^,          V P                  ,          3p\	        V4      ^ 8X  d(   \
        P                  ! ^ \
        P                  VR7      # \	        V4      ^ 8X  d2   \
        P                  ! \	        V4      \
        P                  VR7      ) # V P                  V4      w  r‰V P                  V4      w  r«VP                  R	^4      pV
P                  R	^4      p
\        W†4      P                  VP                  4      p\        W§4      P                  VP                  4      p\        P                  ! \        P                   ! W<RR7      R
,          ^ R7      p\        P                  ! \        P                   ! WMRR7      R
,          ^ R7      pVP#                  4       V,          pR	WéP%                  4       ( &   R	VRVP%                  4       ( 3&   VP                  \	        V4      V P&                  \	        V4      V P&                  4      pVP)                  ^ ^^^4      pV P+                  V4      pV P,                  '       dU   V P+                  VP)                  ^^ ^^4      4      pVV,          \
        P.                  ! \	        V4      VR7      8H  pR	VV( &   V# )z\Find the best matches between two sets of line segments and their corresponding descriptors.©Údtyper6   F)Úalign_cornersºNNN©Údim©r6   )ÚNÚ2r�   )rO   ÚDrQ   rQ   éÿÿÿÿ)r   rˆ   rˆ   r   )r
   r6   Úshaper0   Úlenr5   ÚemptyÚlongÚonesÚsample_line_pointsÚreshapeÚkeypoints_to_gridÚtor†   ÚFÚ	normalizeÚgrid_sampleÚtÚflattenr~   ÚpermuteÚfilter_and_match_linesr}   Úarange)r?   r`   ra   rb   rc   r6   Ú	img_size1Ú	img_size2Úline_points1Úvalid_points1Úline_points2Úvalid_points2Úgrid1Úgrid2ÚscoresÚmatchesÚmatches2Úmutuals   &&&&&             r    r\   ÚWunschLineMatcher.forwardÎ   sŒ  € ô 	˜9¢oÔ6Ü˜9¢oÔ6Ü˜5Ò"6Ô7Ü˜5Ò"6Ô7Ø—‘ˆØ—[‘[ •^ d§n¡nÕ4°e·k±kÀ!µnÀtÇ~Á~Õ6UÐVˆ	Ø—[‘[ •^ d§n¡nÕ4°e·k±kÀ!µnÀtÇ~Á~Õ6UÐVˆ	ô ˆy‹>˜QÔÜ—;’;˜q¬¯
©
¸6ÔBÐBÜˆy‹>˜QÔÜ—J’Jœs 9›~´U·Z±ZÈÔOÐOÐOð '+×&=Ñ&=¸iÓ&HÑ#ˆØ&*×&=Ñ&=¸iÓ&HÑ#ˆØ#×+Ñ+¨B°Ó2ˆØ#×+Ñ+¨B°Ó2ˆô " ,Ó:×=Ñ=¸e¿k¹kÓJˆÜ! ,Ó:×=Ñ=¸e¿k¹kÓJˆÜ—’œAŸMšM¨%ÀeÔLÈZÕXÐ^_Ô`ˆÜ—’œAŸMšM¨%ÀeÔLÈZÕXÐ^_Ô`ˆð —‘“˜UÕ"ˆØ+-ˆ×%Ñ%Ó'Ð'Ñ(Ø.0ˆˆq�=×(Ñ(Ó*Ð*Ð*Ñ+Ø—‘¤ I£°×0@Ñ0@Ä#ÀiÃ.ÐRV×RbÑRbÓcˆØ—‘  1 a¨Ó+ˆð ×-Ñ-¨fÓ5ˆð ××ÐØ×2Ñ2°6·>±>À!ÀQÈÈ1Ó3MÓNˆHØ˜gÕ&¬%¯,ª,´s¸9³~ÈfÔ*UÑUˆFØ!ˆG�V�GÑàˆr#   c                óx   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  S[ P                  3,          /# )r   Úline_segr   )r5   rF   r   )r   r   s   "€r    r!   rz     s4   ø€ ÷ ñ ©5¯<©<ð ¹EÁ%Ç,Á,ÑPU×P\ÑP\ÐB\Õ<]ñ r#   c                óê  € VP                   w  p pV P                  pVP                  p\        P                  ! VR,          VR,          ,
          ^R7      p\        P
                  ! W`P                  ,          P                  4       P                  4       ^VR7      pVR,          P                  ^4      pVR,          VR,          ,
          P                  ^4      p	\        P                  ! WER7      P                  ^ 4      p
V^,
          P                  ^4      pW«,          pW‰VP                  R4      ,          ,           pW§P                  ^4      8  pVP                  VP                  R4      ( R4      pWÞ3# )a  Regularly sample points along each line segments, with a minimal distance between each point.

Pad the remaining points.

Args:
    line_seg: an Nx2x2 torch.Tensor.

Returns:
    line_points: an N x num_samples x 2 torch.Tensor.
    valid_points: a boolean N x num_samples torch.Tensor.
r‰   )ÚminÚmaxr‹   g        )rˆ   r   )rˆ   é   r�   )r�   r~   r6   r5   ÚnormÚclampr   ÚfloorÚintÚ	unsqueezer    Úmasked_fill)r?   r¯   Ú_Nr[   ÚMÚdevÚlengthsÚnum_ptsÚorigÚdirsÚidxÚdenomÚalphaÚptsÚvalids   &&             r    r•   Ú$WunschLineMatcher.sample_line_points  s$  € ð —>‘>‰ˆˆAˆqØ×ÑˆØ�o‰oˆä—*’*˜X d�^¨h°t­nÕ<À!ÔDˆÜ—+’+˜w×):Ñ):Õ:×AÑAÓC×GÑGÓIÈqÐVWÔXˆà˜�~×'Ñ'¨Ó*ˆØ˜• ¨$¥Õ/×:Ñ:¸1Ó=ˆÜ�lŠl˜1Ô)×3Ñ3°AÓ6ˆØ˜1•×'Ñ'¨Ó*ˆØ•ˆØ˜EŸO™O¨BÓ/Õ/Õ/ˆØ×'Ñ'¨Ó*Ñ*ˆØ�o‰o˜uŸ™¨rÓ2Ð2°CÓ8ˆàˆzÐr#   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   r©   r   rd   )r   r   s   "€r    r!   rz     s#   ø€ ÷ %;ñ %;©U¯\©\ð %;¹e¿l¹lñ %;r#   c                ó˜  € \        V. RO4       VP                  ^4      ^ ,          pVR8g  pW#,          P                  ^4      VP                  ^4      ,          pVP                  ^4      ^ ,          pVR8g  pWE,          P                  ^4      VP                  ^4      ,          pW$,           ^,          p\        P                  ! V^R7      RV P
                  ) R13,          p\        P                  ! WR,          ^R7      p\        P                  ! V\        P                  ! VR.R7      .^4      pVP                  w  ršr¼VP                  Wš,          W¼34      pV P                  V4      pVP                  Wš4      p\        P                  ! \        P                  ! V^R7      V
^,          4      pV\        P                  ! V	4      V3,          # )aN  Use scores to keep the top k best lines.

Compute the Needleman- Wunsch algorithm on each candidate pairs, and keep the highest score.

Args:
    scores: a (N, M, n, n) torch.Tensor containing the pairwise scores
            of the elements to match.

Returns:
    matches: a (N) torch.Tensor containing the indices of the best match
r‰   rˆ   N)Údims)r»   rŒ   ÚnrË   r�   )rˆ   rˆ   NN)r
   r²   Úsumr5   Úargsortr€   Útake_along_dimÚcatÚflipr�   r–   Úneedleman_wunschÚ	remainderÚargmaxr    )r?   r©   Úline_scores1Úvalid_scores1Úline_scores2Úvalid_scores2Úline_scoresÚ
topk_linesÚ
top_scoresÚn_lines1Útop2krË   ÚmÚ	nw_scoresrª   s   &&             r    rŸ   Ú(WunschLineMatcher.filter_and_match_lines  s†  € ô 	˜6Ò#7Ô8ð —z‘z !“} QÕ'ˆØ$¨Ñ*ˆØ$Õ4×9Ñ9¸!Ó<¸}×?PÑ?PÐQRÓ?SÕSˆØ—z‘z !“} QÕ'ˆØ$¨Ñ*ˆØ$Õ4×9Ñ9¸!Ó<¸}×?PÑ?PÐQRÓ?SÕSˆØ#Õ2°aÕ7ˆÜ—]’] ;°AÔ6°q¸4×;PÑ;PÐ:PÑ:RÐ7RÕSˆ
ô ×)Ò)¨&Ð=MÕ2NÐTUÔVˆ
ô —Y’Y 
¬E¯JªJ°zÈÈÔ,MÐNÐPQÓRˆ
ð !+× 0Ñ 0Ñˆ˜Ø×'Ñ'¨Õ)9¸1Ð(@ÓAˆ
Ø×)Ñ)¨*Ó5ˆ	Ø×%Ñ% hÓ6ˆ	Ü—/’/¤%§,¢,¨y¸aÔ"@À%È1Å*ÓMˆØœ%Ÿ,š, xÓ0°'Ð9Õ:Ð:r#   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rÈ   rd   )r   r   s   "€r    r!   rz   F  s#   ø€ ÷ ñ ¡u§|¡|ð ¹¿¹ñ r#   c                óà  € \        V. RO4       RpVP                  w  r4p\        P                  ! W4^,           V^,           VP                  VP
                  R7      pW,
          p\        ^WE,           ^,           4       Fæ  p\        ^W…,
          4      p	\        WH^,
          4      p
\        P                  ! Wš^,           VP                  R7      pW‹,
          pVRV^,
          V3,          pVRW¼^,
          3,          pVRV^,
          V^,
          3,          VRV^,
          V^,
          3,          ,           p\        P                  ! \        P                  ! WÞ4      V4      VRW¼3&   Kè  	  VR,          # )a  Batched implementation of the Needleman-Wunsch algorithm.

The cost of the InDel operation is set to 0 by subtracting the gap
penalty to the scores.

Args:
    scores: a (B, N, M) torch.Tensor containing the pairwise scores
            of the elements to match.
gš™™™™™¹?)r6   r†   r‹   rˆ   )rO   rŒ   r»   )rˆ   r�   r�   )
r
   r�   r5   Úzerosr6   r†   Úranger²   r±   r    )r?   r©   ÚgaprO   rŒ   r»   ÚdpÚSÚkÚi_minÚi_maxÚiÚjÚupÚleftÚdiags   &&              r    rÑ   Ú"WunschLineMatcher.needleman_wunschF  s  € ô 	˜6¢?Ô3àˆØ—,‘,‰ˆˆaÜ�[Š[˜ �E 1 q¥5°·±ÀfÇlÁlÔSˆØ�LˆÜ�q˜!�% !�)Ö$ˆAÜ˜˜1�5“MˆEÜ˜˜q�5“MˆEÜ—’˜U¨A¥I°f·m±mÔDˆAØ•ˆAØ�A�q˜1•u˜a�K•ˆBØ�a˜ �E�k•?ˆDØ�a˜˜Q�  A¥�oÕ&¨¨1¨a°!­e°Q¸µU¨?Õ);Õ;ˆDÜŸ)š)¤E§I¢I¨bÓ$7¸Ó>ˆBˆq�!ˆw‹Kñ %ð �)�}Ðr#   )r   r}   r0   r�   r   r~   r€   r|   )ro   rp   rq   rr   rs   r,   r\   r•   rŸ   rÑ   rt   ru   rv   rw   s   @@r    r;   r;   »   sC   ù‡ € ñ÷
1õ 1÷1ð 1÷fð ÷<%;ð %;÷N÷ ð r#   r;   c                ó†   € V ^8„  d   QhR\         P                  R\        \        \        3,          R\         P                  /# )r   Ú	keypointsÚimg_sizer   )r5   rF   r   r·   )r   s   "r    r!   r!   b  s6   € ÷ yñ y¤§¡ð y¼¼sÄC¸x½ð yÌUÏ\É\ñ yr#   c                óÚ   € \        V RR.4       \        V 4      pV R,          \        P                  ! WP                  R7      ,          R,
          R^^ .3,          P                  RV^^4      # )u  Convert a list of keypoints into a grid in [-1, 1]Â² that can be used in torch.nn.functional.grid_sample.

The normalization is the reference implementation's ``keypoints * 2 / img_size - 1``
(cvg/SOLD2, ``sold2/misc/geometry_utils.py``), the convention the pretrained weights were trained
with. It pairs with the ``align_corners=False`` sampling in :class:`WunschLineMatcher`: image pixel
``p`` on an axis of size ``S`` lands on descriptor-map coordinate ``p * S_desc / S - 0.5``, which is
``p / grid_size - 0.5`` whatever ``img_size`` is, so ``p = grid_size * (i + 0.5)`` reads descriptor
``i`` exactly. It is deliberately not
:func:`kornia.geometry.conversions.normalize_pixel_coordinates`, whose corner-aligned mapping
``2p / (S - 1) - 1`` drifts by ``p / (S - 1)`` image pixels toward the far edge under this sampler.
It is also not the half-pixel mapping ``(2p + 1) / S - 1``, from which it differs by a constant
half image pixel at every ``p``. Changing either the formula or the ``align_corners`` of the
sampler would break compatibility with the pretrained weights (compare
:class:`~kornia.feature.XFeat` and its ``normgrid``, which keep their own trained pairing).

Args:
    keypoints: a torch.Tensor [N, 2] of N keypoints (ij coordinates convention).
    img_size: the original image size (H, W)

rŒ   r�   g       @r‹   g      ð?rˆ   r�   )r
   r‘   r5   Útensorr6   Úview)rñ   rò   Ún_pointss   && r    r—   r—   b  sf   € ô* �y 3¨ *Ô-Ü�9‹~€HØ˜�OœeŸlšl¨8×<LÑ<LÔMÕMÐPSÕSÐUVÐYZÐ\]ÐX^ÐU^Õ_×dÑdÐegÐiqÐstÐvwÓxÐxr#   c          
      ó�   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        R\         P                  /# )r   ÚstartÚendÚsteprŠ   r   )r5   rF   r·   )r   s   "r    r!   r!   |  s>   € ÷ 6ñ 6œEŸL™Lð 6¬u¯|©|ð 6Ä3ð 6ÌSð 6ÔUZ×UaÑUañ 6r#   c                óJ  € W,
          V^,
          ,          P                  V4      p^.\        VP                  4      ,          pW%V&   \        P                  ! V\        P
                  V P                  R7      P                  V4      pV P                  V4      Wd,          ,           # )z;Batch version of torch.linspace (similar to the numpy one).r…   )r¸   r‘   r�   r5   r    Úfloatr6   r–   )rø   rù   rú   rŠ   Ú	intervalsÚbroadcast_sizeÚsampless   &&&&   r    Úbatched_linspacer   |  sw   € à•+ $¨¥(Õ+×6Ñ6°sÓ;€IØ�Sœ3˜yŸ™Ó/Õ/€NØ�3ÑÜ�lŠl˜4¤u§{¡{¸5¿<¹<ÔH×PÑPÐQ_Ó`€GØ�?‰?˜3Ó 'Õ"5Õ5Ð5r#   )#r-   Útypingr   r   r   r   r   r   r5   Útorch.nn.functionalr	   Ú
functionalr™   Úkornia.core.checkr
   Úkornia.core.downloadr   Úkornia.core.utilsr   r   Úkornia.feature.sold2.structuresr   r   Ú	backbonesr   Úsold2_detectorr   r   r   r   ÚModuler   r;   r—   r   rm   r#   r    Ú<module>r     sb   ðó$ ß :× :ã ß Ð Ý å 0Ý 9ß Bß Gå ß eÓ eôVˆB�I‰Iô Vôrd˜Ÿ	™	ô dõNy÷46r#   