Skip to content

Commit

Permalink
Add softsign to tensorflow frontend api with test (ivy-llc#21352)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjsingh101 authored Aug 11, 2023
1 parent da62ac2 commit f0389c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ivy/functional/frontends/tensorflow/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,11 @@ def l2_normalize(x, axis=None, epsilon=1e-12, name=None):
square_sum = ivy.sum(ivy.square(x), axis=axis, keepdims=True)
x_inv_norm = ivy.reciprocal(ivy.sqrt(ivy.maximum(square_sum, epsilon)))
return ivy.multiply(x, x_inv_norm)


@with_supported_dtypes(
{"2.13.0 and below": ("bfloat32", "float32", "float64")}, "tensorflow"
)
@to_ivy_arrays_and_back
def softsign(features, name=None):
return ivy.divide(features, ivy.abs(features) + 1)
29 changes: 29 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -3171,3 +3171,32 @@ def test_tensorflow_cumprod( # NOQA
exclusive=exclusive,
reverse=reverse,
)


# softsign
@handle_frontend_test(
fn_tree="tensorflow.math.softsign",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
),
test_with_out=st.just(False),
)
def test_tensorflow_softsign(
*,
dtype_and_x,
on_device,
fn_tree,
frontend,
test_flags,
backend_fw,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
backend_to_test=backend_fw,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
features=x[0],
)

0 comments on commit f0389c2

Please sign in to comment.