def coo2csr(x): handle = device.get_cusparse_handle() m = x.shape[0] indptr = cupy.empty(m + 1, 'i') cusparse.xcoo2csr(handle, x.row.data.ptr, x.nnz, m, indptr.data.ptr, cusparse.CUSPARSE_INDEX_BASE_ZERO) return cupyx.scipy.sparse.csr.csr_matrix((x.data, x.col, indptr), shape=x.shape)
def coo2csc(x): handle = device.get_cusparse_handle() n = x.shape[1] indptr = cupy.empty(n + 1, 'i') cusparse.xcoo2csr(handle, x.col.data.ptr, x.nnz, n, indptr.data.ptr, cusparse.CUSPARSE_INDEX_BASE_ZERO) return cupyx.scipy.sparse.csc.csc_matrix((x.data, x.row, indptr), shape=x.shape)
def coo2csc(x): handle = _device.get_cusparse_handle() n = x.shape[1] nnz = x.nnz if nnz == 0: indptr = _cupy.zeros(n + 1, 'i') else: indptr = _cupy.empty(n + 1, 'i') _cusparse.xcoo2csr(handle, x.col.data.ptr, nnz, n, indptr.data.ptr, _cusparse.CUSPARSE_INDEX_BASE_ZERO) return cupyx.scipy.sparse.csc.csc_matrix((x.data, x.row, indptr), shape=x.shape)