code: def stable_sort_residuals(
      residuals: Tensor, ransidx: Tensor
  ) -> Tuple[Tensor, Tensor]:
      logres = torch.log(residuals + 1e-10)
      minlogres = torch.min(logres)
      maxlogres = torch.max(logres)
  
      sorting_score = ransidx.unsqueeze(0).float() + 0.99 * (
          logres - minlogres
      ) / (maxlogres - minlogres)
  
      sorting_idxes = torch.argsort(
          sorting_score, dim=-1
      )  # (niters, numsamples)
  
      iters_range = torch.arange(
          residuals.shape[0], device=residuals.device
      )
  
      return (
          residuals[iters_range.unsqueeze(-1), sorting_idxes],
          sorting_idxes,
      )
  
file_path: kornia/kornia/feature/adalam/ransac.py
imports: from typing import Any, Dict, Tuple, Union
  import torch
  from kornia.core import Tensor
  from .utils import arange_sequence, batch_2x2_ellipse, batch_2x2_inv, draw_first_k_couples, piecewise_arange
label_desc: Use image node_id 1 for calling a global function with example usage: stable_sort_residuals(residuals, ransidx) and returns: residuals,  sorting_idxes