Skip to content

Commit

Permalink
add torch frontend tanh and tanh_ instance methods (#6757)
Browse files Browse the repository at this point in the history
Co-authored-by: ahmedo42 <[email protected]>
  • Loading branch information
mcemilg and ahmedo42 authored Nov 9, 2022
1 parent 28479cf commit e723cd9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def asinh_(self):

def tan(self, *, out=None):
return torch_frontend.tan(self.data, out=out)

def tanh(self, *, out=None):
return torch_frontend.tanh(self.data, out=out)

def tanh_(self):
self.data = self.tanh()
return self.data

def log(self):
return ivy.log(self.data)
Expand Down
66 changes: 66 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 @@ -663,6 +663,72 @@ def test_torch_instance_tan(
)


# tanh
@handle_cmd_line_args
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
allow_inf=False,
),
)
def test_torch_instance_tanh(
dtype_and_x,
as_variable,
native_array,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_method(
input_dtypes_init=["float64"] + input_dtype,
as_variable_flags_init=as_variable,
num_positional_args_init=1,
native_array_flags_init=native_array,
all_as_kwargs_np_init={
"data": x[0],
},
input_dtypes_method=["float64"] + input_dtype,
as_variable_flags_method=as_variable,
num_positional_args_method=0,
native_array_flags_method=native_array,
all_as_kwargs_np_method={},
frontend="torch",
class_name="tensor",
method_name="tanh",
)


# tanh_
@handle_cmd_line_args
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
allow_inf=False,
),
)
def test_torch_instance_tanh_(
dtype_and_x,
as_variable,
native_array,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_method(
input_dtypes_init=["float64"] + input_dtype,
as_variable_flags_init=as_variable,
num_positional_args_init=1,
native_array_flags_init=native_array,
all_as_kwargs_np_init={
"data": x[0],
},
input_dtypes_method=["float64"] + input_dtype,
as_variable_flags_method=as_variable,
num_positional_args_method=0,
native_array_flags_method=native_array,
all_as_kwargs_np_method={},
frontend="torch",
class_name="tensor",
method_name="tanh_",
)


# asin
@handle_cmd_line_args
@given(
Expand Down

0 comments on commit e723cd9

Please sign in to comment.