def __mul__(self, other): if cupy.isscalar(other): self.sum_duplicates() return self._with_data(self.data * other) elif isspmatrix_csr(other): self.sum_duplicates() other.sum_duplicates() return cusparse.csrgemm(self, other) elif csc.isspmatrix_csc(other): self.sum_duplicates() other.sum_duplicates() return cusparse.csrgemm(self, other.T, transb=True) elif base.isspmatrix(other): return self * other.tocsr() elif base.isdense(other): if other.ndim == 0: self.sum_duplicates() return self._with_data(self.data * other) elif other.ndim == 1: self.sum_duplicates() return cusparse.csrmv(self, cupy.asfortranarray(other)) elif other.ndim == 2: self.sum_duplicates() return cusparse.csrmm2(self, cupy.asfortranarray(other)) else: raise ValueError('could not interpret dimensions') else: return NotImplemented
def __mul__(self, other): if cupy.isscalar(other): self.sum_duplicates() return self._with_data(self.data * other) elif isspmatrix_csr(other): self.sum_duplicates() other.sum_duplicates() return cusparse.csrgemm(self, other) elif csc.isspmatrix_csc(other): self.sum_duplicates() other.sum_duplicates() return cusparse.csrgemm(self, other.T, transb=True) elif base.isspmatrix(other): return self * other.tocsr() elif base.isdense(other): if other.ndim == 0: self.sum_duplicates() return self._with_data(self.data * other) elif other.ndim == 1: self.sum_duplicates() other = cupy.asfortranarray(other) # csrmvEx does not work if nnz == 0 if self.nnz > 0 and cusparse.csrmvExIsAligned(self, other): if cupy.cuda.cub_enabled and other.flags.c_contiguous: return device_csrmv(self.shape[0], self.shape[1], self.nnz, self.data, self.indptr, self.indices, other) else: return cusparse.csrmvEx(self, other) else: return cusparse.csrmv(self, other) elif other.ndim == 2: self.sum_duplicates() return cusparse.csrmm2(self, cupy.asfortranarray(other)) else: raise ValueError('could not interpret dimensions') else: return NotImplemented