code: def flat_dim(idxs, dims):
      assert len(idxs) == len(dims) or len(idxs) == len(dims) + 1
      base = 1
      res = 0
      dims = dims[::-1]
      idxs = idxs[::-1]
      if len(idxs) == len(dims) + 1:
          dims.append(0)
          for idx, dim in zip(idxs, dims):
              assert idx < dim
              res += idx * base
              base *= dim
      return res
  
imports: import random
  import time
  from collections import OrderedDict
  import numpy
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: flat_dim(idxs, dims) and returns: res