From f0389c2f584abc564d7eca9ef9b5d806295f7161 Mon Sep 17 00:00:00 2001 From: Simranjeet Singh Date: Fri, 11 Aug 2023 16:56:07 +0530 Subject: [PATCH] Add softsign to tensorflow frontend api with test (#21352) --- ivy/functional/frontends/tensorflow/math.py | 8 +++++ .../test_tensorflow/test_math.py | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/ivy/functional/frontends/tensorflow/math.py b/ivy/functional/frontends/tensorflow/math.py index be820a7f1c76b..8fccb8cbfcc78 100644 --- a/ivy/functional/frontends/tensorflow/math.py +++ b/ivy/functional/frontends/tensorflow/math.py @@ -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) diff --git a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py index 6c4d26ff1201c..9f7f44cf4cf3f 100644 --- a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py +++ b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py @@ -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], + )