def apply(self, space, orig_arr): arr = orig_arr.implementation ofs, subdtype = arr.dtype.fields[self.name] # strides backstrides are identical, ofs only changes start return W_NDimArray.new_slice(space, arr.start + ofs, arr.get_strides(), arr.get_backstrides(), arr.shape, arr, orig_arr, subdtype)
def new_view(space, w_arr, chunks): arr = w_arr.implementation dim = -1 for i, c in enumerate(chunks): if isinstance(c, BooleanChunk): dim = i break if dim >= 0: # filter by axis dim filtr = chunks[dim] assert isinstance(filtr, BooleanChunk) # XXX this creates a new array, and fails in setitem w_arr = w_arr.getitem_filter(space, filtr.w_idx, axis=dim) arr = w_arr.implementation chunks[dim] = SliceChunk( space.newslice(space.wrap(0), space.w_None, space.w_None)) r = calculate_slice_strides(space, arr.shape, arr.start, arr.get_strides(), arr.get_backstrides(), chunks) else: r = calculate_slice_strides(space, arr.shape, arr.start, arr.get_strides(), arr.get_backstrides(), chunks) shape, start, strides, backstrides = r return W_NDimArray.new_slice(space, start, strides[:], backstrides[:], shape[:], arr, w_arr)
def apply(self, space, orig_arr): arr = orig_arr.implementation ofs, subdtype = arr.dtype.fields[self.name] # strides backstrides are identical, ofs only changes start return W_NDimArray.new_slice(space, arr.start + ofs, arr.get_strides(), arr.get_backstrides(), arr.shape, arr, orig_arr, subdtype)
def new_view(space, w_arr, chunks): arr = w_arr.implementation r = calculate_slice_strides(space, arr.shape, arr.start, arr.get_strides(), arr.get_backstrides(), chunks) shape, start, strides, backstrides = r return W_NDimArray.new_slice(space, start, strides[:], backstrides[:], shape[:], arr, w_arr)
def apply(self, space, orig_arr): arr = orig_arr.implementation shape = self.extend_shape(arr.shape) r = calculate_slice_strides(arr.shape, arr.start, arr.get_strides(), arr.get_backstrides(), self.l) _, start, strides, backstrides = r return W_NDimArray.new_slice(space, start, strides[:], backstrides[:], shape[:], arr, orig_arr)
def apply(self, space, orig_arr): arr = orig_arr.implementation shape = self.extend_shape(arr.shape) r = calculate_slice_strides(arr.shape, arr.start, arr.get_strides(), arr.get_backstrides(), self.l) _, start, strides, backstrides = r return W_NDimArray.new_slice(space, start, strides[:], backstrides[:], shape[:], arr, orig_arr)
def swapaxes(self, space, orig_arr, axis1, axis2): shape = self.get_shape()[:] strides = self.get_strides()[:] backstrides = self.get_backstrides()[:] shape[axis1], shape[axis2] = shape[axis2], shape[axis1] strides[axis1], strides[axis2] = strides[axis2], strides[axis1] backstrides[axis1], backstrides[axis2] = backstrides[axis2], backstrides[axis1] return W_NDimArray.new_slice(space, self.start, strides, backstrides, shape, self, orig_arr)
def swapaxes(self, space, orig_arr, axis1, axis2): shape = self.get_shape()[:] strides = self.get_strides()[:] backstrides = self.get_backstrides()[:] shape[axis1], shape[axis2] = shape[axis2], shape[axis1] strides[axis1], strides[axis2] = strides[axis2], strides[axis1] backstrides[axis1], backstrides[axis2] = backstrides[axis2], backstrides[axis1] return W_NDimArray.new_slice(space, self.start, strides, backstrides, shape, self, orig_arr)
def apply(self, space, orig_arr): arr = orig_arr.implementation ofs, subdtype = arr.dtype.fields[self.name] # ofs only changes start # create a view of the original array by extending # the shape, strides, backstrides of the array strides, backstrides = calc_strides(subdtype.shape, subdtype.subdtype, arr.order) final_shape = arr.shape + subdtype.shape final_strides = arr.get_strides() + strides final_backstrides = arr.get_backstrides() + backstrides final_dtype = subdtype if subdtype.subdtype: final_dtype = subdtype.subdtype return W_NDimArray.new_slice(space, arr.start + ofs, final_strides, final_backstrides, final_shape, arr, orig_arr, final_dtype)
def apply(self, space, orig_arr): arr = orig_arr.implementation ofs, subdtype = arr.dtype.fields[self.name] # ofs only changes start # create a view of the original array by extending # the shape, strides, backstrides of the array strides, backstrides = calc_strides(subdtype.shape, subdtype.subdtype, arr.order) final_shape = arr.shape + subdtype.shape final_strides = arr.get_strides() + strides final_backstrides = arr.get_backstrides() + backstrides final_dtype = subdtype if subdtype.subdtype: final_dtype = subdtype.subdtype return W_NDimArray.new_slice(space, arr.start + ofs, final_strides, final_backstrides, final_shape, arr, orig_arr, final_dtype)
def new_view(space, w_arr, chunks): arr = w_arr.implementation dim = -1 for i, c in enumerate(chunks): if isinstance(c, BooleanChunk): dim = i break if dim >= 0: # filter by axis dim filtr = chunks[dim] assert isinstance(filtr, BooleanChunk) # XXX this creates a new array, and fails in setitem w_arr = w_arr.getitem_filter(space, filtr.w_idx, axis=dim) arr = w_arr.implementation chunks[dim] = SliceChunk(space.newslice(space.wrap(0), space.w_None, space.w_None)) r = calculate_slice_strides(space, arr.shape, arr.start, arr.get_strides(), arr.get_backstrides(), chunks) else: r = calculate_slice_strides(space, arr.shape, arr.start, arr.get_strides(), arr.get_backstrides(), chunks) shape, start, strides, backstrides = r return W_NDimArray.new_slice(space, start, strides[:], backstrides[:], shape[:], arr, w_arr)