code: def ncrps(
      y_pred: QuantileForecasts, y_true: npt.NDArray[np.float32]
  ) -> float:
      y_true_rep = y_true[:, None].repeat(len(y_pred.quantiles), axis=1)
      quantiles = np.array([float(q) for q in y_pred.quantiles])
      quantile_losses = 2 * np.sum(
          np.abs(
              (y_pred.values - y_true_rep)
              * ((y_true_rep <= y_pred.values) - quantiles[:, None])
          ),
          axis=-1,
      )  # shape [num_time_series, num_quantiles]
      denom = np.sum(np.abs(y_true))  # shape [1]
      weighted_losses = (
          quantile_losses.sum(0) / denom
      )  # shape [num_quantiles]
      return weighted_losses.mean()
  
file_path: gluonts/src/gluonts/nursery/tsbench/src/tsbench/forecasts/metrics.py
imports: import math
  import numpy
  import numpy.typing
  from numpy import ma
  from .quantile import QuantileForecasts
label_desc: Use image node_id 8 for calling a global function with example usage: ncrps(y_pred, y_true) and returns: weighted_losses