Skip to content

Commit

Permalink
Merge 5255cbc into daa053e
Browse files Browse the repository at this point in the history
  • Loading branch information
okuta committed Jun 17, 2018
2 parents daa053e + 5255cbc commit 22da64e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 21 deletions.
42 changes: 42 additions & 0 deletions cupyx/scipy/sparse/__init__.py
@@ -0,0 +1,42 @@
from cupy.sparse.base import issparse # NOQA
from cupy.sparse.base import isspmatrix # NOQA
from cupy.sparse.base import spmatrix # NOQA
from cupy.sparse.coo import coo_matrix # NOQA
from cupy.sparse.coo import isspmatrix_coo # NOQA
from cupy.sparse.csc import csc_matrix # NOQA
from cupy.sparse.csc import isspmatrix_csc # NOQA
from cupy.sparse.csr import csr_matrix # NOQA
from cupy.sparse.csr import isspmatrix_csr # NOQA
from cupy.sparse.dia import dia_matrix # NOQA
from cupy.sparse.dia import isspmatrix_dia # NOQA

from cupy.sparse.construct import eye # NOQA
from cupy.sparse.construct import identity # NOQA
from cupy.sparse.construct import rand # NOQA
from cupy.sparse.construct import random # NOQA
from cupy.sparse.construct import spdiags # NOQA

# TODO(unno): implement bsr_matrix
# TODO(unno): implement dok_matrix
# TODO(unno): implement lil_matrix

# TODO(unno): implement kron
# TODO(unno): implement kronsum
# TODO(unno): implement diags
# TODO(unno): implement block_diag
# TODO(unno): implement tril
# TODO(unno): implement triu
# TODO(unno): implement bmat
# TODO(unno): implement hstack
# TODO(unno): implement vstack

# TODO(unno): implement save_npz
# TODO(unno): implement load_npz

# TODO(unno): implement find

# TODO(unno): implement isspmatrix_bsr(x)
# TODO(unno): implement isspmatrix_lil(x)
# TODO(unno): implement isspmatrix_dok(x)

from cupyx.scipy.sparse import linalg # NOQA
5 changes: 5 additions & 0 deletions cupyx/scipy/sparse/linalg/__init__.py
@@ -0,0 +1,5 @@
# Functions from the following SciPy document
# https://docs.scipy.org/doc/scipy/reference/sparse.linalg.html

# "NOQA" to suppress flake8 warning
from cupy.sparse.linalg.solve import lsqr # NOQA
42 changes: 21 additions & 21 deletions docs/source/reference/sparse.rst
Expand Up @@ -5,16 +5,16 @@ Sparse matrices
CuPy supports sparse matrices using `cuSPARSE <https://developer.nvidia.com/cusparse>`_.
These matrices have the same interfaces of `SciPy's sparse matrices <https://docs.scipy.org/doc/scipy/reference/sparse.html>`_.

.. module:: cupy.sparse
.. module:: cupyx.scipy.sparse

Conversion to/from SciPy sparse matrices
----------------------------------------

``cupy.sparse.*_matrix`` and ``scipy.sparse.*_matrix`` are not implicitly convertible to each other.
That means, SciPy functions cannot take ``cupy.sparse.*_matrix`` objects as inputs, and vice versa.
``cupyx.scipy.sparse.*_matrix`` and ``cupyx.scipy.sparse.*_matrix`` are not implicitly convertible to each other.
That means, SciPy functions cannot take ``cupyx.scipy.sparse.*_matrix`` objects as inputs, and vice versa.

- To convert SciPy sparse matrices to CuPy, pass it to the constructor of each CuPy sparse matrix class.
- To convert CuPy sparse matrices to SciPy, use :func:`get <cupy.sparse.spmatrix.get>` method of each CuPy sparse matrix class.
- To convert CuPy sparse matrices to SciPy, use :func:`get <cupyx.scipy.sparse.spmatrix.get>` method of each CuPy sparse matrix class.

Note that converting between CuPy and SciPy incurs data transfer between
the host (CPU) device and the GPU device, which is costly in terms of performance.
Expand All @@ -26,11 +26,11 @@ Sparse matrix classes
:toctree: generated/
:nosignatures:

cupy.sparse.coo_matrix
cupy.sparse.csr_matrix
cupy.sparse.csc_matrix
cupy.sparse.dia_matrix
cupy.sparse.spmatrix
cupyx.scipy.sparse.coo_matrix
cupyx.scipy.sparse.csr_matrix
cupyx.scipy.sparse.csc_matrix
cupyx.scipy.sparse.dia_matrix
cupyx.scipy.sparse.spmatrix


Functions
Expand All @@ -43,11 +43,11 @@ Building sparse matrices
:toctree: generated/
:nosignatures:

cupy.sparse.eye
cupy.sparse.identity
cupy.sparse.spdiags
cupy.sparse.rand
cupy.sparse.random
cupyx.scipy.sparse.eye
cupyx.scipy.sparse.identity
cupyx.scipy.sparse.spdiags
cupyx.scipy.sparse.rand
cupyx.scipy.sparse.random


Identifying sparse matrices
Expand All @@ -57,12 +57,12 @@ Identifying sparse matrices
:toctree: generated/
:nosignatures:

cupy.sparse.issparse
cupy.sparse.isspmatrix
cupy.sparse.isspmatrix_csc
cupy.sparse.isspmatrix_csr
cupy.sparse.isspmatrix_coo
cupy.sparse.isspmatrix_dia
cupyx.scipy.sparse.issparse
cupyx.scipy.sparse.isspmatrix
cupyx.scipy.sparse.isspmatrix_csc
cupyx.scipy.sparse.isspmatrix_csr
cupyx.scipy.sparse.isspmatrix_coo
cupyx.scipy.sparse.isspmatrix_dia


Linear Algebra
Expand All @@ -72,4 +72,4 @@ Linear Algebra
:toctree: generated/
:nosignatures:

cupy.sparse.linalg.lsqr
cupyx.scipy.sparse.linalg.lsqr
2 changes: 2 additions & 0 deletions setup.py
Expand Up @@ -104,6 +104,8 @@
'cupyx',
'cupyx.scipy',
'cupyx.scipy.ndimage',
'cupyx.scipy.sparse',
'cupyx.scipy.sparse.linalg',
'cupyx.scipy.special',
],
package_data=package_data,
Expand Down

0 comments on commit 22da64e

Please sign in to comment.