code: def get_loss(p, data, out, loss_func, device, get_auc=True):
      edge_mask = np.concatenate(
          (
              data["positive_edges_{}".format(p)],
              data["negative_edges_{}".format(p)],
          ),
          axis=-1,
      )
  
      nodes_first = torch.index_select(
          out,
          0,
          torch.from_numpy(edge_mask[0, :]).long().to(out.device),
      )
      nodes_second = torch.index_select(
          out,
          0,
          torch.from_numpy(edge_mask[1, :]).long().to(out.device),
      )
  
      pred = torch.sum(nodes_first * nodes_second, dim=-1)
  
      label_positive = torch.ones(
          [
              data["positive_edges_{}".format(p)].shape[1],
          ],
          dtype=pred.dtype,
      )
      label_negative = torch.zeros(
          [
              data["negative_edges_{}".format(p)].shape[1],
          ],
          dtype=pred.dtype,
      )
      label = torch.cat((label_positive, label_negative)).to(device)
      loss = loss_func(pred, label)
  
      if get_auc:
          auc = roc_auc_score(
              label.flatten().cpu().numpy(),
              torch.sigmoid(pred).flatten().data.cpu().numpy(),
          )
          return loss, auc
      else:
          return loss
  
file_path: dgl/examples/pytorch/P-GNN/main.py
imports: import os
  import warnings
  import dgl
  import numpy
  import torch
  import torch.nn
  from model import PGNN
  from sklearn.metrics import roc_auc_score
  from utils import get_dataset, preselect_anchor
label_desc: Use image node_id 1 for calling a global function with example usage: get_loss(p, data, out, loss_func, device, get_auc) and returns: loss,  auc, loss