Skip to content

Commit ef423c6

Browse files
hameerabbasimrocklin
authored andcommitted
Add N-ary broadcasting operations. (#98)
This PR adds N-ary broadcasting operations (in preparation for where) and simplifies code for the N-ary case.
1 parent 678de28 commit ef423c6

File tree

9 files changed

+611
-434
lines changed

9 files changed

+611
-434
lines changed

docs/generated/sparse.COO.elemwise.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/generated/sparse.COO.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ COO
3131
.. autosummary::
3232
:toctree:
3333

34-
COO.elemwise
3534
COO.astype
3635
COO.round
3736

docs/generated/sparse.elemwise.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
elemwise
2+
========
3+
4+
.. currentmodule:: sparse
5+
6+
.. autofunction:: elemwise

docs/generated/sparse.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ API
2727

2828
dot
2929

30+
elemwise
31+
3032
random
3133

3234
stack

docs/operations.rst

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ or numpy functions that are not yet implemented for sparse arrays
3333
3434
This page describes those valid operations, and their limitations.
3535

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

4343
.. code-block:: python
4444
45-
x.elemwise(np.add, y)
45+
sparse.elemwise(np.add, x, y)
46+
47+
48+
.. note:: Previously, :obj:`elemwise` was a method of the :obj:`COO` class. Now,
49+
it has been moved to the :obj:`sparse` module.
4650

4751
.. _operations-auto-densification:
4852

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

81-
82-
Operations with :doc:`Numpy arrays <reference/generated/numpy.ndarray>`
83-
-----------------------------------------------------------------------
84-
Certain operations with :obj:`numpy.ndarray` are also supported. For example,
85-
the following are all allowed if :code:`x` is a :obj:`numpy.ndarray` and
86-
:code:`(x == 0).all()` evaluates to :code:`True`:
87-
88-
.. code-block:: python
89-
90-
x + y
91-
x - y
92-
93-
The following is true so long as there are no infinities or NaNs in :code:`x`:
94-
95-
.. code-block:: python
96-
97-
x * y
98-
99-
In general, if operating on the :code:`numpy.ndarray` with a zero would produce
100-
all-zeros then the operation is supported.
85+
.. note:: Previously, operations with Numpy arrays were sometimes supported. Now,
86+
it is necessary to convert Numpy arrays to :obj:`COO` objects.
10187

10288

10389
Operations with :obj:`scipy.sparse.spmatrix`

sparse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .coo import COO, tensordot, concatenate, stack, dot, triu, tril
1+
from .coo import COO, elemwise, tensordot, concatenate, stack, dot, triu, tril
22
from .dok import DOK
33
from .sparse_array import SparseArray
44
from .utils import random

0 commit comments

Comments
 (0)