def _mul_sparse_matrix(self, other): M, K1 = self.shape K2, N = other.shape indptr = np.empty_like(self.indptr) R, n = self.blocksize # convert to this format if isspmatrix_bsr(other): C = other.blocksize[1] else: C = 1 from csr import isspmatrix_csr if isspmatrix_csr(other) and n == 1: other = other.tobsr(blocksize=(n, C), copy=False) # lightweight conversion else: other = other.tobsr(blocksize=(n, C)) csr_matmat_pass1(M // R, N // C, self.indptr, self.indices, other.indptr, other.indices, indptr) bnnz = indptr[-1] indices = np.empty(bnnz, dtype=np.intc) data = np.empty(R * C * bnnz, dtype=upcast(self.dtype, other.dtype)) bsr_matmat_pass2( M // R, N // C, R, C, n, self.indptr, self.indices, np.ravel(self.data), other.indptr, other.indices, np.ravel(other.data), indptr, indices, data, ) data = data.reshape(-1, R, C) # TODO eliminate zeros return bsr_matrix((data, indices, indptr), shape=(M, N), blocksize=(R, C))
def _mul_sparse_matrix(self, other): M, K1 = self.shape K2, N = other.shape indptr = np.empty_like(self.indptr) R, n = self.blocksize #convert to this format if isspmatrix_bsr(other): C = other.blocksize[1] else: C = 1 from csr import isspmatrix_csr if isspmatrix_csr(other) and n == 1: other = other.tobsr(blocksize=(n, C), copy=False) #lightweight conversion else: other = other.tobsr(blocksize=(n, C)) csr_matmat_pass1( M/R, N/C, \ self.indptr, self.indices, \ other.indptr, other.indices, \ indptr) bnnz = indptr[-1] indices = np.empty(bnnz, dtype=np.intc) data = np.empty(R * C * bnnz, dtype=upcast(self.dtype, other.dtype)) bsr_matmat_pass2( M/R, N/C, R, C, n, \ self.indptr, self.indices, np.ravel(self.data), \ other.indptr, other.indices, np.ravel(other.data), \ indptr, indices, data) data = data.reshape(-1, R, C) #TODO eliminate zeros return bsr_matrix((data, indices, indptr), shape=(M, N), blocksize=(R, C))