def broadcast_to(self, shape): b = array_utils.broadcast(self.shape, shape) result_block_shape = array_utils.broadcast_block_shape(self.shape, shape, self.block_shape) result: BlockArrayBase = BlockArrayBase(ArrayGrid(b.shape, result_block_shape, self.grid.dtype.__name__), self.system) extras = [] # Below taken directly from _broadcast_to in numpy's stride_tricks.py. it = np.nditer( (self.blocks,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras, op_flags=['readonly'], itershape=result.grid.grid_shape, order='C') with it: # never really has writebackifcopy semantics broadcast = it.itviews[0] result.blocks = broadcast return result
def __inequality__(self, op, other): other = self.check_or_convert_other(other) assert other.shape == () or other.shape == self.shape, \ "Currently supports comparison with scalars only." shape = array_utils.broadcast(self.shape, other.shape).shape block_shape = array_utils.broadcast_block_shape(self.shape, other.shape, self.block_shape) dtype = np.bool.__name__ grid = ArrayGrid(shape, block_shape, dtype) result = BlockArray(grid, self.system) for grid_entry in result.grid.get_entry_iterator(): if other.shape == (): other_block: Block = other.blocks.item() else: other_block: Block = other.blocks[grid_entry] result.blocks[grid_entry] = self.blocks[grid_entry].bop(op, other_block, args={}) return result