def adalam_core(
    k1: Tensor,
    k2: Tensor,
    fnn12: Tensor,
    scores1: Tensor,
    config: AdalamConfig,
    mnn: Optional[Tensor] = None,
    im1shape: Optional[Tuple[int, int]] = None,
    im2shape: Optional[Tuple[int, int]] = None,
    o1: Optional[Tensor] = None,
    o2: Optional[Tensor] = None,
    s1: Optional[Tensor] = None,
    s2: Optional[Tensor] = None,
    return_dist: bool = False,
) -> Union[Tuple[Tensor, Tensor], Tensor]:
    """Call the core functionality of AdaLAM, i.e. just outlier filtering.

    No sanity check is performed on the inputs.

    Args:
        k1: keypoint locations in the source image, in pixel coordinates.
            Expected a float32 tensor with shape (num_keypoints_in_source_image, 2).
        k2: keypoint locations in the destination image, in pixel coordinates.
            Expected a float32 tensor with shape (num_keypoints_in_destination_image, 2).
        fnn12: Initial set of putative matches to be filtered.
              The current implementation assumes that these are unfiltered nearest neighbor matches,
              so it requires this to be a list of indices a_i such that the source keypoint i is associated to the
              destination keypoint a_i. For now to use AdaLAM on different inputs a workaround on the input format is
              required. Expected a long tensor with shape (num_keypoints_in_source_image,).
        scores1: Confidence scores on the putative_matches. Usually holds Lowe's ratio scores.
        config: Adalam configuration.
        mnn: A mask indicating which putative matches are also mutual nearest neighbors. See documentation on
             'force_seed_mnn' in the DEFAULT_CONFIG. If None, it disables the mutual nearest neighbor filtering on seed
             point selection. Expected a bool tensor with shape (num_keypoints_in_source_image,)
        im1shape: Shape of the source image. If None, it is inferred from keypoints max and min, at the cost of wasted
                  runtime. So please provide it. Expected a tuple with (width, height) or (height, width) of source
                  image
        im2shape: Shape of the destination image. If None, it is inferred from keypoints max and min, at the cost of
                  wasted runtime. So please provide it. Expected a tuple with (width, height) or (height, width) of
                  destination image
        o1: keypoint orientations in degrees. They can be None if 'orientation_difference_threshold' in config is
               set to None. See documentation on 'orientation_difference_threshold' in the DEFAULT_CONFIG.
               Expected a float32 tensor with shape (num_keypoints_in_source/destination_image,)
        o2: Same as o1 but for destination.
        s1: keypoint scales. They can be None if 'scale_rate_threshold' in config is set to None.
               See documentation on 'scale_rate_threshold' in the DEFAULT_CONFIG.
               Expected a float32 tensor with shape (num_keypoints_in_source/destination_image,)
        s2: Same as s1 but for destination.
        return_dist: if True, inverse confidence value is also outputted. Default is False

    Returns:
        idxs: A long tensor with shape (num_filtered_matches, 2) with indices of corresponding keypoints in k1 and k2.
        dists: inverse confidence ratio.

    """
    AREA_RATIO = config["area_ratio"]
    SEARCH_EXP = config["search_expansion"]
    RANSAC_ITERS = config["ransac_iters"]
    MIN_INLIERS = config["min_inliers"]
    MIN_CONF = config["min_confidence"]
    ORIENTATION_THR = config["orientation_difference_threshold"]
    SCALE_RATE_THR = config["scale_rate_threshold"]
    REFIT = config["refit"]

    if isinstance(im1shape, tuple):
        _im1shape = tensor(im1shape, device=k1.device, dtype=k1.dtype)
    else:
        k1mins = k1.min(dim=0).values
        k1maxs = k1.max(dim=0).values
        _im1shape = k1maxs - k1mins

    if isinstance(im2shape, tuple):
        _im2shape = tensor(im2shape, device=k2.device, dtype=k2.dtype)
    else:
        k2mins = k2.min(dim=0).values
        k2maxs = k2.max(dim=0).values
        _im2shape = k2maxs - k2mins

    # Compute seed selection radii to be invariant to image rescaling
    R1 = torch.sqrt(torch.prod(_im1shape[:2]) / AREA_RATIO / math.pi)
    R2 = torch.sqrt(torch.prod(_im2shape[:2]) / AREA_RATIO / math.pi)

    # Precompute the inner distances of keypoints in image I_1
    dist1 = dist_matrix(k1, k1)

    # Select seeds
    im1seeds, im2seeds = select_seeds(dist1, R1, scores1, fnn12, mnn)

    # Find the neighboring and coherent keyopints consistent with each seed
    local_neighs_mask, rdims, im1seeds, im2seeds = extract_neighborhood_sets(
        o1,
        o2,
        s1,
        s2,
        dist1,
        im1seeds,
        im2seeds,
        k1,
        k2,
        R1,
        R2,
        fnn12,
        ORIENTATION_THR,
        SCALE_RATE_THR,
        SEARCH_EXP,
        MIN_INLIERS,
    )

    if rdims.shape[0] == 0:
        # No seed point survived. Just output ratio-test matches. This should happen very rarely.
        score_mask = scores1 <= 0.95
        absolute_im1idx = where(score_mask)[0]
        if len(absolute_im1idx) > 0:
            absolute_im2idx = fnn12[absolute_im1idx]
            out_scores = scores1[score_mask].reshape(-1, 1)
            idxs = torch.stack([absolute_im1idx, absolute_im2idx], dim=1)
        else:
            idxs, out_scores = _no_match(scores1)
        if return_dist:
            return idxs, out_scores
        else:
            return idxs

    # Format neighborhoods for parallel RANSACs
    im1loc, im2loc, ransidx, tokp1, tokp2 = extract_local_patterns(
        fnn12, local_neighs_mask, k1, k2, im1seeds, im2seeds, scores1
    )
    im1loc = im1loc / (R1 * SEARCH_EXP)
    im2loc = im2loc / (R2 * SEARCH_EXP)

    # Run the parallel confidence-based RANSACs to perform local affine verification
    inlier_idx, _, inl_confidence, inlier_counts = ransac(
        xsamples=im1loc, ysamples=im2loc, rdims=rdims, iters=RANSAC_ITERS, refit=REFIT, config=dict(config)
    )

    conf = inl_confidence[ransidx[inlier_idx]]
    cnt = inlier_counts[ransidx[inlier_idx]].float()
    dist_ratio = 1.0 / conf
    passed_inliers_mask = (conf >= MIN_CONF) & (cnt * (1 - dist_ratio) >= MIN_INLIERS)
    accepted_inliers = inlier_idx[passed_inliers_mask]
    accepted_dist = dist_ratio[passed_inliers_mask]

    absolute_im1idx = tokp1[accepted_inliers]
    absolute_im2idx = tokp2[accepted_inliers]

    final_matches = torch.stack([absolute_im1idx, absolute_im2idx], dim=1)
    if final_matches.shape[0] > 1:
        # https://stackoverflow.com/a/72005790
        final_matches, idxs, counts = torch.unique(final_matches, dim=0, return_inverse=True, return_counts=True)
        _, ind_sorted = torch.sort(idxs)
        cum_sum = counts.cumsum(0)
        cum_sum = concatenate((torch.tensor([0], dtype=cum_sum.dtype, device=cum_sum.device), cum_sum[:-1]))
        first_indicies = ind_sorted[cum_sum]
        accepted_dist = accepted_dist[first_indicies]
    if return_dist:
        return final_matches, accepted_dist.reshape(-1, 1)
    return final_matches
