def numpyfy(expr,parallel = False,restype = None): from expresso.pycas.evaluators.optimizers import optimize_for_compilation compiler = NumpyCompiler() res = compiler.visit(optimize_for_compilation(e.S(expr))) if restype is None: restype = f.Type(expr).evaluate(cache=compiler.cache).value if isinstance(restype,f.TypeInfo): restype = restype.__dict__.get('python_type') if restype == None: restype = complex else: restype = complex def call(**args): args,shape = prepare_arguments(args) cres = np.array(res(args)).astype(restype) if not shape: if cres.shape: cres = cres[0] else: if shape and cres.shape != shape: cres = np.ones(shape)*cres return cres call.restype = restype if parallel: return make_parallel(call) else: return call
def numpyfy(expr, parallel=False, restype=None): from expresso.pycas.evaluators.optimizers import optimize_for_compilation compiler = NumpyCompiler() res = compiler.visit(optimize_for_compilation(e.S(expr))) if restype is None: restype = f.Type(expr).evaluate(cache=compiler.cache).value if isinstance(restype, f.TypeInfo): restype = restype.__dict__.get('python_type') if restype == None: restype = complex else: restype = complex def call(**args): args, shape = prepare_arguments(args) cres = np.array(res(args)).astype(restype) if not shape: if cres.shape: cres = cres[0] else: if shape and cres.shape != shape: cres = np.ones(shape) * cres return cres call.restype = restype if parallel: return make_parallel(call) else: return call
def get_optimized(self,expr,**kwargs): from expresso.pycas.evaluators.optimizers import optimize_for_compilation return optimize_for_compilation(self.get_unitless(expr,**kwargs),cache = self.get_cache())
def approximate(self,prec = 16,**kwargs): from expresso.pycas.evaluators.optimizers import optimize_for_compilation return optimize_for_compilation(self,prec=prec,**kwargs)
def optimize_function(self,expr): from expresso.pycas.evaluators.optimizers import optimize_for_compilation return optimize_for_compilation(expr)
def approximate(self, prec=16, **kwargs): from expresso.pycas.evaluators.optimizers import optimize_for_compilation return optimize_for_compilation(self, prec=prec, **kwargs)
def optimize_function(self, expr): from expresso.pycas.evaluators.optimizers import optimize_for_compilation return optimize_for_compilation(expr)
def get_optimized(self, expr, **kwargs): from expresso.pycas.evaluators.optimizers import optimize_for_compilation return optimize_for_compilation(self.get_unitless(expr, **kwargs), cache=self.get_cache())