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

Add N-ary broadcasting operations. #98

Merged
merged 12 commits into from
Feb 18, 2018
6 changes: 0 additions & 6 deletions docs/generated/sparse.COO.elemwise.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/generated/sparse.COO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ COO
.. autosummary::
:toctree:

COO.elemwise
COO.astype
COO.round

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

.. currentmodule:: sparse

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

dot

elemwise

random

stack
Expand Down
32 changes: 9 additions & 23 deletions docs/operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ or numpy functions that are not yet implemented for sparse arrays

This page describes those valid operations, and their limitations.

:obj:`COO.elemwise`
:obj:`elemwise`
~~~~~~~~~~~~~~~~~~~
This function allows you to apply any arbitrary unary or binary function where
the first object is :obj:`COO`, and the second is a scalar, :obj:`COO`, or
a :doc:`Numpy arrays <reference/generated/numpy.ndarray>`. For example, the
a :obj:`scipy.sparse.spmatrix`. For example, the
following will add two :obj:`COO` objects:

.. code-block:: python

x.elemwise(np.add, y)
sparse.elemwise(np.add, x, y)


.. note:: Previously, :obj:`elemwise` was a method of the :obj:`COO` class. Now,
it has been moved to the :obj:`sparse` module.

.. _operations-auto-densification:

Expand Down Expand Up @@ -78,26 +82,8 @@ If densification is needed, it must be explicit. In other words, you must call
:obj:`COO.todense` on the :obj:`COO` object. If both operands are :obj:`COO`,
both must be densified.


Operations with :doc:`Numpy arrays <reference/generated/numpy.ndarray>`
-----------------------------------------------------------------------
Certain operations with :obj:`numpy.ndarray` are also supported. For example,
the following are all allowed if :code:`x` is a :obj:`numpy.ndarray` and
:code:`(x == 0).all()` evaluates to :code:`True`:

.. code-block:: python

x + y
x - y

The following is true so long as there are no infinities or NaNs in :code:`x`:

.. code-block:: python

x * y

In general, if operating on the :code:`numpy.ndarray` with a zero would produce
all-zeros then the operation is supported.
.. note:: Previously, operations with Numpy arrays were sometimes supported. Now,
it is necessary to convert Numpy arrays to :obj:`COO` objects.


Operations with :obj:`scipy.sparse.spmatrix`
Expand Down
2 changes: 1 addition & 1 deletion sparse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .coo import COO, tensordot, concatenate, stack, dot, triu, tril
from .coo import COO, elemwise, tensordot, concatenate, stack, dot, triu, tril
from .dok import DOK
from .sparse_array import SparseArray
from .utils import random
Expand Down
Loading