class_docstr: Generic class for a recommender model. All recommendation models should inherit from this class.
  
  Parameters
  ----------------
  name: str, required
      Name of the recommender model.
  
  trainable: boolean, optional, default: True
      When False, the model is not trainable.
  
  verbose: boolean, optional, default: False
      When True, running logs are displayed.
  
  Attributes
  ----------
  num_users: int
      Number of users in training data.
  
  num_items: int
      Number of items in training data.
  
  total_users: int
      Number of users in training, validation, and test data.
      In other words, this includes unknown/unseen users.
  
  total_items: int
      Number of items in training, validation, and test data.
      In other words, this includes unknown/unseen items.
  
  uid_map: int
      Global mapping of user ID-index.
  
  iid_map: int
      Global mapping of item ID-index.
  
  max_rating: float
      Maximum value among the rating observations.
  
  min_rating: float
      Minimum value among the rating observations.
  
  global_mean: float
      Average value over the rating observations.
class_docstr_tok: ["Generic","class","for","a","recommender","model",".","All","recommendation","models","should","inherit","from","this","class",".","Parameters","--","--","--","--","--","--","--","--","name",":","str",",","required","Name","of","the","recommender","model",".","trainable",":","boolean",",","optional",",","default",":","True","When","False",",","the","model","is","not","trainable",".","verbose",":","boolean",",","optional",",","default",":","False","When","True",",","running","logs","are","displayed",".","Attributes","--","--","--","--","--","num_users",":","int","Number","of","users","in","training","data",".","num_items",":","int","Number","of","items","in","training","data",".","total_users",":","int","Number","of","users","in","training",",","validation",",","and","test","data",".","In","other","words",",","this","includes","unknown\/unseen","users",".","total_items",":","int","Number","of","items","in","training",",","validation",",","and","test","data",".","In","other","words",",","this","includes","unknown\/unseen","items",".","uid_map",":","int","Global","mapping","of","user","ID-index",".","iid_map",":","int","Global","mapping","of","item","ID-index",".","max_rating",":","float","Maximum","value","among","the","rating","observations",".","min_rating",":","float","Minimum","value","among","the","rating","observations",".","global_mean",":","float","Average","value","over","the","rating","observations","."]
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.
      This is more important for ANN to know the limit to avoid exhaustive ranking.
  
  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",".","This","is","more","important","for","ANN","to","know","the","limit","to","avoid","exhaustive","ranking",".","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.
          This is more important for ANN to know the limit to avoid exhaustive ranking.
  
      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.
  
      """
      # obtain item scores from the model
      try:
          known_item_scores = self.score(user_idx, **kwargs)
      except ScoreException:
          known_item_scores = (
              np.ones(self.total_items) * self.default_score()
          )
  
      # check if the returned scores also cover unknown items
      # if not, all unknown items will be given the MIN score
      if len(known_item_scores) == self.total_items:
          all_item_scores = known_item_scores
      else:
          all_item_scores = np.ones(self.total_items) * np.min(
              known_item_scores
          )
          all_item_scores[: self.num_items] = known_item_scores
  
      # rank items based on their scores
      item_indices = (
          np.arange(self.num_items)
          if item_indices is None
          else np.asarray(item_indices)
      )
      item_scores = all_item_scores[item_indices]
  
      if (
          k != -1
      ):  # O(n + k log k), faster for small k which is usually the case
          partitioned_idx = np.argpartition(item_scores, -k)
          top_k_idx = partitioned_idx[-k:]
          sorted_top_k_idx = top_k_idx[
              np.argsort(item_scores[top_k_idx])
          ]
          partitioned_idx[-k:] = sorted_top_k_idx
          ranked_items = item_indices[partitioned_idx[::-1]]
      else:  # O(n log n)
          ranked_items = item_indices[item_scores.argsort()[::-1]]
  
      return ranked_items, item_scores
  
imports: import copy
  import inspect
  import os
  import pickle
  import warnings
  from datetime import datetime
  from glob import glob
  import numpy
  from ..exception import ScoreException
  from ..utils.common import clip
label_desc: Use image node_id 21 for calling the Recommender obj's underlying member method code with example usage: obj.rank(user_idx, item_indices, k) and returns: ranked_items,  item_scores