Beispiel #1
0
 def get_view(self, orig_array, dtype, new_shape):
     strides, backstrides = support.calc_strides(new_shape, dtype,
                                                 self.order)
     return SliceArray(self.start,
                       strides,
                       backstrides,
                       new_shape,
                       self,
                       orig_array,
                       dtype=dtype)
Beispiel #2
0
 def astype(self, space, dtype):
     strides, backstrides = support.calc_strides(self.get_shape(), dtype,
                                                 self.order)
     impl = ConcreteArray(self.get_shape(), dtype, self.order,
                          strides, backstrides)
     if self.dtype.is_str_or_unicode() and not dtype.is_str_or_unicode():
         raise OperationError(space.w_NotImplementedError, space.wrap(
             "astype(%s) not implemented yet" % self.dtype))
     else:
         loop.setslice(space, impl.get_shape(), impl, self)
     return impl
Beispiel #3
0
    def from_shape(space, shape, dtype, order='C', w_instance=None):
        from pypy.module.micronumpy.arrayimpl import concrete, scalar

        if not shape:
            impl = scalar.Scalar(dtype.base)
        else:
            strides, backstrides = calc_strides(shape, dtype.base, order)
            impl = concrete.ConcreteArray(shape, dtype.base, order, strides,
                                      backstrides)
        if w_instance:
            return wrap_impl(space, space.type(w_instance), w_instance, impl)
        return W_NDimArray(impl)
Beispiel #4
0
 def astype(self, space, dtype):
     strides, backstrides = support.calc_strides(self.get_shape(), dtype,
                                                 self.order)
     impl = ConcreteArray(self.get_shape(), dtype, self.order, strides,
                          backstrides)
     if self.dtype.is_str_or_unicode() and not dtype.is_str_or_unicode():
         raise OperationError(
             space.w_NotImplementedError,
             space.wrap("astype(%s) not implemented yet" % self.dtype))
     else:
         loop.setslice(space, impl.get_shape(), impl, self)
     return impl
Beispiel #5
0
 def from_shape_and_storage(space, shape, storage, dtype, order='C', owning=False, w_subtype=None):
     from pypy.module.micronumpy.arrayimpl import concrete
     assert shape
     strides, backstrides = calc_strides(shape, dtype, order)
     if owning:
         # Will free storage when GCd
         impl = concrete.ConcreteArray(shape, dtype, order, strides,
                                             backstrides, storage=storage)
     else:
         impl = concrete.ConcreteArrayNotOwning(shape, dtype, order, strides,
                                             backstrides, storage)
     if w_subtype:
         w_ret = space.allocate_instance(W_NDimArray, w_subtype)
         W_NDimArray.__init__(w_ret, impl)
         space.call_method(w_ret, '__array_finalize__', w_subtype)
         return w_ret
     return W_NDimArray(impl)
Beispiel #6
0
 def set_shape(self, space, orig_array, new_shape):
     strides, backstrides = support.calc_strides(new_shape, self.dtype,
                                                 self.order)
     return SliceArray(0, strides, backstrides, new_shape, self, orig_array)
Beispiel #7
0
 def copy(self, space):
     strides, backstrides = support.calc_strides(self.get_shape(),
                                                 self.dtype, self.order)
     impl = ConcreteArray(self.get_shape(), self.dtype, self.order, strides,
                          backstrides)
     return loop.setslice(space, self.get_shape(), impl, self)
Beispiel #8
0
 def get_view(self, orig_array, dtype, new_shape):
     strides, backstrides = support.calc_strides(new_shape, dtype,
                                                 self.order)
     return SliceArray(self.start, strides, backstrides, new_shape,
                       self, orig_array, dtype=dtype)
Beispiel #9
0
 def set_shape(self, space, orig_array, new_shape):
     strides, backstrides = support.calc_strides(new_shape, self.dtype,
                                                 self.order)
     return SliceArray(0, strides, backstrides, new_shape, self,
                       orig_array)
Beispiel #10
0
 def copy(self, space):
     strides, backstrides = support.calc_strides(self.get_shape(), self.dtype,
                                                 self.order)
     impl = ConcreteArray(self.get_shape(), self.dtype, self.order, strides,
                          backstrides)
     return loop.setslice(space, self.get_shape(), impl, self)