code: def add_outgrads(prev_g_flagged, g):
      sparse = type(g) in sparse_object_types
      if prev_g_flagged:
          vs = vspace(g)
          prev_g, mutable = prev_g_flagged
          if mutable:
              if sparse:
                  return sparse_add(vs, prev_g, g), True
              else:
                  return vs.mut_add(prev_g, g), True
          else:
              if sparse:
                  prev_g_mutable = vs.mut_add(None, prev_g)
                  return sparse_add(vs, prev_g_mutable, g), True
              else:
                  return vs.add(prev_g, g), True
      else:
          if sparse:
              return sparse_add(vspace(g), None, g), True
          else:
              return g, False
  
imports: from itertools import count
  from functools import reduce
  from .tracer import trace, primitive, toposort, Node, Box, isbox, getval
  from .util import func, subval
  import warnings
label_desc: Use image node_id 13 for calling a global function with example usage: add_outgrads(prev_g_flagged, g) and returns: sparse_add,  True, g,  False, sparse_add,  True, vs,  True, sparse_add,  True, vs,  True