code: def get_loss(
      loss: Optional[np.ndarray],
      labels: Optional[np.ndarray],
      logits: Optional[np.ndarray],
      probs: Optional[np.ndarray],
      loss_function: LossFunctionCallable,
      loss_function_using_logits: Optional[bool],
      multilabel_data: Optional[bool],
      sample_weight: Optional[np.ndarray] = None,
  ) -> Optional[np.ndarray]:
      """Calculates (if needed) losses.
  
      Args:
        loss: the loss of each example.
        labels: the scalar label of each example.
        logits: the logits vector of each example.
        probs: the probability vector of each example.
        loss_function: if `loss` is not available, `labels` and one of `logits`
          and `probs` are available, we will use this function to compute loss. It
          is supposed to take in (label, logits / probs) as input.
        loss_function_using_logits: if `loss_function` expects `logits` or
          `probs`.
        multilabel_data: if the data is from a multilabel classification problem.
        sample_weight: a vector of weights of shape (num_samples, ) that are
          assigned to individual samples. If not provided, then each sample is
          given unit weight. Only the LogisticRegressionAttacker and the
          RandomForestAttacker support sample weights.
  
      Returns:
        Loss (or None if neither the loss nor the labels are present).
      """
      if loss is not None:
          return loss
      if labels is None or (logits is None and probs is None):
          return None
      if loss_function_using_logits and logits is None:
          raise ValueError(
              "We need logits to compute loss, but it is set to None."
          )
      if not loss_function_using_logits and probs is None:
          raise ValueError(
              "We need probs to compute loss, but it is set to None."
          )
  
      predictions = logits if loss_function_using_logits else probs
  
      if isinstance(loss_function, str):
          loss_function = string_to_loss_function(loss_function)
      if loss_function == LossFunction.CROSS_ENTROPY:
          if multilabel_data:
              loss = multilabel_bce_loss(
                  labels,
                  predictions,
                  sample_weight,
                  loss_function_using_logits,
              )
          else:
              loss = log_loss(
                  labels,
                  predictions,
                  sample_weight,
                  loss_function_using_logits,
              )
      elif loss_function == LossFunction.SQUARED:
          loss = squared_loss(labels, predictions, sample_weight)
      else:
          loss = loss_function(labels, predictions, sample_weight)
      return loss
  
file_path: privacy/tensorflow_privacy/privacy/privacy_tests/utils.py
imports: import enum
  import logging
  import numbers
  from typing import Callable, Iterable, Optional, Union
  import numpy
  from scipy import special
label_desc: Use image node_id 5 for calling a global function with example usage: get_loss(loss, labels, logits, probs, loss_function, loss_function_using_logits, multilabel_data, sample_weight) and returns: loss, loss, None