def process_tile(self, tile): '' flat_data = tile.reshape((tile.shape[0], -1)) if self.task_data.use_torch: import torch masks = self.task_data.masks.get(self.meta.slice, transpose=True) # CuPy back-end disables torch in get_task_data # FIXME use GPU torch with CuPy array? result = torch.mm( torch.from_numpy(flat_data), torch.from_numpy(masks), ).numpy() # Required due to https://github.com/cupy/cupy/issues/4072 elif self.backend == 'cupy' and self.task_data.masks.use_sparse: masks = self.task_data.masks.get(self.meta.slice, transpose=False) result = masks.dot(flat_data.T).T # Required due to https://github.com/scipy/scipy/issues/13211 elif (self.backend == 'numpy' and self.task_data.masks.use_sparse and 'scipy.sparse' in self.task_data.masks.use_sparse): masks = self.task_data.masks.get(self.meta.slice, transpose=True) result = rmatmul(flat_data, masks) else: masks = self.task_data.masks.get(self.meta.slice, transpose=True) result = flat_data @ masks # '+' is the correct merge for dot product self.results.intensity[:] += result
def test_rmatmul_4(): le = np.zeros((2, 3)) ri = np.zeros((3, 2)) # Not a csc or csr matrix with pytest.raises(ValueError): rmatmul(le, ri)
def test_rmatmul_3(): le = np.zeros((2, 3)) ri = scipy.sparse.csr_matrix(np.zeros((5, 6))) # Shape mismatch with pytest.raises(ValueError): rmatmul(le, ri)
def test_rmatmul_2(): le = np.zeros((2, 3)) ri = np.zeros((4, 5, 6)) # 3D shape right with pytest.raises(ValueError, ): rmatmul(le, ri)
def test_rmatmul_1(): le = np.zeros((1, 2, 3)) ri = scipy.sparse.csr_matrix(np.zeros((5, 6))) # 3D shape left with pytest.raises(ValueError): rmatmul(le, ri)
def test_rmatmul_csc(): le = np.random.random((2, 3)) ri = scipy.sparse.csr_matrix(np.random.random((3, 2))) assert np.allclose(rmatmul(le, ri), le @ ri)