def _build_tree(type_args):
 stack = list()
 for arg in type_args:
  arg_type = arg[0]
  if (arg_type in _float_ops):
   numops = _float_ops[arg_type][0]
   node = [arg, (numops > 0), 0]
   for i in range(numops):
    operand = stack.pop()
    if (type(operand) is list):
     node[2] += operand[2]
     if (operand[1] == 0):
      node[1] = False
    elif ((operand[0] is ng.GPUTensor) and ((operand[1] > 0) or (not operand[4]))):
     node[1] = False
    node.insert(3, operand)
   stack.append(node)
  elif (arg_type in _reduction_ops):
   operand = stack.pop()
   reds = 1
   if (type(operand) is list):
    reds += operand[2]
   stack.append([arg, True, reds, operand])
  else:
   stack.append(arg)
 return stack[0]

def _build_tree ( type_args ) : stack = list ( ) for arg in type_args : arg_type = arg [ 0 ] if ( arg_type in _float_ops ) : numops = _float_ops [ arg_type ] [ 0 ] node = [ arg , ( numops > 0 ) , 0 ] for i in range ( numops ) : operand = stack . pop ( ) if ( type ( operand ) is list ) : node [ 2 ] += operand [ 2 ] if ( operand [ 1 ] == 0 ) : node [ 1 ] = False elif ( ( operand [ 0 ] is ng . GPUTensor ) and ( ( operand [ 1 ] > 0 ) or ( not operand [ 4 ] ) ) ) : node [ 1 ] = False node . insert ( 3 , operand ) stack . append ( node ) elif ( arg_type in _reduction_ops ) : operand = stack . pop ( ) reds = 1 if ( type ( operand ) is list ) : reds += operand [ 2 ] stack . append ( [ arg , True , reds , operand ] ) else : stack . append ( arg ) return stack [ 0 ]
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 .