code: def do_generate_api(targets, sources):
      header_file = targets[0]
      c_file = targets[1]
      doc_file = targets[2]
  
      global_vars = sources[0]
      scalar_bool_values = sources[1]
      types_api = sources[2]
      multiarray_funcs = sources[3]
  
      multiarray_api = sources[:]
  
      module_list = []
      extension_list = []
      init_list = []
  
      # Check multiarray api indexes
      multiarray_api_index = genapi.merge_api_dicts(multiarray_api)
      genapi.check_api_dict(multiarray_api_index)
  
      numpyapi_list = genapi.get_api_functions(
          "NUMPY_API", multiarray_funcs
      )
  
      # FIXME: ordered_funcs_api is unused
      ordered_funcs_api = genapi.order_dict(multiarray_funcs)
  
      # Create dict name -> *Api instance
      api_name = "PyArray_API"
      multiarray_api_dict = {}
      for f in numpyapi_list:
          name = f.name
          index = multiarray_funcs[name][0]
          annotations = multiarray_funcs[name][1:]
          multiarray_api_dict[f.name] = FunctionApi(
              f.name,
              index,
              annotations,
              f.return_type,
              f.args,
              api_name,
          )
  
      for name, val in global_vars.items():
          index, type = val
          multiarray_api_dict[name] = GlobalVarApi(
              name, index, type, api_name
          )
  
      for name, val in scalar_bool_values.items():
          index = val[0]
          multiarray_api_dict[name] = BoolValuesApi(
              name, index, api_name
          )
  
      for name, val in types_api.items():
          index = val[0]
          multiarray_api_dict[name] = TypeApi(
              name, index, "PyTypeObject", api_name
          )
  
      if len(multiarray_api_dict) != len(multiarray_api_index):
          keys_dict = set(multiarray_api_dict.keys())
          keys_index = set(multiarray_api_index.keys())
          raise AssertionError(
              "Multiarray API size mismatch - "
              "index has extra keys {}, dict has extra keys {}".format(
                  keys_index - keys_dict, keys_dict - keys_index
              )
          )
  
      extension_list = []
      for name, index in genapi.order_dict(multiarray_api_index):
          api_item = multiarray_api_dict[name]
          extension_list.append(api_item.define_from_array_api_string())
          init_list.append(api_item.array_api_define())
          module_list.append(api_item.internal_define())
  
      # Write to header
      s = h_template % (
          "\n".join(module_list),
          "\n".join(extension_list),
      )
      genapi.write_file(header_file, s)
  
      # Write to c-code
      s = c_template % ",\n".join(init_list)
      genapi.write_file(c_file, s)
  
      # write to documentation
      s = c_api_header
      for func in numpyapi_list:
          s += func.to_ReST()
          s += "\n\n"
      genapi.write_file(doc_file, s)
  
      return targets
  
imports: from __future__ import division, print_function
  import os
  import genapi
  from genapi import TypeApi, GlobalVarApi, FunctionApi, BoolValuesApi
  import numpy_api
label_desc: Use image node_id 2 for calling a global function with example usage: do_generate_api(targets, sources) and returns: targets