code: def detect_anomaly(
      y, yhat=None, th=math.inf, dist_measure=EuclideanDistance()
  ):
      """
      Detect anomalies. Each sample can have 1 or more dimensions.
  
      :param y: the values to detect. shape could be 1-D (num_samples,)
          or 2-D array (num_samples, features)
      :param yhat: the estimated values, a tensor with same shape as y,
          could be None when threshold is a tuple
      :param th: threshold, could be
  
          1. a single value - absolute distance threshold, same for all samples
  
          2. a tuple (min, max) - min and max are either int/float or tensors in same shape as y,
          yhat is ignored in this case
      :param dist_measure: measure of distance
      :return: the anomaly values indexes in the samples, i.e. num_samples dimension.
      """
      if isinstance(th, int) or isinstance(th, float):
          if yhat is None:
              raise ValueError(
                  "Please specify a threshold range (min,max) ",
                  "if forecast values are not available",
              )
          return detect_all(y, yhat, th, dist_measure)
      elif isinstance(th, tuple) and len(th) == 2:
          # min max values are scalars
          if (isinstance(th[0], int) or isinstance(th[0], float)) and (
              isinstance(th[1], int) or isinstance(th[1], float)
          ):
              if th[0] > th[1]:
                  raise ValueError(
                      "In threshold (min,max), max should be larger than min"
                  )
              return detect_range(y, th)
          # min max values are arrays
          elif th[0].shape == y.shape and th[-1].shape == y.shape:
              if np.any((th[1] - th[0]) < 0):
                  raise ValueError(
                      "In threshold (min,max) ",
                      "each data point in max tensor should be larger than min",
                  )
              return detect_range_arr(y, th)
          else:
              raise ValueError(
                  "Threshold format", str(th), "is not supported"
              )
      else:
          raise ValueError(
              "Threshold format", str(th), "is not supported"
          )
  
imports: import math
  import numpy
  from zoo.chronos.detector.anomaly.abstract import AnomalyDetector
  from abc import ABC, abstractmethod
label_desc: Use image node_id 5 for calling a global function with example usage: detect_anomaly(y, yhat, th, dist_measure) and returns: detect_all, detect_range, detect_range_arr