-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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 torch.meshgrid to torch frontend #11560
Changes from all commits
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 |
---|---|---|
|
@@ -137,6 +137,51 @@ def test_torch_roll( | |
) | ||
|
||
|
||
# meshgrid | ||
@handle_frontend_test( | ||
fn_tree="torch.meshgrid", | ||
dtypes_and_tensors=helpers.dtype_and_values( | ||
available_dtypes=helpers.get_dtypes("float").filter( | ||
lambda x: "bfloat16" not in x[0] | ||
), | ||
num_arrays=st.integers(min_value=1, max_value=5), | ||
min_num_dims=1, | ||
max_num_dims=1, | ||
min_dim_size=2, | ||
max_dim_size=5, | ||
shared_dtype=True, | ||
), | ||
indexing=st.sampled_from(['ij', 'xy']), | ||
) | ||
def test_torch_meshgrid( | ||
*, | ||
dtypes_and_tensors, | ||
indexing, | ||
on_device, | ||
fn_tree, | ||
frontend, | ||
test_flags, | ||
): | ||
dtypes, tensors = dtypes_and_tensors | ||
if isinstance(dtypes, list): | ||
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. the if else statement here is actually not needed as the output is always a list, also no need to cast the output to a numpy array, it is already one, no need to cast the type either, just keep it as |
||
kwargs = { | ||
f"tensor{i}": np.array(tensor, dtype=dtypes[i]) | ||
for i, tensor in enumerate(tensors) | ||
} | ||
else: | ||
args = {"tensor": np.array(tensors, dtype=dtypes)} | ||
kwargs['indexing'] = indexing | ||
test_flags.num_positional_args = len(tensors) + 1 | ||
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. there is no need for the |
||
helpers.test_frontend_function( | ||
input_dtypes=dtypes, | ||
frontend=frontend, | ||
test_flags=test_flags, | ||
fn_tree=fn_tree, | ||
on_device=on_device, | ||
**kwargs, | ||
) | ||
|
||
|
||
# fliplr | ||
@handle_frontend_test( | ||
fn_tree="torch.fliplr", | ||
|
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.
torch's meshgrid returns a tuple so cast the output to a tuple instead of a list, (this also fixes the type issues and output length issues)