class_docstr: Base class for a recommender model supporting Approximate Nearest Neighbor (ANN) search.
  
  Parameters
  ----------------
  model: object: :obj:`cornac.models.Recommender`, required
      Trained recommender model which to get user/item vectors from.
  
  name: str, required
      Name of the recommender model.
  
  verbose: boolean, optional, default: False
      When True, running logs are displayed.
class_docstr_tok: ["Base","class","for","a","recommender","model","supporting","Approximate","Nearest","Neighbor","(","ANN",")","search",".","Parameters","--","--","--","--","--","--","--","--","model",":","object",":",":","obj",":","`","cornac.models.Recommender","`",",","required","Trained","recommender","model","which","to","get","user\/item","vectors","from",".","name",":","str",",","required","Name","of","the","recommender","model",".","verbose",":","boolean",",","optional",",","default",":","False","When","True",",","running","logs","are","displayed","."]
docstr: Rank all test items for a given user.
  
  Parameters
  ----------
  user_idx: int, required
      The index of the user for whom to perform item raking.
  
  item_indices: 1d array, optional, default: None
      A list of candidate item indices to be ranked by the user.
      If `None`, list of ranked known item indices and their scores will be returned.
  
  k: int, required
      Cut-off length for recommendations, k=-1 will return ranked list of all items.
  
  Returns
  -------
  (ranked_items, item_scores): tuple
      `ranked_items` contains item indices being ranked by their scores.
      `item_scores` contains scores of items corresponding to index in `item_indices` input.
docstr_tok: ["Rank","all","test","items","for","a","given","user",".","Parameters","--","--","--","--","--","user_idx",":","int",",","required","The","index","of","the","user","for","whom","to","perform","item","raking",".","item_indices",":","1d","array",",","optional",",","default",":","None","A","list","of","candidate","item","indices","to","be","ranked","by","the","user",".","If","`","None","`",",","list","of","ranked","known","item","indices","and","their","scores","will","be","returned",".","k",":","int",",","required","Cut-off","length","for","recommendations",",","k=-1","will","return","ranked","list","of","all","items",".","Returns","--","--","--","-","(","ranked_items",",","item_scores",")",":","tuple","`","ranked_items","`","contains","item","indices","being","ranked","by","their","scores",".","`","item_scores","`","contains","scores","of","items","corresponding","to","index","in","`","item_indices","`","input","."]
code: def rank(self, user_idx, item_indices=None, k=-1, **kwargs):
      """Rank all test items for a given user.
  
      Parameters
      ----------
      user_idx: int, required
          The index of the user for whom to perform item raking.
  
      item_indices: 1d array, optional, default: None
          A list of candidate item indices to be ranked by the user.
          If `None`, list of ranked known item indices and their scores will be returned.
  
      k: int, required
          Cut-off length for recommendations, k=-1 will return ranked list of all items.
  
      Returns
      -------
      (ranked_items, item_scores): tuple
          `ranked_items` contains item indices being ranked by their scores.
          `item_scores` contains scores of items corresponding to index in `item_indices` input.
  
      """
      query = self.user_vectors[[user_idx]]
      knn_items, distances = self.knn_query(query, k=k)
  
      top_k_items = knn_items[0]
      top_k_scores = -distances[0]
  
      item_scores = np.full(self.total_items, -np.Inf)
      item_scores[top_k_items] = top_k_scores
  
      all_items = np.arange(self.total_items)
      ranked_items = np.concatenate(
          [
              top_k_items,
              all_items[
                  ~np.isin(all_items, top_k_items, assume_unique=True)
              ],
          ]
      )
  
      # rank items based on their scores
      if item_indices is None:
          item_scores = item_scores[: self.num_items]
          ranked_items = ranked_items[: self.num_items]
      else:
          item_scores = item_scores[item_indices]
          ranked_items = ranked_items[
              np.isin(ranked_items, item_indices, assume_unique=True)
          ]
  
      return ranked_items, item_scores
  
file_path: cornac/cornac/models/ann/recom_ann_base.py
imports: import copy
  import warnings
  import numpy
  from ..recommender import Recommender
  from ..recommender import is_ann_supported
  from ..recommender import MEASURE_DOT, MEASURE_COSINE
label_desc: Use image node_id 5 for calling the BaseANN obj's underlying member method code with example usage: obj.rank(user_idx, item_indices, k) and returns: ranked_items,  item_scores