def test_create_ops_arg_constant(self): a = Constant(name='*a') ops_arg = create_ops_arg(a, {}, {}, {}) assert ops_arg.ops_type == namespace['ops_arg_gbl'] assert str(ops_arg.ops_name) == str(Byref(Constant(name='a'))) assert ops_arg.elements_per_point == 1 assert ops_arg.dtype == Literal('"%s"' % dtype_to_cstr(a.dtype)) assert ops_arg.rw_flag == namespace['ops_read']
def test_create_ops_arg_constant(self): a = Constant(name='*a') res = create_ops_arg(a, {}, {}, {}) assert type(res) == namespace['ops_arg_gbl'] assert str(res.args[0]) == str(Byref(Constant(name='a'))) assert res.args[1] == 1 assert res.args[2] == Literal('"%s"' % dtype_to_cstr(a.dtype)) assert res.args[3] == namespace['ops_read']
def test_create_ops_arg_constant(self): a = Constant(name='*a') res = create_ops_arg(a, {}, {}) assert res.name == namespace['ops_arg_gbl'].name assert res.args == [ Byref(Constant(name='a')), 1, Literal('"%s"' % dtype_to_cstr(a.dtype)), namespace['ops_read'] ]
def create_ops_arg(p, accessible_origin, name_to_ops_dat, par_to_ops_stencil): elements_per_point = 1 dtype = Literal('"%s"' % dtype_to_cstr(p.dtype)) if p.is_Constant: ops_type = namespace['ops_arg_gbl'] ops_name = Byref(Constant(name=p.name[1:])) rw_flag = namespace['ops_read'] else: ops_type = namespace['ops_arg_dat'] accessible_info = accessible_origin[p.name] ops_name = name_to_ops_dat[p.name] \ if accessible_info.time is None \ else name_to_ops_dat[accessible_info.origin_name].\ indexify([Add(accessible_info.time, accessible_info.shift)]) rw_flag = namespace['ops_read'] if p.read_only else namespace[ 'ops_write'] ops_arg = OpsArgDecl(ops_type=ops_type, ops_name=ops_name, elements_per_point=elements_per_point, dtype=dtype, rw_flag=rw_flag) return ops_arg
def new_ops_gbl(self, c): if c in self.ops_args: return self.ops_args[c] new_c = Constant(name='*%s' % c.name, dtype=c.dtype) self.ops_args[c] = new_c return new_c
def create_ops_arg(p, name_to_ops_dat, par_to_ops_stencil): if p.is_Constant: return namespace['ops_arg_gbl']( Byref(Constant(name=p.name[1:])), 1, Literal('"%s"' % dtype_to_cstr(p.dtype)), namespace['ops_read']) else: return namespace['ops_arg_dat']( name_to_ops_dat[p.name], 1, par_to_ops_stencil[p], Literal('"%s"' % dtype_to_cstr(p.dtype)), namespace['ops_read'] if p.read_only else namespace['ops_write'])
def create_ops_arg(p, accessible_origin, name_to_ops_dat, par_to_ops_stencil): if p.is_Constant: return namespace['ops_arg_gbl']( Byref(Constant(name=p.name[1:])), 1, Literal('"%s"' % dtype_to_cstr(p.dtype)), namespace['ops_read']) else: accessible_info = accessible_origin[p.name] dat_name = name_to_ops_dat[p.name] \ if accessible_info.time is None \ else name_to_ops_dat[accessible_info.origin_name].\ indexify([accessible_info.time]) return namespace['ops_arg_dat']( dat_name, 1, par_to_ops_stencil[p], Literal('"%s"' % dtype_to_cstr(p.dtype)), namespace['ops_read'] if p.read_only else namespace['ops_write'])
def get_ops_args(args, stencils, name_to_dat): ops_args = [] for arg in args: if arg.is_Constant: ops_args.append( Call("ops_arg_gbl", [ Byref(Constant(name=arg.name[1:])), 1, String(dtype_to_cstr(arg.dtype)), OPS_READ ], False)) else: ops_args.append( Call("ops_arg_dat", [ name_to_dat[arg.name], 1, stencils[arg.name], String(dtype_to_cstr(arg.dtype)), OPS_WRITE if arg.is_Write else OPS_READ ], False)) return ops_args
def __new__(cls, **kwargs): name = kwargs.get('name', cls.name) value = cls.default_value() obj = Constant.__new__(cls, name=name, dtype=np.int32, value=value) obj.aliases = as_tuple(kwargs.get('aliases')) + (name, ) return obj