code: def aggregate(values: Sequence["ReportedValue"]) -> Num:
      assert check_argument_types()
  
      for v in values:
          if not isinstance(v, type(values[0])):
              raise ValueError(
                  f"Can't use different Reported type together: "
                  f"{type(v)} != {type(values[0])}"
              )
  
      if len(values) == 0:
          warnings.warn("No stats found")
          retval = np.nan
  
      elif isinstance(values[0], Average):
          retval = np.nanmean([v.value for v in values])
  
      elif isinstance(values[0], WeightedAverage):
          # Excludes non finite values
          invalid_indices = set()
          for i, v in enumerate(values):
              if not np.isfinite(v.value) or not np.isfinite(v.weight):
                  invalid_indices.add(i)
          values = [
              v
              for i, v in enumerate(values)
              if i not in invalid_indices
          ]
  
          if len(values) != 0:
              # Calc weighed average. Weights are changed to sum-to-1.
              sum_weights = sum(v.weight for i, v in enumerate(values))
              sum_value = sum(
                  v.value * v.weight for i, v in enumerate(values)
              )
              if sum_weights == 0:
                  warnings.warn("weight is zero")
                  retval = np.nan
              else:
                  retval = sum_value / sum_weights
          else:
              warnings.warn("No valid stats found")
              retval = np.nan
  
      else:
          raise NotImplementedError(f"type={type(values[0])}")
      assert check_return_type(retval)
      return retval
  
imports: import dataclasses
  import datetime
  import logging
  import time
  import warnings
  from collections import defaultdict
  from contextlib import contextmanager
  from pathlib import Path
  from typing import ContextManager, Dict, List, Optional, Sequence, Tuple, Union
  import humanfriendly
  import numpy
  import torch
  from packaging.version import parse
  from typeguard import check_argument_types, check_return_type
label_desc: Use image node_id 2 for calling a global function with example usage: aggregate(values) and returns: retval