docstr: Aggregates array of `StatDict` items by a given `mode`
docstr_tok: ["Aggregates","array","of","`","StatDict","`","items","by","a","given","`","mode","`"]
code: def aggregate_items(
      cls,
      items: "List[StatDict]",
      agg_mode: str = AGG_DEFAULT,
  ):
      """
      Aggregates array of `StatDict` items by a given `mode`
      """
      aggregated_stat = cls()
  
      # Return empty item if items array is empty
      if not items or len(items) == 0:
          return aggregated_stat
  
      gpu_stats = []
      for s in items:
          # Collect system stats
          for k in s.system.keys():
              aggregated_stat.system.setdefault(k, [])
              aggregated_stat.system[k].append(s.system[k])
  
          # Collect GPU device stats
          for stat_item_gpu_idx in range(len(s.gpus)):
              stat_item_gpu_stat = s.gpus[stat_item_gpu_idx]
              if len(gpu_stats) == stat_item_gpu_idx:
                  gpu_stats.append({})
              for gpu_stat_key in stat_item_gpu_stat.keys():
                  gpu_stat = stat_item_gpu_stat[gpu_stat_key]
                  gpu_stats[stat_item_gpu_idx].setdefault(
                      gpu_stat_key, []
                  )
                  gpu_stats[stat_item_gpu_idx][gpu_stat_key].append(
                      gpu_stat
                  )
  
      # Aggregate system stats
      for k in aggregated_stat.system.keys():
          aggregated_stat.system[k] = cls.aggregate(
              aggregated_stat.system[k], agg_mode
          )
  
      # Aggregate GPU device stats
      for g in range(len(gpu_stats)):
          for k in gpu_stats[g].keys():
              gpu_stats[g][k] = cls.aggregate(gpu_stats[g][k], agg_mode)
      aggregated_stat.gpu = gpu_stats
  
      return aggregated_stat
  
file_path: aim/aim/ext/resource/stat.py
imports: import psutil
  import json
  from typing import List
  from aim.ext.resource.utils import round10e5
  import aim.ext.pynvml
label_desc: Use image node_id 2 for calling the StatDict obj's underlying member method code with example usage: obj.aggregate_items(cls, items, agg_mode) and returns: aggregated_stat, aggregated_stat