def compile_vforms(vfs, verbose=False): vfs = tuple(vfs) n = len(vfs) names = tuple('CustomAssembler%d' % i for i in range(n)) code = codegen.CodeGen() for (name, vf) in zip(names, vfs): codegen.AsmGenerator(vf, name, code).generate() src = codegen.preamble() + '\n' + code.result() mod = compile_cython_module(src, verbose=verbose) return tuple(getattr(mod, name) for name in names)
def compile_vforms(vfs, verbose=False): """Compile a list of vforms into assembler classes. This may be faster than compiling each vform individually since they are all combined into one source file. """ vfs = tuple(vfs) names = tuple('CustomAssembler%d' % i for i in range(len(vfs))) code = codegen.CodeGen() for (name, vf) in zip(names, vfs): codegen.AsmGenerator(vf, name, code).generate() src = codegen.preamble() + '\n' + code.result() mod = compile_cython_module(src, verbose=verbose) return tuple(getattr(mod, name) for name in names)
if __name__ == '__main__': _args = parse_args() vf = vform.VForm(dim=_args.dim) u, v = vf.basisfuns() # create scalar input fields if _args.scalarinput: for funcname in _args.scalarinput: locals()[funcname] = vf.input(funcname) # create vector input fields if _args.vectorinput: for funcname in _args.vectorinput: locals()[funcname] = vf.input(funcname, shape=(_args.dim, )) e = eval(_args.expr, vars(vform), locals()) if _args.dumptree: vform.tree_print(e) vf.add(e) code = backend.CodeGen() backend.AsmGenerator(vf, _args.name, code, on_demand=_args.ondemand).generate() f = open(_args.output, 'w') if _args.output else None print(backend.preamble(), file=f) print(code.result(), file=f) if _args.output: f.close()
def generate(vf, classname='CustomAssembler', on_demand=False): """Generate Cython code for an assembler class which implements the vform `vf`.""" code = codegen.CodeGen() codegen.AsmGenerator(vf, classname, code, on_demand=on_demand).generate() return codegen.preamble() + '\n' + code.result()
def test_codegen_wave_st2d(): code = codegen.CodeGen() vf = vform.wave_st_vf(2) assert (not vf.vec) and vf.arity == 2 and vf.spacetime codegen.AsmGenerator(vf, 'TestAsm', code).generate() code = codegen.preamble() + '\n' + code.result()
def test_codegen_vecfunctional(): code = codegen.CodeGen() vf = vector_L2functional_vf(3) assert vf.vec == 3 and vf.arity == 1 codegen.AsmGenerator(vf, 'TestAsm', code).generate() code = codegen.preamble() + '\n' + code.result()
def test_codegen_functional(): code = codegen.CodeGen() vf = vform.L2functional_vf(3, updatable=True) assert (not vf.vec) and vf.arity == 1 codegen.AsmGenerator(vf, 'TestAsm', code).generate() code = codegen.preamble() + '\n' + code.result()
def test_codegen_vectorlaplace2d(): code = codegen.CodeGen() vf = vector_laplace_vf(2) assert vf.vec == 2 * 2 and vf.arity == 2 codegen.AsmGenerator(vf, 'TestAsm', code).generate() code = codegen.preamble() + '\n' + code.result()
def test_codegen_poisson3d(): code = codegen.CodeGen() vf = my_stiffness_vf(3) assert (not vf.vec) and vf.arity == 2 codegen.AsmGenerator(vf, 'TestAsm', code).generate() code = codegen.preamble() + '\n' + code.result()
def gen(vf, classname): backend.AsmGenerator(vf, classname, code).generate()
def generate(vf, classname='CustomAssembler'): code = codegen.CodeGen() codegen.AsmGenerator(vf, classname, code).generate() return codegen.preamble() + '\n' + code.result()