Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cupyx.scipy.sparse.bmat default return format is different than scipy.sparse.bmat #8308

Open
ivirshup opened this issue Apr 25, 2024 · 1 comment

Comments

@ivirshup
Copy link

ivirshup commented Apr 25, 2024

Description

Cupy's sparse bmat returns a coo matrix when calling bmat on a grid of csr matrices where scipy returns a csr matrix.

I would expect the result format to be the same.

To Reproduce

import cupyx.scipy.sparse as cpsparse
from scipy import sparse

X_gpu = cpsparse.random(20, 10, format="csr")
X_cpu = X_gpu.get()

assert sparse.bmat([[X_cpu, X_cpu], [X_cpu, X_cpu]]).format == "csr"

assert cpsparse.bmat([[X_gpu, X_gpu], [X_gpu, X_gpu]]).format == "csr"
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[4], [line 9](vscode-notebook-cell:?execution_count=4&line=9)
      [5](vscode-notebook-cell:?execution_count=4&line=5) X_cpu = X_gpu.get()
      [7](vscode-notebook-cell:?execution_count=4&line=7) assert sparse.bmat([[X_cpu, X_cpu], [X_cpu, X_cpu]]).format == "csr"
----> [9](vscode-notebook-cell:?execution_count=4&line=9) assert cpsparse.bmat([[X_gpu, X_gpu], [X_gpu, X_gpu]]).format == "csr"

AssertionError:

Installation

None

Environment

 OS                           : Linux-5.15.0-101-generic-x86_64-with-glibc2.35
Python Version               : 3.12.2
CuPy Version                 : 13.1.0
CuPy Platform                : NVIDIA CUDA
NumPy Version                : 1.26.4
SciPy Version                : 1.12.0
Cython Build Version         : 0.29.37
Cython Runtime Version       : None
CUDA Root                    : /usr/local/cuda
nvcc PATH                    : /usr/local/cuda/bin/nvcc
CUDA Build Version           : 12000
CUDA Driver Version          : 12040
CUDA Runtime Version         : 12000 (linked to CuPy) / 12040 (locally installed)
cuBLAS Version               : (available)
cuFFT Version                : 11201
cuRAND Version               : 10305
cuSOLVER Version             : (11, 6, 1)
cuSPARSE Version             : (available)
NVRTC Version                : (12, 4)
Thrust Version               : 200001
CUB Build Version            : 200200
Jitify Build Version         : <unknown>
cuDNN Build Version          : None
cuDNN Version                : None
NCCL Build Version           : None
NCCL Runtime Version         : None
cuTENSOR Version             : None
cuSPARSELt Build Version     : None
Device 0 Name                : Tesla T4
Device 0 Compute Capability  : 75
Device 0 PCI Bus ID          : 0000:00:06.0

Additional Information

There is similar behaviour with hstack:

assert sparse.hstack([X_cpu, X_cpu]).format == "csr"
assert not cpsparse.hstack([X_gpu, X_gpu]).format == "csr"
@ivirshup ivirshup added the cat:bug Bugs label Apr 25, 2024
@ivirshup ivirshup changed the title cupyx.scipy.sparse.bmat default return type is different than scipy.sparse.bmat cupyx.scipy.sparse.bmat default return format is different than scipy.sparse.bmat Apr 25, 2024
@ivirshup ivirshup mentioned this issue Apr 25, 2024
18 tasks
@takagi takagi self-assigned this Apr 30, 2024
@takagi takagi removed their assignment May 1, 2024
@takagi
Copy link
Member

takagi commented May 1, 2024

Thanks for your report! I could reproduce the your result, and it seems that cupy.scipy.sparse haven't been following scipy.sparse's changes for recent years.

Are you interested in contributing to cupy's bmat to make it get along with the latest scipy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants