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 convert_to_array(space, w_obj): if isinstance(w_obj, BaseArray): return w_obj elif space.issequence_w(w_obj): # Convert to array. return array(space, w_obj, w_order=None) else: # If it's a scalar dtype = interp_ufuncs.find_dtype_for_scalar(space, w_obj) return scalar_w(space, dtype, w_obj)
def convert_to_array(space, w_obj): if isinstance(w_obj, BaseArray): return w_obj elif space.issequence_w(w_obj): # Convert to array. return array(space, w_obj, w_order=None) else: # If it's a scalar dtype = interp_ufuncs.find_dtype_for_scalar(space, w_obj) return scalar_w(space, dtype, w_obj)
def array(space, w_item_or_iterable, w_dtype=None, w_order=NoneNotWrapped): # find scalar if not space.issequence_w(w_item_or_iterable): if space.is_w(w_dtype, space.w_None): w_dtype = interp_ufuncs.find_dtype_for_scalar( space, w_item_or_iterable) dtype = space.interp_w( interp_dtype.W_Dtype, space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype)) return scalar_w(space, dtype, w_item_or_iterable) if w_order is None: order = 'C' else: order = space.str_w(w_order) if order != 'C': # or order != 'F': raise operationerrfmt(space.w_ValueError, "Unknown order: %s", order) shape, elems_w = _find_shape_and_elems(space, w_item_or_iterable) # they come back in C order size = len(elems_w) if space.is_w(w_dtype, space.w_None): w_dtype = None for w_elem in elems_w: w_dtype = interp_ufuncs.find_dtype_for_scalar( space, w_elem, w_dtype) if w_dtype is interp_dtype.get_dtype_cache(space).w_float64dtype: break if w_dtype is None: w_dtype = space.w_None dtype = space.interp_w( interp_dtype.W_Dtype, space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype)) arr = W_NDimArray(size, shape[:], dtype=dtype, order=order) shapelen = len(shape) arr_iter = ArrayIterator(arr.size) for i in range(len(elems_w)): w_elem = elems_w[i] dtype.setitem(arr.storage, arr_iter.offset, dtype.coerce(space, w_elem)) arr_iter = arr_iter.next(shapelen) return arr
def descr_new_array(space, w_subtype, w_item_or_iterable, w_dtype=None, w_order=NoneNotWrapped): # find scalar if not space.issequence_w(w_item_or_iterable): if space.is_w(w_dtype, space.w_None): w_dtype = interp_ufuncs.find_dtype_for_scalar(space, w_item_or_iterable) dtype = space.interp_w(interp_dtype.W_Dtype, space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype) ) return scalar_w(space, dtype, w_item_or_iterable) if w_order is None: order = 'C' else: order = space.str_w(w_order) if order != 'C': # or order != 'F': raise operationerrfmt(space.w_ValueError, "Unknown order: %s", order) shape, elems_w = _find_shape_and_elems(space, w_item_or_iterable) # they come back in C order size = len(elems_w) if space.is_w(w_dtype, space.w_None): w_dtype = None for w_elem in elems_w: w_dtype = interp_ufuncs.find_dtype_for_scalar(space, w_elem, w_dtype) if w_dtype is space.fromcache(interp_dtype.W_Float64Dtype): break if w_dtype is None: w_dtype = space.w_None dtype = space.interp_w(interp_dtype.W_Dtype, space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype) ) arr = NDimArray(size, shape[:], dtype=dtype, order=order) shapelen = len(shape) arr_iter = arr.start_iter(arr.shape) for i in range(len(elems_w)): w_elem = elems_w[i] dtype.setitem_w(space, arr.storage, arr_iter.offset, w_elem) arr_iter = arr_iter.next(shapelen) return arr
def convert_to_array(space, w_obj): if isinstance(w_obj, BaseArray): return w_obj elif space.issequence_w(w_obj): # Convert to array. w_obj = space.call_function(space.gettypefor(BaseArray), w_obj) assert isinstance(w_obj, BaseArray) return w_obj else: # If it's a scalar dtype = interp_ufuncs.find_dtype_for_scalar(space, w_obj) return scalar_w(space, dtype, w_obj)
def convert_to_array(space, w_obj): from pypy.module.micronumpy.interp_numarray import array from pypy.module.micronumpy import interp_ufuncs if isinstance(w_obj, W_NDimArray): return w_obj elif issequence_w(space, w_obj): # Convert to array. return array(space, w_obj, w_order=None) else: # If it's a scalar dtype = interp_ufuncs.find_dtype_for_scalar(space, w_obj) return W_NDimArray.new_scalar(space, dtype, w_obj)
def descr__new__(space, w_subtype, w_size_or_iterable, w_dtype=None): l = space.listview(w_size_or_iterable) if space.is_w(w_dtype, space.w_None): w_dtype = None for w_item in l: w_dtype = interp_ufuncs.find_dtype_for_scalar(space, w_item, w_dtype) if w_dtype is space.fromcache(interp_dtype.W_Float64Dtype): break if w_dtype is None: w_dtype = space.w_None dtype = space.interp_w(interp_dtype.W_Dtype, space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype) ) arr = SingleDimArray(len(l), dtype=dtype) i = 0 for w_elem in l: dtype.setitem_w(space, arr.storage, i, w_elem) i += 1 return arr
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])