Skip to content

Commit a609e40

Browse files
authored
fix: simplify stanh implementation in paddle frontend and avoid nan values from exp in the test(#28493)
1 parent 14a6c2f commit a609e40

File tree

2 files changed

+16
-9
lines changed
  • ivy/functional/frontends/paddle
  • ivy_tests/test_ivy/test_frontends/test_paddle

2 files changed

+16
-9
lines changed

ivy/functional/frontends/paddle/math.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,8 @@ def square(x, name=None):
629629
@with_supported_dtypes({"2.6.0 and below": ("float32", "float64")}, "paddle")
630630
@to_ivy_arrays_and_back
631631
def stanh(x, scale_a=0.67, scale_b=1.7159, name=None):
632-
# TODO this function will be simplified as soon as the ivy.stanh(x,a,b) is added
633-
exp_ax = ivy.exp(ivy.multiply(scale_a, x))
634-
exp_minus_ax = ivy.exp(ivy.multiply(-scale_a, x))
635-
numerator = ivy.subtract(exp_ax, exp_minus_ax)
636-
denominator = ivy.add(exp_ax, exp_minus_ax)
637-
ret = ivy.multiply(scale_b, ivy.divide(numerator, denominator))
638-
return ret
632+
ret = ivy.stanh(x, alpha=scale_b, beta=scale_a, out=name)
633+
return ivy.asarray(ret, dtype=x.dtype)
639634

640635

641636
@with_unsupported_dtypes({"2.6.0 and below": ("float16", "bfloat16")}, "paddle")

ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,8 +2495,20 @@ def test_paddle_square(
24952495
dtype_and_x=helpers.dtype_and_values(
24962496
available_dtypes=helpers.get_dtypes("float"),
24972497
),
2498-
scale_a=st.floats(1e-5, 1e5),
2499-
scale_b=st.floats(1e-5, 1e5),
2498+
scale_a=st.floats(
2499+
min_value=-5,
2500+
max_value=5,
2501+
allow_nan=False,
2502+
allow_subnormal=False,
2503+
allow_infinity=False,
2504+
),
2505+
scale_b=st.floats(
2506+
min_value=-5,
2507+
max_value=5,
2508+
allow_nan=False,
2509+
allow_subnormal=False,
2510+
allow_infinity=False,
2511+
),
25002512
)
25012513
def test_paddle_stanh(
25022514
*,

0 commit comments

Comments
 (0)