示例#1
0
 def execute(self, interp):
     w_lhs = self.lhs.execute(interp)
     if isinstance(self.rhs, SliceConstant):
         w_rhs = self.rhs.wrap(interp.space)
     else:
         w_rhs = self.rhs.execute(interp)
     if not isinstance(w_lhs, BaseArray):
         # scalar
         dtype = get_dtype_cache(interp.space).w_float64dtype
         w_lhs = scalar_w(interp.space, dtype, w_lhs)
     assert isinstance(w_lhs, BaseArray)
     if self.name == '+':
         w_res = w_lhs.descr_add(interp.space, w_rhs)
     elif self.name == '*':
         w_res = w_lhs.descr_mul(interp.space, w_rhs)
     elif self.name == '-':
         w_res = w_lhs.descr_sub(interp.space, w_rhs)
     elif self.name == '->':
         assert not isinstance(w_rhs, Scalar)
         if isinstance(w_rhs, FloatObject):
             w_rhs = IntObject(int(w_rhs.floatval))
         assert isinstance(w_lhs, BaseArray)
         w_res = w_lhs.descr_getitem(interp.space, w_rhs)
     else:
         raise NotImplementedError
     if (not isinstance(w_res, BaseArray) and
         not isinstance(w_res, interp_boxes.W_GenericBox)):
         dtype = get_dtype_cache(interp.space).w_float64dtype
         w_res = scalar_w(interp.space, dtype, w_res)
     return w_res
示例#2
0
 def execute(self, interp):
     w_lhs = self.lhs.execute(interp)
     if isinstance(self.rhs, SliceConstant):
         w_rhs = self.rhs.wrap(interp.space)
     else:
         w_rhs = self.rhs.execute(interp)
     if not isinstance(w_lhs, BaseArray):
         # scalar
         dtype = get_dtype_cache(interp.space).w_float64dtype
         w_lhs = scalar_w(interp.space, dtype, w_lhs)
     assert isinstance(w_lhs, BaseArray)
     if self.name == '+':
         w_res = w_lhs.descr_add(interp.space, w_rhs)
     elif self.name == '*':
         w_res = w_lhs.descr_mul(interp.space, w_rhs)
     elif self.name == '-':
         w_res = w_lhs.descr_sub(interp.space, w_rhs)
     elif self.name == '->':
         assert not isinstance(w_rhs, Scalar)
         if isinstance(w_rhs, FloatObject):
             w_rhs = IntObject(int(w_rhs.floatval))
         assert isinstance(w_lhs, BaseArray)
         w_res = w_lhs.descr_getitem(interp.space, w_rhs)
     else:
         raise NotImplementedError
     if (not isinstance(w_res, BaseArray)
             and not isinstance(w_res, interp_boxes.W_GenericBox)):
         dtype = get_dtype_cache(interp.space).w_float64dtype
         w_res = scalar_w(interp.space, dtype, w_res)
     return w_res
示例#3
0
 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
示例#4
0
 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
示例#5
0
 def execute(self, interp):
     w_lhs = self.lhs.execute(interp)
     if isinstance(self.rhs, SliceConstant):
         w_rhs = self.rhs.wrap(interp.space)
     else:
         w_rhs = self.rhs.execute(interp)
     assert isinstance(w_lhs, BaseArray)
     if self.name == '+':
         w_res = w_lhs.descr_add(interp.space, w_rhs)
     elif self.name == '*':
         w_res = w_lhs.descr_mul(interp.space, w_rhs)
     elif self.name == '-':
         w_res = w_lhs.descr_sub(interp.space, w_rhs)
     elif self.name == '->':
         if isinstance(w_rhs, Scalar):
             w_rhs = w_rhs.eval(w_rhs.start_iter()).wrap(interp.space)
             assert isinstance(w_rhs, FloatObject)
             w_rhs = IntObject(int(w_rhs.floatval))
         w_res = w_lhs.descr_getitem(interp.space, w_rhs)
     else:
         raise NotImplementedError
     if not isinstance(w_res, BaseArray):
         dtype = interp.space.fromcache(W_Float64Dtype)
         w_res = scalar_w(interp.space, dtype, w_res)
     return w_res
示例#6
0
 def execute(self, interp):
     w_lhs = self.lhs.execute(interp)
     assert isinstance(w_lhs, BaseArray)
     if isinstance(self.rhs, SliceConstant):
         # XXX interface has changed on multidim branch
         raise NotImplementedError
     w_rhs = self.rhs.execute(interp)
     if self.name == '+':
         w_res = w_lhs.descr_add(interp.space, w_rhs)
     elif self.name == '*':
         w_res = w_lhs.descr_mul(interp.space, w_rhs)
     elif self.name == '-':
         w_res = w_lhs.descr_sub(interp.space, w_rhs)            
     elif self.name == '->':
         if isinstance(w_rhs, Scalar):
             index = int(interp.space.float_w(
                 w_rhs.value.wrap(interp.space)))
             dtype = interp.space.fromcache(W_Float64Dtype)
             return Scalar(dtype, w_lhs.get_concrete().eval(index))
         else:
             raise NotImplementedError
     else:
         raise NotImplementedError
     if not isinstance(w_res, BaseArray):
         dtype = interp.space.fromcache(W_Float64Dtype)
         w_res = scalar_w(interp.space, dtype, w_res)
     return w_res
示例#7
0
 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)
示例#8
0
 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
示例#9
0
 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