Пример #1
0
 def compute(self):
     result = W_NDimArray(self.size, self.shape, self.find_dtype())
     shapelen = len(self.shape)
     sig = self.find_sig()
     frame = sig.create_frame(self)
     ri = ArrayIterator(self.size)
     while not ri.done():
         numpy_driver.jit_merge_point(sig=sig,
                                      shapelen=shapelen,
                                      result_size=self.size,
                                      frame=frame,
                                      ri=ri,
                                      self=self, result=result)
         result.dtype.setitem(result.storage, ri.offset,
                              sig.eval(frame, self))
         frame.next(shapelen)
         ri = ri.next(shapelen)
     return result
Пример #2
0
 def compute(self):
     result = W_NDimArray(self.size, self.shape, self.find_dtype())
     shapelen = len(self.shape)
     sig = self.find_sig()
     frame = sig.create_frame(self)
     ri = ArrayIterator(self.size)
     while not ri.done():
         numpy_driver.jit_merge_point(sig=sig,
                                      shapelen=shapelen,
                                      result_size=self.size,
                                      frame=frame,
                                      ri=ri,
                                      self=self,
                                      result=result)
         result.dtype.setitem(result.storage, ri.offset,
                              sig.eval(frame, self))
         frame.next(shapelen)
         ri = ri.next(shapelen)
     return result
Пример #3
0
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
Пример #4
0
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
Пример #5
0
 def allocate_iter(self, arr, transforms):
     return ArrayIterator(arr.size).apply_transformations(arr, transforms)