(type_args)
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(op, tensor or const), is_scalar, red_count, left_child, right_child ]
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 ]
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 ]
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]
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 ] # 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 ]