From 35a0571fd0bc3dd062b0b0c9ade3c916a32bbd4a Mon Sep 17 00:00:00 2001 From: Sumayyah Chougle Date: Thu, 17 Aug 2023 16:57:31 +0530 Subject: [PATCH 1/2] implemented std paddle frontend --- .../frontends/paddle/tensor/stat.py | 14 +++++++++ .../test_paddle/test_tensor/test_stat.py | 30 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/ivy/functional/frontends/paddle/tensor/stat.py b/ivy/functional/frontends/paddle/tensor/stat.py index 48c94b2fb583c..1ac53658cc850 100644 --- a/ivy/functional/frontends/paddle/tensor/stat.py +++ b/ivy/functional/frontends/paddle/tensor/stat.py @@ -59,3 +59,17 @@ def nanmedian(x, axis=None, keepdim=True, name=None): else ivy.astype(x, ivy.float32) ) return ivy.median(x, axis=axis, keepdims=keepdim) + + +@with_supported_dtypes( + {"2.5.1 and below": ("bool", "float16", "float32", "float64", "int32", "int64")}, + "paddle", +) +@to_ivy_arrays_and_back +def std(x, axis=None, keepdim=False, name=None): + x = ( + ivy.astype(x, ivy.float64) + if ivy.dtype(x) == "float64" + else ivy.astype(x, ivy.float32) + ) + return ivy.std(x, axis=axis, keepdims=keepdim) diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_stat.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_stat.py index 411bf24362b67..5a64b34e79487 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_stat.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_stat.py @@ -162,3 +162,33 @@ def test_paddle_nanmedian( axis=axis, keepdim=keepdim, ) + + +# std +@handle_frontend_test( + fn_tree="paddle.std", + dtype_and_x=_statistical_dtype_values(function="std"), + keepdims=st.booleans(), +) +def test_paddle_std( + *, + dtype_and_x, + keepdims, + on_device, + fn_tree, + frontend, + test_flags, + backend_fw, +): + input_dtype, x, axis, correction = 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, + x=x[0], + axis=axis, + keepdim=keepdims, + ) From dc31dc90855ae70ca8e8b606914247d6b2b8d997 Mon Sep 17 00:00:00 2001 From: Sumayyah Chougle Date: Fri, 18 Aug 2023 10:54:31 +0530 Subject: [PATCH 2/2] Fixed std function --- ivy/functional/frontends/paddle/tensor/stat.py | 6 +++--- .../test_paddle/test_tensor/test_stat.py | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ivy/functional/frontends/paddle/tensor/stat.py b/ivy/functional/frontends/paddle/tensor/stat.py index 843670424221a..637935b943542 100644 --- a/ivy/functional/frontends/paddle/tensor/stat.py +++ b/ivy/functional/frontends/paddle/tensor/stat.py @@ -72,14 +72,14 @@ def nanmedian(x, axis=None, keepdim=True, name=None): @with_supported_dtypes( - {"2.5.1 and below": ("bool", "float16", "float32", "float64", "int32", "int64")}, + {"2.5.1 and below": ("float32", "float64", "uint16")}, "paddle", ) @to_ivy_arrays_and_back -def std(x, axis=None, keepdim=False, name=None): +def std(x, axis=None, unbiased=True, keepdim=False, name=None): x = ( ivy.astype(x, ivy.float64) if ivy.dtype(x) == "float64" else ivy.astype(x, ivy.float32) ) - return ivy.std(x, axis=axis, keepdims=keepdim) + return ivy.std(x, axis=axis, correction=int(unbiased), keepdims=keepdim) diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_stat.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_stat.py index ba73e07393b22..a82530bc610b9 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_stat.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_stat.py @@ -199,27 +199,28 @@ def test_paddle_nanmedian( @handle_frontend_test( fn_tree="paddle.std", dtype_and_x=_statistical_dtype_values(function="std"), - keepdims=st.booleans(), + unbiased=st.booleans(), + keepdim=st.booleans(), ) def test_paddle_std( *, + unbiased, dtype_and_x, - keepdims, - on_device, + keepdim, fn_tree, frontend, - test_flags, backend_fw, + test_flags, ): - input_dtype, x, axis, correction = dtype_and_x + input_dtype, x, axis, _ = 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, x=x[0], axis=axis, - keepdim=keepdims, + unbiased=unbiased, + keepdim=keepdim, )