Skip to content

Commit

Permalink
max for torch frontend.
Browse files Browse the repository at this point in the history
Close #6285
  • Loading branch information
Ishticode committed Oct 29, 2022
1 parent 4aac4a9 commit 8bcfe6b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ivy/functional/frontends/torch/reduction_ops.py
Expand Up @@ -87,6 +87,22 @@ def min(input, dim=None, keepdim=False, *, out=None):
)


@to_ivy_arrays_and_back
def max(input, dim=None, keepdim=False, *, out=None):
if dim is None:
return ivy.max(input, axis=dim, keepdims=keepdim, out=out)
elif out is not None:
ivy.max(input, axis=dim, keepdims=keepdim, out=out[0])
ivy.argmax(input, axis=dim, keepdims=keepdim, out=out[1])
return out
else:
max_tuple = namedtuple("max", ["values", "indices"])
return max_tuple(
ivy.max(input, axis=dim, keepdims=keepdim),
ivy.argmax(input, axis=dim, keepdims=keepdim),
)


@to_ivy_arrays_and_back
def moveaxis(input, source, destination):
return ivy.moveaxis(input, source, destination)
37 changes: 37 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_reduction_ops.py
Expand Up @@ -551,3 +551,40 @@ def test_torch_moveaxis(
source=source,
destination=destination,
)


@handle_cmd_line_args
@given(
dtype_input_axis=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("numeric"),
min_num_dims=1,
valid_axis=True,
force_int_axis=True,
),
num_positional_args=helpers.num_positional_args(
fn_name="ivy.functional.frontends.torch.max"
),
keepdim=st.booleans(),
)
def test_torch_max(
dtype_input_axis,
as_variable,
num_positional_args,
native_array,
keepdim,
with_out,
):
input_dtype, x, axis = dtype_input_axis
helpers.test_frontend_function(
input_dtypes=input_dtype,
as_variable_flags=as_variable,
with_out=with_out,
num_positional_args=num_positional_args,
native_array_flags=native_array,
frontend="torch",
fn_tree="max",
input=x[0],
dim=axis,
keepdim=keepdim,
out=None,
)

0 comments on commit 8bcfe6b

Please sign in to comment.