Skip to content

Commit

Permalink
Merge 1e8d01e into 6abcc0d
Browse files Browse the repository at this point in the history
  • Loading branch information
patel-zeel committed Jun 25, 2021
2 parents 6abcc0d + 1e8d01e commit 489953f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -325,6 +325,7 @@ leaky_relu(a, alpha)
min(a, axis=None, squeeze=True)
max(a, axis=None, squeeze=True)
sum(a, axis=None, squeeze=True)
prod(a, axis=None, squeeze=True)
mean(a, axis=None, squeeze=True)
std(a, axis=None, squeeze=True)
logsumexp(a, axis=None, squeeze=True)
Expand Down
5 changes: 5 additions & 0 deletions lab/autograd/generic.py
Expand Up @@ -192,6 +192,11 @@ def sum(a: Numeric, axis=None, squeeze=True):
return anp.sum(a, axis=axis, keepdims=not squeeze)


@dispatch
def prod(a: Numeric, axis=None, squeeze=True):
return anp.prod(a, axis=axis, keepdims=not squeeze)


@dispatch
def mean(a: Numeric, axis=None, squeeze=True):
return anp.mean(a, axis=axis, keepdims=not squeeze)
Expand Down
17 changes: 17 additions & 0 deletions lab/generic.py
Expand Up @@ -74,6 +74,7 @@
"max",
"argmax",
"sum",
"prod",
"nansum",
"mean",
"nanmean",
Expand Down Expand Up @@ -971,6 +972,22 @@ def sum(a: Numeric, axis=None, squeeze=True): # pragma: no cover
"""


@dispatch
@abstract()
def prod(a: Numeric, axis=None, squeeze=True): # pragma: no cover
"""Product of all elements in a tensor, possibly along an axis.
Args:
a (tensor): Tensor.
axis (int, optional): Optional axis.
squeeze (bool, optional): Squeeze the dimension after the reduction. Defaults
to `True`.
Returns:
tensor: Reduced tensor.
"""


@dispatch
def nansum(x, **kw_args):
"""Like :func:`sum`, but ignores `NaN`s."""
Expand Down
5 changes: 5 additions & 0 deletions lab/jax/generic.py
Expand Up @@ -237,6 +237,11 @@ def sum(a: Numeric, axis=None, squeeze=True):
return jnp.sum(a, axis=axis, keepdims=not squeeze)


@dispatch
def prod(a: Numeric, axis=None, squeeze=True):
return jnp.prod(a, axis=axis, keepdims=not squeeze)


@dispatch
def mean(a: Numeric, axis=None, squeeze=True):
return jnp.mean(a, axis=axis, keepdims=not squeeze)
Expand Down
5 changes: 5 additions & 0 deletions lab/numpy/generic.py
Expand Up @@ -216,6 +216,11 @@ def sum(a: Numeric, axis=None, squeeze=True):
return np.sum(a, axis=axis, keepdims=not squeeze)


@dispatch
def prod(a: Numeric, axis=None, squeeze=True):
return np.prod(a, axis=axis, keepdims=not squeeze)


@dispatch
def mean(a: Numeric, axis=None, squeeze=True):
return np.mean(a, axis=axis, keepdims=not squeeze)
Expand Down
5 changes: 5 additions & 0 deletions lab/tensorflow/generic.py
Expand Up @@ -231,6 +231,11 @@ def sum(a: Numeric, axis=None, squeeze=True):
return tf.reduce_sum(a, axis=axis, keepdims=not squeeze)


@dispatch
def prod(a: Numeric, axis=None, squeeze=True):
return tf.reduce_prod(a, axis=axis, keepdims=not squeeze)


@dispatch
def mean(a: Numeric, axis=None, squeeze=True):
return tf.reduce_mean(a, axis=axis, keepdims=not squeeze)
Expand Down
8 changes: 8 additions & 0 deletions lab/torch/generic.py
Expand Up @@ -238,6 +238,14 @@ def sum(a: Numeric, axis=None, squeeze=True):
return torch.sum(a, dim=axis, keepdim=not squeeze)


@dispatch
def prod(a: Numeric, axis=None, squeeze=True):
if axis is None:
return torch.prod(a)
else:
return torch.prod(a, dim=axis, keepdim=not squeeze)


@dispatch
def mean(a: Numeric, axis=None, squeeze=True):
if axis is None:
Expand Down
1 change: 1 addition & 0 deletions tests/test_generic.py
Expand Up @@ -356,6 +356,7 @@ def test_binary_positive_first(f, check_lazy_shapes):
(B.min, True),
(B.max, True),
(B.sum, True),
(B.prod, True),
(B.nansum, True),
(B.mean, True),
(B.nanmean, True),
Expand Down

0 comments on commit 489953f

Please sign in to comment.