-
Notifications
You must be signed in to change notification settings - Fork 132
Implemented Repeat and Unique Ops in PyTorch #890
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
Changes from all commits
9a14dba
dfdc114
330a7d2
8dbe5ca
62e453d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,61 @@ def test_pytorch_CumOp(axis, dtype): | |
out = pt.cumprod(a, axis=axis) | ||
fgraph = FunctionGraph([a], [out]) | ||
compare_pytorch_and_py(fgraph, [test_value]) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"axis, repeats", | ||
[ | ||
(0, (1, 2, 3)), | ||
(1, (3, 3)), | ||
pytest.param( | ||
None, | ||
3, | ||
marks=pytest.mark.xfail(reason="Reshape not implemented"), | ||
), | ||
], | ||
) | ||
def test_pytorch_Repeat(axis, repeats): | ||
a = pt.matrix("a", dtype="float64") | ||
|
||
test_value = np.arange(6, dtype="float64").reshape((3, 2)) | ||
|
||
out = pt.repeat(a, repeats, axis=axis) | ||
fgraph = FunctionGraph([a], [out]) | ||
compare_pytorch_and_py(fgraph, [test_value]) | ||
|
||
|
||
@pytest.mark.parametrize("axis", [None, 0, 1]) | ||
def test_pytorch_Unique_axis(axis): | ||
a = pt.matrix("a", dtype="float64") | ||
|
||
test_value = np.array( | ||
[[1.0, 1.0, 2.0], [1.0, 1.0, 2.0], [3.0, 3.0, 0.0]], dtype="float64" | ||
) | ||
|
||
out = pt.unique(a, axis=axis) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does PyTensor only allows integer axis at the moment? No There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All good with this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't check the code, but we need to see if multiple (but not all) axis is supported by PyTensor and if so test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean multiple axis like in the case of
|
||
fgraph = FunctionGraph([a], [out]) | ||
compare_pytorch_and_py(fgraph, [test_value]) | ||
|
||
|
||
@pytest.mark.parametrize("return_inverse", [False, True]) | ||
@pytest.mark.parametrize("return_counts", [False, True]) | ||
@pytest.mark.parametrize( | ||
"return_index", | ||
(False, pytest.param(True, marks=pytest.mark.xfail(raises=NotImplementedError))), | ||
) | ||
def test_pytorch_Unique_params(return_index, return_inverse, return_counts): | ||
a = pt.matrix("a", dtype="float64") | ||
test_value = np.array( | ||
[[1.0, 1.0, 2.0], [1.0, 1.0, 2.0], [3.0, 3.0, 0.0]], dtype="float64" | ||
) | ||
|
||
out = pt.unique( | ||
a, | ||
return_index=return_index, | ||
return_inverse=return_inverse, | ||
return_counts=return_counts, | ||
axis=0, | ||
) | ||
fgraph = FunctionGraph([a], [out[0] if isinstance(out, list) else out]) | ||
compare_pytorch_and_py(fgraph, [test_value]) |
Uh oh!
There was an error while loading. Please reload this page.