code: def test(x, predictor, split_edge, evaluator, batch_size):
      predictor.eval()
  
      pos_train_edge = split_edge["train"]["edge"].to(x.device)
      pos_valid_edge = split_edge["valid"]["edge"].to(x.device)
      neg_valid_edge = split_edge["valid"]["edge_neg"].to(x.device)
      pos_test_edge = split_edge["test"]["edge"].to(x.device)
      neg_test_edge = split_edge["test"]["edge_neg"].to(x.device)
  
      pos_train_preds = []
      for perm in DataLoader(range(pos_train_edge.size(0)), batch_size):
          edge = pos_train_edge[perm].t()
          pos_train_preds += [
              predictor(x[edge[0]], x[edge[1]]).squeeze().cpu()
          ]
      pos_train_pred = torch.cat(pos_train_preds, dim=0)
  
      pos_valid_preds = []
      for perm in DataLoader(range(pos_valid_edge.size(0)), batch_size):
          edge = pos_valid_edge[perm].t()
          pos_valid_preds += [
              predictor(x[edge[0]], x[edge[1]]).squeeze().cpu()
          ]
      pos_valid_pred = torch.cat(pos_valid_preds, dim=0)
  
      neg_valid_preds = []
      for perm in DataLoader(range(neg_valid_edge.size(0)), batch_size):
          edge = neg_valid_edge[perm].t()
          neg_valid_preds += [
              predictor(x[edge[0]], x[edge[1]]).squeeze().cpu()
          ]
      neg_valid_pred = torch.cat(neg_valid_preds, dim=0)
  
      pos_test_preds = []
      for perm in DataLoader(range(pos_test_edge.size(0)), batch_size):
          edge = pos_test_edge[perm].t()
          pos_test_preds += [
              predictor(x[edge[0]], x[edge[1]]).squeeze().cpu()
          ]
      pos_test_pred = torch.cat(pos_test_preds, dim=0)
  
      neg_test_preds = []
      for perm in DataLoader(range(neg_test_edge.size(0)), batch_size):
          edge = neg_test_edge[perm].t()
          neg_test_preds += [
              predictor(x[edge[0]], x[edge[1]]).squeeze().cpu()
          ]
      neg_test_pred = torch.cat(neg_test_preds, dim=0)
  
      results = {}
      for K in [10, 50, 100]:
          evaluator.K = K
          train_hits = evaluator.eval(
              {
                  "y_pred_pos": pos_train_pred,
                  "y_pred_neg": neg_valid_pred,
              }
          )[f"hits@{K}"]
          valid_hits = evaluator.eval(
              {
                  "y_pred_pos": pos_valid_pred,
                  "y_pred_neg": neg_valid_pred,
              }
          )[f"hits@{K}"]
          test_hits = evaluator.eval(
              {
                  "y_pred_pos": pos_test_pred,
                  "y_pred_neg": neg_test_pred,
              }
          )[f"hits@{K}"]
  
          results[f"Hits@{K}"] = (train_hits, valid_hits, test_hits)
  
      return results
  
file_path: ogb/examples/linkproppred/ppa/mf.py
imports: import argparse
  import torch
  import torch.nn.functional
  from torch.utils.data import DataLoader
  from ogb.linkproppred import PygLinkPropPredDataset, Evaluator
  from logger import Logger
label_desc: Use image node_id 2 for calling a global function with example usage: test(x, predictor, split_edge, evaluator, batch_size) and returns: results