Skip to content

cupyx.scipy.sparse.block_diag working with cupy sparse matrix on GPU #7058

@tagerjump

Description

@tagerjump

Description

Thanks to Cupy, I'm able to migrate my project from CPU to GPU.

However, I rely on scipy.sparse.diag_block operation, which is not available in Cupy. I have to do this on CPU with scipy and transfer the data to GPU. We have linalg.block_diag but that only takes dense matrix. Is there any plan to implement it for sparse matrix as well? If not, is there a way around or I have to implement it myself? Following is an example of my usage.

ideal:

matricies = []
for i in range(num):
        data, row, col = cp.random.rand(size),  cp.random.rand(size),  cp.random.rand(size)
        coo_matrix = cupyx.scipy.sparse.coo_matrix(data, (row, col)
        matricies.append(coo_matrix )
block = cupyx.scipy.sparse.block_diag(matricies)

Currently, I have to diag block it with scipy and transfer it to GPU, lossing a lot of performance.

matricies = []
for i in range(num):
        data, row, col = np.random.rand(size),  np.random.rand(size),  np.random.rand(size)
        coo_matrix = scipy.sparse.coo_matrix(data, (row, col)
        matricies.append(coo_matrix )
block = scipy.sparse.block_diag(matricies)
block_cp = cupyx.scipy.sparse.csr_matrix(block)

Thanks

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions