-
Notifications
You must be signed in to change notification settings - Fork 20
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 ReductionOp, ops.mean, ops.std, ops.var #482
Conversation
Could you register implementations in funsor/jax/ops.py the following test to test/test_terms.py: diff --git a/test/test_terms.py b/test/test_terms.py
index e495e3e..88ed47a 100644
--- a/test/test_terms.py
+++ b/test/test_terms.py
@@ -287,6 +287,29 @@ def test_unary(symbol, data):
check_funsor(actual, {}, Array[dtype, ()], expected_data)
+@pytest.mark.parametrize("event_shape", [(4,), (3, 2)], ids=str)
+@pytest.mark.parametrize(
+ "name",
+ [
+ "all",
+ "any",
+ "logsumexp",
+ "max",
+ "mean",
+ "min",
+ "prod",
+ "std",
+ "sum",
+ "var",
+ ],
+)
+def test_reduce_event(name, event_shape):
+ dtype = 2 if name in ("any", "all") else "real"
+ x = random_tensor(OrderedDict(i=Bint[5]), output=Array[dtype, event_shape])
+ actual = getattr(x, name)()
+ check_funsor(actual, x.inputs, Array[dtype, ()])
+
+
BINARY_OPS = [
"+",
"-", |
Is there a need to allow def reshape(self, shape):
return Unary(ops.ReshapeOp(shape), self) |
I'm not sure what the class Funsor(...):
...
def mean(self, axis=None, keepdims=False):
if axis is None and keepdims is False:
op = ops.mean # default version from this PR
else:
op = ops.MeanOp(axis, keepdims) # fancy version from a future PR
return Unary(op, self) Or if you refactored such that class Funsor(...):
...
def mean(self, axis=None, keepdims=False):
return Unary(ops.MeanOp(axis, keepdims), self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I'm still uncertain of argmin
, argmax
...
There were some rough edges and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
No description provided.