Skip to content

Commit

Permalink
Add any() to torch tensor frontend (ivy-llc#9439)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaketae and simonetgordon authored Jan 8, 2023
1 parent a59792f commit 0417306
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def add(self, other, *, alpha=1):
def chunk(self, chunks, dim=0):
return torch_frontend.chunk(self._ivy_array, chunks, dim=dim)

def any(self, dim=None, keepdim=False, *, out=None):
return torch_frontend.any(self._ivy_array, dim=dim, keepdim=keepdim, out=out)

@with_unsupported_dtypes({"1.11.0 and below": ("bfloat16",)}, "torch")
def add_(self, other, *, alpha=1):
self._ivy_array = self.add(other, alpha=alpha).ivy_array
Expand Down
47 changes: 47 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,53 @@ def test_torch_instance_chunk(
)


# any
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="torch.tensor",
method_name="any",
dtype_input_axis=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("numeric"),
min_num_dims=1,
min_value=-1e04,
max_value=1e04,
valid_axis=True,
force_int_axis=True,
),
keepdim=st.booleans(),
)
def test_torch_instance_any(
dtype_input_axis,
init_num_positional_args: pf.NumPositionalArgFn,
method_num_positional_args: pf.NumPositionalArgMethod,
as_variable: pf.AsVariableFlags,
native_array: pf.NativeArrayFlags,
keepdim,
frontend_method_data,
frontend,
):
input_dtype, x, axis = dtype_input_axis
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
init_as_variable_flags=as_variable,
init_num_positional_args=init_num_positional_args,
init_native_array_flags=native_array,
init_all_as_kwargs_np={
"data": x[0],
},
method_input_dtypes=input_dtype,
method_as_variable_flags=as_variable,
method_num_positional_args=method_num_positional_args,
method_native_array_flags=native_array,
method_all_as_kwargs_np={
"dim": axis,
"keepdim": keepdim,
},
frontend_method_data=frontend_method_data,
frontend=frontend,
)


# add
@handle_frontend_method(
class_tree=CLASS_TREE,
Expand Down

0 comments on commit 0417306

Please sign in to comment.