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

Refactor and clean format conversions. #152

Merged
merged 7 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions docs/construct.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ matrix:

.. code-block:: python

import sparse
>>> import sparse

coords = [[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4]]
data = [10, 20, 30, 40, 50]
s = sparse.COO(coords, data)
>>> coords = [[0, 1, 2, 3, 4],
... [0, 1, 2, 3, 4]]
>>> data = [10, 20, 30, 40, 50]
>>> s = sparse.COO(coords, data, shape=(5, 5))

>>> s.todense()
array([[10, 0, 0, 0, 0],
Expand All @@ -28,13 +28,25 @@ matrix:
[ 0, 0, 0, 40, 0],
[ 0, 0, 0, 0, 50]])


In general :code:`coords` should be a :code:`(ndim, nnz)` shaped
array. Each row of :code:`coords` contains one dimension of the
desired sparse array, and each column contains the index
corresponding to that nonzero element. :code:`data` contains
the nonzero elements of the array corresponding to the indices
in :code:`coords`. Its shape should be :code:`(nnz,)`
in :code:`coords`. Its shape should be :code:`(nnz,)`.

If ``data`` is the same across all the coordinates, it can be passed
in as a scalar. For example, the following produces the :math:`4 \times 4`
identity matrix:

.. code-block:: python

>>> import sparse

>>> coords = [[0, 1, 2, 3],
... [0, 1, 2, 3]]
>>> data = 1
>>> s = sparse.COO(coords, data, shape=(4, 4))

You can, and should, pass in :obj:`numpy.ndarray` objects for
:code:`coords` and :code:`data`.
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/sparse.COO.asformat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
COO.asformat
============

.. currentmodule:: sparse

.. automethod:: COO.asformat
6 changes: 6 additions & 0 deletions docs/generated/sparse.COO.from_iter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
COO.from\_iter
==============

.. currentmodule:: sparse

.. automethod:: COO.from_iter
2 changes: 2 additions & 0 deletions docs/generated/sparse.COO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ COO
.. autosummary::
:toctree:

COO.from_iter
COO.from_numpy
COO.from_scipy_sparse

Expand All @@ -48,6 +49,7 @@ COO
.. autosummary::
:toctree:

COO.asformat
COO.todense
COO.maybe_densify
COO.to_scipy_sparse
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/sparse.DOK.asformat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DOK.asformat
============

.. currentmodule:: sparse

.. automethod:: DOK.asformat
2 changes: 2 additions & 0 deletions docs/generated/sparse.DOK.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ DOK
.. rubric:: Methods
.. autosummary::
:toctree:

DOK.asformat

DOK.from_coo

Expand Down
6 changes: 6 additions & 0 deletions docs/generated/sparse.SparseArray.asformat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SparseArray.asformat
====================

.. currentmodule:: sparse

.. automethod:: SparseArray.asformat
6 changes: 6 additions & 0 deletions docs/generated/sparse.SparseArray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ SparseArray
SparseArray.nnz
SparseArray.size

.. rubric:: Methods
.. autosummary::
:toctree:

SparseArray.asformat

6 changes: 6 additions & 0 deletions docs/generated/sparse.as_coo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
as\_coo
=======

.. currentmodule:: sparse

.. autofunction:: as_coo
2 changes: 2 additions & 0 deletions docs/generated/sparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ API
.. autosummary::
:toctree:

as_coo

concatenate

dot
Expand Down
2 changes: 1 addition & 1 deletion sparse/coo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .core import COO
from .core import COO, as_coo
from .umath import elemwise
from .common import tensordot, dot, concatenate, stack, triu, tril, where, \
nansum, nanprod, nanmin, nanmax, nanreduce
Loading