class_docstr: Class matching two sets of line segments with the Needleman-Wunsch algorithm.
  
  TODO: move it later in kornia.feature.matching
class_docstr_tok: ["Class","matching","two","sets","of","line","segments","with","the","Needleman-Wunsch","algorithm",".","TODO",":","move","it","later","in","kornia.feature.matching"]
docstr: 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.
  Inputs:
      scores: a (B, N, M) Tensor containing the pairwise scores
              of the elements to match.
docstr_tok: ["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",".","Inputs",":","scores",":","a","(","B",",","N",",","M",")","Tensor","containing","the","pairwise","scores","of","the","elements","to","match","."]
code: def needleman_wunsch(self, scores: Tensor) -> Tensor:
      """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.
      Inputs:
          scores: a (B, N, M) Tensor containing the pairwise scores
                  of the elements to match.
      """
      KORNIA_CHECK_SHAPE(scores, ["B", "N", "M"])
      b, n, m = scores.shape
  
      # Recalibrate the scores to get a gap score of 0
      gap = 0.1
      nw_scores = scores - gap
      dev = scores.device
      # Run the dynamic programming algorithm
      nw_grid = torch.zeros(
          b, n + 1, m + 1, dtype=torch.float, device=dev
      )
      for i in range(n):
          for j in range(m):
              nw_grid[:, i + 1, j + 1] = torch.maximum(
                  torch.maximum(
                      nw_grid[:, i + 1, j], nw_grid[:, i, j + 1]
                  ),
                  nw_grid[:, i, j] + nw_scores[:, i, j],
              )
  
      return nw_grid[:, -1, -1]
  
imports: from typing import Any, Dict, Optional, Tuple
  import torch
  import torch.nn.functional
  from kornia.core import Module, Tensor, concatenate, pad, stack
  from kornia.core.check import KORNIA_CHECK_SHAPE
  from kornia.geometry.conversions import normalize_pixel_coordinates
  from kornia.utils import map_location_to_cpu
  from .backbones import SOLD2Net
  from .sold2_detector import LineSegmentDetectionModule, line_map_to_segments, prob_to_junctions
label_desc: Use image node_id 5 for calling the WunschLineMatcher obj's underlying member method code with example usage: obj.needleman_wunsch(scores) and returns: nw_grid