code: def value(self):
          
  
          if self.scores.numel() == 0:
              return 0
          ap = torch.zeros(self.scores.size(1))
          if hasattr(torch, "arange"):
              rg = torch.arange(1, self.scores.size(0) + 1).float()
          else:
              rg = torch.range(1, self.scores.size(0)).float()
          if self.weights.numel() > 0:
              weight = self.weights.new(self.weights.size())
              weighted_truth = self.weights.new(self.weights.size())
  
          # compute average precision for each class
          for k in range(self.scores.size(1)):
              # sort scores
              scores = self.scores[:, k]
              targets = self.targets[:, k]
              _, sortind = torch.sort(scores, 0, True)
              truth = targets[sortind]
              if self.weights.numel() > 0:
                  weight = self.weights[sortind]
                  weighted_truth = truth.float() * weight
                  rg = weight.cumsum(0)
  
              # compute true positive sums
              if self.weights.numel() > 0:
                  tp = weighted_truth.cumsum(0)
              else:
                  tp = truth.float().cumsum(0)
  
              # compute precision curve
              precision = tp.div(rg)
  
              # compute average precision
              ap[k] = precision[truth.byte()].sum() / max(float(truth.sum()), 1)
          return ap
docs: Returns the model's average precision for each class
  
          Return:
              ap (FloatTensor): 1xK tensor, with avg precision for each class k