code: def mrr(
      targets: csr_matrix,
      user_ids: Union[np.array, torch.tensor],
      preds: Union[np.array, torch.tensor],
      k: Optional[Any] = None,
  ) -> float:
      """
      Calculate the mean reciprocal rank (MRR) of the input predictions.
  
      Parameters
      ----------
      targets: scipy.sparse.csr_matrix
          Interaction matrix containing user and item IDs
      user_ids: np.array or torch.tensor
          Users corresponding to the recommendations in the top k predictions
      preds: torch.tensor
          Tensor of shape (n_users x n_items) with each user's scores for each item
      k: Any
          Ignored, included only for compatibility with ``mapk``
  
      Returns
      -------
      mrr_score: float
  
      """
      predicted_items = preds.topk(preds.shape[1], dim=1).indices
      labeled = _get_labels(
          targets, user_ids, predicted_items, device=preds.device
      )
  
      # weighting each 0/1 by position so that topk returns index of *first* postive result
      position_weight = 1.0 / (
          torch.arange(1, targets.shape[1] + 1, device=preds.device)
          .repeat(len(user_ids), 1)
          .float()
      )
      labeled_weighted = labeled.float() * position_weight
  
      highest_score, rank = labeled_weighted.topk(k=1)
  
      reciprocal_rank = 1.0 / (rank.float() + 1)
      reciprocal_rank[highest_score == 0] = 0
  
      return reciprocal_rank.mean().item()
  
imports: from typing import Any, Callable, Iterable, List, Optional, Tuple, Union
  import warnings
  import numpy
  from scipy.sparse import csr_matrix
  import torch
  from torchmetrics import Metric
  from torchmetrics.functional import auroc
  from tqdm.auto import tqdm
  import collie
  from collie.interactions import ExplicitInteractions, Interactions, InteractionsDataLoader
  from collie.model import BasePipeline
label_desc: Use image node_id 5 for calling a global function with example usage: mrr(targets, user_ids, preds, k) and returns: reciprocal_rank