code: def return_results(D, I, ref_includes_query):
      if ref_includes_query:
          self_idx = torch.arange(len(I), device=I.device)
          matches_self_idx = I == self_idx.unsqueeze(1)
          row_has_match = torch.any(matches_self_idx, dim=1)
          # If every row has a match, then masking will work
          if not torch.all(row_has_match):
              # For rows that don't contain the self index
              # Remove the Nth value by setting matches_self_idx[N] to True
              matches_self_idx[~row_has_match, -1] = True
          I = mask_reshape_knn_idx(I, matches_self_idx)
          D = mask_reshape_knn_idx(D, matches_self_idx)
      return D, I
  
imports: import numpy
  import torch
  from ..distances import BatchedDistance, CosineSimilarity
  from .None import common_functions
label_desc: Use image node_id 7 for calling a global function with example usage: return_results(D, I, ref_includes_query) and returns: D,  I