Ejemplo n.º 1
0
 def visit_InputElement(self, node):
     index = self.gen_array_macro(
         node.grid.name,
         map(
             lambda x, y: cpp_ast.BinOp(cpp_ast.CName(x), "+",
                                        cpp_ast.CNumber(y)), self.dim_vars,
             node.offset_list))
     return cpp_ast.Subscript("_my_" + node.grid.name, index)
Ejemplo n.º 2
0
 def declare_child(self, child, idx):
     if child.is_scalar():
         return cpp_ast.Subscript(self.ref_name(), idx)
     else:
         return cpp_ast.BinOp(cpp_ast.CName(self.ref_name()), '+',
                              cpp_ast.BinOp(idx, '*', self.element_size()))
Ejemplo n.º 3
0
 def declare_child(self, child, idx):
     return cpp_ast.Subscript(cpp_ast.CName(self.ref_name()), idx)
Ejemplo n.º 4
0
 def visit_InputElementExprIndex(self, node):
     return cpp_ast.Subscript("_my_" + node.grid.name,
                              self.visit(node.index))
Ejemplo n.º 5
0
 def visit_OutputElement(self, node):
     return cpp_ast.Subscript("_my_" + self.output_grid_name,
                              self.output_index_var)
Ejemplo n.º 6
0
 def __init__(self, weight_index, target):
     self.left = cpp_ast.Subscript(cpp_ast.CName('_blb_weights'),
                                   weight_index)
     self.right = target
     self.op = '*'
     super(cpp_ast.BinOp, self).__init__()
Ejemplo n.º 7
0
    def visit_Subscript(self, node):
        index = self.visit(node.slice)
        value = self.visit(node.value)
        if type(node.ctx) == ast.Load:
            if type(value) == cpp_ast.CName:
                target_model = self.get_or_create_model(value)
                if target_model.is_scalar():
                    raise ValueError(
                        'Invalid target for indexing: %s is scalar' %
                        value.name)
                child_model = target_model.branch(idx=index.name)
                if not child_model.weight_index:
                    child_model.weight_with(index.name)
                ret = cpp_ast.Subscript(value, index)
                if child_model.is_scalar() and self.weighted:

                    ret = WeightOp(child_model.weight_index, ret)
                    self.data_model[ret] = child_model
                    return ret
                else:
                    self.data_model[ret] = child_model
                    return ret
            elif type(value) == cpp_ast.Subscript:
                target_model = self.get_or_create_model(value)
                if target_model.is_scalar():
                    raise ValueError('Invalid target for indexing: %s' %
                                     value.name)
                child_model = target_model.branch()
                new_index = cpp_ast.CName(
                    '(((%d)*(%s))+(%s))' %
                    (target_model.dimensions[0], value.index.generate(),
                     index.generate()))
                ret = cpp_ast.Subscript(value, new_index)
                if child_model.is_scalar() and self.weighted:
                    # This isn't fully general, and in fact only works for two level indexing.
                    ret = WeightOp(
                        child_model.weight_index
                        if child_model.weight_index else index, value)
                    self.data_model[ret] = child_model
                    return ret
                else:
                    ret = cpp_ast.Subscript(value.value, new_index)
                    self.data_model[ret] = child_model
                    return ret
            else:
                raise ValueError('Invalid target for indexing: %s' %
                                 str(value))
        else:
            #Nothing fancy here, just make sure everything gets written out right
            if type(value) == cpp_ast.CName:
                return cpp_ast.Subscipt(value, index)
            elif type(value) == cpp_ast.Subscript:

                if not target_model or target_model.is_scalar():
                    raise ValueError('Invalid target for indexing: %s' %
                                     value.name)
                child_model = target_model.branch()
                new_index = cpp_ast.CName(
                    '(((%d)*(%s))+(%s))' %
                    (target_model.dimensions[0], value.index.generate(),
                     index.generate()))
                return cpp_ast.Subscript(value.value, new_index)
            else:
                raise ValueError('Invalid target for indexing: %s' %
                                 str(value))