def f(i): ar = SingleDimArray(i, dtype=self.float64_dtype) v1 = interp_ufuncs.get(self.space).add.call(space, [ar, scalar_w(space, self.float64_dtype, space.wrap(4.5))]) assert isinstance(v1, BaseArray) v2 = interp_ufuncs.get(self.space).multiply.call(space, [v1, scalar_w(space, self.float64_dtype, space.wrap(4.5))]) v1.force_if_needed() assert isinstance(v2, BaseArray) return v2.get_concrete().eval(3).val
def f(i): ar = SingleDimArray(i, dtype=self.float64_dtype) v1 = interp_ufuncs.get(self.space).add.call(space, [ar, ar]) v2 = interp_ufuncs.get(self.space).negative.call(space, [v1]) v2.get_concrete() for i in xrange(5): v1 = interp_ufuncs.get(self.space).multiply.call(space, [ar, ar]) v2 = interp_ufuncs.get(self.space).negative.call(space, [v1]) v2.get_concrete()
def execute(self, interp): if self.name in SINGLE_ARG_FUNCTIONS: if len(self.args) != 1: raise ArgumentMismatch arr = self.args[0].execute(interp) if not isinstance(arr, BaseArray): raise ArgumentNotAnArray if self.name == "sum": w_res = arr.descr_sum(interp.space) elif self.name == "prod": w_res = arr.descr_prod(interp.space) elif self.name == "max": w_res = arr.descr_max(interp.space) elif self.name == "min": w_res = arr.descr_min(interp.space) elif self.name == "any": w_res = arr.descr_any(interp.space) elif self.name == "all": w_res = arr.descr_all(interp.space) elif self.name == "unegative": neg = interp_ufuncs.get(interp.space).negative w_res = neg.call(interp.space, [arr]) else: assert False # unreachable code if isinstance(w_res, BaseArray): return w_res if isinstance(w_res, FloatObject): dtype = interp.space.fromcache(W_Float64Dtype) elif isinstance(w_res, BoolObject): dtype = interp.space.fromcache(W_BoolDtype) else: dtype = None return scalar_w(interp.space, dtype, w_res) else: raise WrongFunctionName
def execute(self, interp): arr = self.args[0].execute(interp) if not isinstance(arr, BaseArray): raise ArgumentNotAnArray if self.name in SINGLE_ARG_FUNCTIONS: if len(self.args) != 1 and self.name != 'sum': raise ArgumentMismatch if self.name == "sum": if len(self.args)>1: w_res = arr.descr_sum(interp.space, self.args[1].execute(interp)) else: w_res = arr.descr_sum(interp.space) elif self.name == "prod": w_res = arr.descr_prod(interp.space) elif self.name == "max": w_res = arr.descr_max(interp.space) elif self.name == "min": w_res = arr.descr_min(interp.space) elif self.name == "any": w_res = arr.descr_any(interp.space) elif self.name == "all": w_res = arr.descr_all(interp.space) elif self.name == "unegative": neg = interp_ufuncs.get(interp.space).negative w_res = neg.call(interp.space, [arr]) elif self.name == "flat": w_res = arr.descr_get_flatiter(interp.space) elif self.name == "tostring": arr.descr_tostring(interp.space) w_res = None else: assert False # unreachable code elif self.name in TWO_ARG_FUNCTIONS: if len(self.args) != 2: raise ArgumentMismatch arg = self.args[1].execute(interp) if not isinstance(arg, BaseArray): raise ArgumentNotAnArray if not isinstance(arg, BaseArray): raise ArgumentNotAnArray if self.name == "dot": w_res = arr.descr_dot(interp.space, arg) elif self.name == 'take': w_res = arr.descr_take(interp.space, arg) else: assert False # unreachable code else: raise WrongFunctionName if isinstance(w_res, BaseArray): return w_res if isinstance(w_res, FloatObject): dtype = get_dtype_cache(interp.space).w_float64dtype elif isinstance(w_res, BoolObject): dtype = get_dtype_cache(interp.space).w_booldtype elif isinstance(w_res, interp_boxes.W_GenericBox): dtype = w_res.get_dtype(interp.space) else: dtype = None return scalar_w(interp.space, dtype, w_res)
def impl(self, space, w_other): w_other = scalar_w( space, interp_ufuncs.find_dtype_for_scalar(space, w_other, self.find_dtype()), w_other) return getattr(interp_ufuncs.get(space), ufunc_name).call(space, [w_other, self])
def f(i): ar = SingleDimArray(i, dtype=self.float64_dtype) v = interp_ufuncs.get(self.space).add.call(self.space, [ ar, scalar_w(self.space, self.float64_dtype, self.space.wrap(4.5)) ], ) assert isinstance(v, BaseArray) return v.get_concrete().eval(3).val
def f(i): step = 3 ar = SingleDimArray(step*i, dtype=self.float64_dtype) new_sig = signature.Signature.find_sig([ SingleDimSlice.signature, ar.signature ]) s = SingleDimSlice(0, step*i, step, i, ar, new_sig) v = interp_ufuncs.get(self.space).add.call(self.space, [s, s]) return v.get_concrete().eval(3).val
def f(i): step1 = 2 step2 = 3 ar = NDimArray(step2*i, dtype=self.float64_dtype) new_sig = signature.Signature.find_sig([ NDimSlice.signature, ar.signature ]) s1 = NDimSlice(0, step1*i, step1, i, ar, new_sig) new_sig = signature.Signature.find_sig([ NDimSlice.signature, s1.signature ]) s2 = NDimSlice(0, step2*i, step2, i, ar, new_sig) v = interp_ufuncs.get(self.space).add.call(self.space, [s1, s2]) return v.get_concrete().eval(3).val
def execute(self, interp): if self.name in SINGLE_ARG_FUNCTIONS: if len(self.args) != 1 and self.name != 'sum': raise ArgumentMismatch arr = self.args[0].execute(interp) if not isinstance(arr, BaseArray): raise ArgumentNotAnArray if self.name == "sum": if len(self.args) > 1: w_res = arr.descr_sum(interp.space, self.args[1].execute(interp)) else: w_res = arr.descr_sum(interp.space) elif self.name == "prod": w_res = arr.descr_prod(interp.space) elif self.name == "max": w_res = arr.descr_max(interp.space) elif self.name == "min": w_res = arr.descr_min(interp.space) elif self.name == "any": w_res = arr.descr_any(interp.space) elif self.name == "all": w_res = arr.descr_all(interp.space) elif self.name == "unegative": neg = interp_ufuncs.get(interp.space).negative w_res = neg.call(interp.space, [arr]) else: assert False # unreachable code if isinstance(w_res, BaseArray): return w_res if isinstance(w_res, FloatObject): dtype = get_dtype_cache(interp.space).w_float64dtype elif isinstance(w_res, BoolObject): dtype = get_dtype_cache(interp.space).w_booldtype elif isinstance(w_res, interp_boxes.W_GenericBox): dtype = w_res.get_dtype(interp.space) else: dtype = None return scalar_w(interp.space, dtype, w_res) else: raise WrongFunctionName
def impl(self, space, w_other): return getattr(interp_ufuncs.get(space), ufunc_name).call(space, [self, w_other])
def impl(self, space): return getattr(interp_ufuncs.get(space), ufunc_name).descr_reduce(space, self)
def descr_std(self, space): # std(v) = sqrt(var(v)) return interp_ufuncs.get(space).sqrt.call(space, [self.descr_var(space)])
def impl(self, space, w_axis=None): if space.is_w(w_axis, space.w_None): w_axis = space.wrap(-1) return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space, self, True, promote_to_largest, w_axis)
def impl(self, space): from pypy.module.micronumpy import interp_ufuncs return getattr(interp_ufuncs.get(space), ufunc_name).call(space, [self])
def impl(self, space): return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space, self, multidim=True)
def impl(self, space, w_other): w_other = scalar_w(space, interp_ufuncs.find_dtype_for_scalar(space, w_other, self.find_dtype()), w_other ) return getattr(interp_ufuncs.get(space), ufunc_name).call(space, [w_other, self])
def f(i): ar = SingleDimArray(i, dtype=self.float64_dtype) v = interp_ufuncs.get(self.space).add.call(self.space, [ar, ar]) return v.get_concrete().eval(3).val
def impl(self, space, w_other, w_out=None): from pypy.module.micronumpy import interp_ufuncs return getattr(interp_ufuncs.get(space), ufunc_name).call(space, [w_other, self, w_out])