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 a sum method to _sparse_py_operators #745

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions aesara/sparse/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def __dot__(left, right):
def __rdot__(right, left):
return structured_dot(left, right)

def sum(self, axis=None, sparse_grad=False):
return sp_sum(self, axis=axis, sparse_grad=sparse_grad)

dot = __dot__

# N.B. THIS IS COMMENTED OUT ON PURPOSE!!!
Expand Down
9 changes: 7 additions & 2 deletions tests/sparse/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2039,12 +2039,17 @@ def setup_method(self):
self.op_class = sparse.SpSum
self.op = sparse.sp_sum

def test_op(self):
@pytest.mark.parametrize("op_type", ["func", "method"])
def test_op(self, op_type):
for format in sparse.sparse_formats:
for axis in self.possible_axis:
variable, data = sparse_random_inputs(format, shape=(10, 10))

z = sparse.sp_sum(variable[0], axis=axis)
if op_type == "func":
z = sparse.sp_sum(variable[0], axis=axis)
if op_type == "method":
z = variable[0].sum(axis=axis)

if axis is None:
assert z.type.broadcastable == ()
else:
Expand Down