code: def _build_tree(type_args):
      """
      rebuild a mutable tree from the stack
      flag each op node with whether it is scalar or not
      also include a count of reductions under this node:
      node: [ arg(op, tensor or const), is_scalar, red_count, left_child, right_child ]
      """
  
      stack = list()
      for arg in type_args:
          arg_type = arg[0]
          if arg_type in _float_ops:
              numops = _float_ops[arg_type][0]
              # ops with zero args default to non-scalar
              node = [arg, numops > 0, 0]
              for i in range(numops):
                  operand = stack.pop()
                  # if child is another node in the tree:
                  if type(operand) is list:
                      # accumulate reduction count
                      node[2] += operand[2]
                      # if a child is not scalar, then neither is this node
                      if operand[1] == 0:
                          node[1] = False
                  # if child is an input tensor (an output tensor has id=0) then
                  # this node is not scalar
                  # if it's an output tensor check the shape[axis]==1 flag
                  elif operand[0] is ng.GPUTensor and (
                      operand[1] > 0 or not operand[4]
                  ):
                      node[1] = False
                  # children start at position 3 and are added in reverse order
                  node.insert(3, operand)
              stack.append(node)
  
          elif arg_type in _reduction_ops:
              operand = stack.pop()
              reds = 1
              # if child is another node accumulate reduction count
              if type(operand) is list:
                  reds += operand[2]
              # reductions are scalar by definition
              stack.append([arg, True, reds, operand])
  
          else:
              # tensors and scalars just get added to the stack
              # for later processing with operators
              stack.append(arg)
  
      # the stack should now contain just a single node which is the complete
      # tree
      return stack[0]
  
imports: from __future__ import division
  from future.utils import native_str
  import os.path
  import re
  import traceback
  import numpy
  from pycuda.tools import context_dependent_memoize
  from pytools import memoize
  from neon import logger
  import neon.backends.nervanagpu
  from neon.backends.util.source_module import SourceModule
  from neon.backends.cuda_templates import _ew_template, _stage_template, _fin_template, _init_rand_func, _init_rand_round_func, _finish_rand_func, _common_kepler, _common_urand_gen, _common_frand, _common_round, _common_fp16_to_fp32, _ew_types, _ew_strings, _is_finite, _float_ops, _reduction_ops
  from neon.backends.cuda_batchnorm import _get_bn_fprop_kernel, _get_bn_bprop_kernel
  from neon.backends.kernels.cuda.lookuptable import _get_lut_bprop_kernel, _get_sorting_kernel
label_desc: Use image node_id 1 for calling a global function with example usage: _build_tree(type_args) and returns: stack