cupy.scipy.sparse.csrmatrix gives unhelpful error message when np.ndarray is passed
- Dominant language
- Python
- Stars
- 12.3k
- Forks
- 1.1k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 46
Description
# Problem description
```
cupyx.scipy.sparse.csr_matrix((
np.ones([4], np.int32),
np.array([1, 2, 3, 4], np.int32),
np.array([0, 2, 3])
))
```
gives following error.
```
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
7 np.ones([4], np.int32),
8 np.array([1, 2, 3, 4], np.int32),
----> 9 np.array([0, 2, 3])
10 ))
/usr/local/lib/python3.6/dist-packages/cupyx/scipy/sparse/compressed.py in __init__(self, arg1, shape, dtype, copy)
81 base.isdense(indptr) and indptr.ndim == 1):
82 raise ValueError(
---> 83 'data, indices, and indptr should be 1-D')
84
85 if len(data) != len(indices):
```
Input tensors are indeed 1-D. The problem is that trigger for this `ValueError` is:
```
if not (base.isdense(data) and data.ndim == 1 and
base.isdense(indices) and indices.ndim == 1 and
base.isdense(indptr) and indptr.ndim == 1):
raise ValueError(
'data, indices, and indptr should be 1-D')
```
https://github.com/cupy/cupy/blob/v5/cupyx/scipy/sparse/compressed.py#L79-L83
where,
```
def isdense(x):
return isinstance(x, cupy.ndarray)
```
https://github.com/cupy/cupy/blob/v5/cupyx/scipy/sparse/sputils.py#L4-L5
## Environment to reproduce
```
CuPy Version : 5.0.0
CUDA Root : /usr/local/cuda
CUDA Build Version : 9020
CUDA Driver Version : 9020
CUDA Runtime Version : 9020
cuDNN Build Version : 7201
cuDNN Version : 7201
NCCL Build Version : 2213
```
# Suggestion
It should test input matrices first if they are cupy array or not, then check for sparse matrices or not.
It should give separate error messages for different reasons of failures.
Contributor guide
Assessment
This issue has not been assessed yet.