code: def coherency_error(S: np.ndarray, samples: np.ndarray) -> float:
      r"""
      Computes the maximum relative coherency error
  
      .. math::
  
                  \max_i | (S @ y_b)_i - y_i | / y_i
  
      where :math:`y` refers to the `samples` and :math:`y_b` refers to the
      samples at the bottom level.
  
      Parameters
      ----------
      S
          The summation matrix S. Shape:
          (total_num_time_series, num_bottom_time_series)
      samples
          Samples. Shape: `(*batch_shape, target_dim)`.
  
      Returns
      -------
      Float
          Coherency error
      """
      samples_bottom_level = samples[..., -S.shape[1] :]
  
      errs = np.abs(samples_bottom_level @ S.T - samples)
      rel_errs = np.where(
          samples == 0.0,
          errs,
          errs / np.abs(samples),
      )
      return rel_errs.max()
  
imports: import logging
  from typing import List, Optional
  from itertools import product
  import mxnet
  import numpy
  from gluonts.core.component import validated
  from gluonts.mx import Tensor
  from gluonts.mx.distribution import Distribution, DistributionOutput
  from gluonts.mx.distribution import EmpiricalDistribution
  from gluonts.mx.util import assert_shape
  from gluonts.mx.distribution import LowrankMultivariateGaussian
  from gluonts.mx.model.deepvar._network import DeepVARNetwork, DeepVARTrainingNetwork, DeepVARPredictionNetwork
label_desc: Use image node_id 2 for calling a global function with example usage: coherency_error(S, samples) and returns: rel_errs