Call the core functionality of AdaLAM, i.e. just outlier filtering.

    No sanity check is performed on the inputs.

    Args:
        k1: keypoint locations in the source image, in pixel coordinates.
            Expected a float32 tensor with shape (num_keypoints_in_source_image, 2).
        k2: keypoint locations in the destination image, in pixel coordinates.
            Expected a float32 tensor with shape (num_keypoints_in_destination_image, 2).
        fnn12: Initial set of putative matches to be filtered.
              The current implementation assumes that these are unfiltered nearest neighbor matches,
              so it requires this to be a list of indices a_i such that the source keypoint i is associated to the
              destination keypoint a_i. For now to use AdaLAM on different inputs a workaround on the input format is
              required. Expected a long tensor with shape (num_keypoints_in_source_image,).
        scores1: Confidence scores on the putative_matches. Usually holds Lowe's ratio scores.
        config: Adalam configuration.
        mnn: A mask indicating which putative matches are also mutual nearest neighbors. See documentation on
             'force_seed_mnn' in the DEFAULT_CONFIG. If None, it disables the mutual nearest neighbor filtering on seed
             point selection. Expected a bool tensor with shape (num_keypoints_in_source_image,)
        im1shape: Shape of the source image. If None, it is inferred from keypoints max and min, at the cost of wasted
                  runtime. So please provide it. Expected a tuple with (width, height) or (height, width) of source
                  image
        im2shape: Shape of the destination image. If None, it is inferred from keypoints max and min, at the cost of
                  wasted runtime. So please provide it. Expected a tuple with (width, height) or (height, width) of
                  destination image
        o1: keypoint orientations in degrees. They can be None if 'orientation_difference_threshold' in config is
               set to None. See documentation on 'orientation_difference_threshold' in the DEFAULT_CONFIG.
               Expected a float32 tensor with shape (num_keypoints_in_source/destination_image,)
        o2: Same as o1 but for destination.
        s1: keypoint scales. They can be None if 'scale_rate_threshold' in config is set to None.
               See documentation on 'scale_rate_threshold' in the DEFAULT_CONFIG.
               Expected a float32 tensor with shape (num_keypoints_in_source/destination_image,)
        s2: Same as s1 but for destination.
        return_dist: if True, inverse confidence value is also outputted. Default is False

    Returns:
        idxs: A long tensor with shape (num_filtered_matches, 2) with indices of corresponding keypoints in k1 and k2.
        dists: inverse confidence ratio.

    
kornia/feature/adalam/core.py