From 70015766f87dcf6df57cfb74e63e149ac9917b15 Mon Sep 17 00:00:00 2001 From: melabady1 <34304958+melabady1@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:35:01 +0200 Subject: [PATCH 1/2] add diff to numpy frontend --- .../sums_products_differences.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ivy/functional/frontends/numpy/mathematical_functions/sums_products_differences.py b/ivy/functional/frontends/numpy/mathematical_functions/sums_products_differences.py index e757e7b0cf3a0..dadd40bfd624a 100644 --- a/ivy/functional/frontends/numpy/mathematical_functions/sums_products_differences.py +++ b/ivy/functional/frontends/numpy/mathematical_functions/sums_products_differences.py @@ -116,3 +116,16 @@ def nancumprod(a, /, axis=None, dtype=None, out=None): def nancumsum(a, /, axis=None, dtype=None, out=None): a = ivy.where(ivy.isnan(a), ivy.zeros_like(a), a) return ivy.cumsum(a, axis=axis, dtype=dtype, out=out) + + +@to_ivy_arrays_and_back +def diff( + x, + /, + *, + n=1, + axis=-1, + prepend=None, + append=None +): + return ivy.diff(x, n=n, axis=axis, prepend=prepend, append=append) From e5da1c30816cbc61dc8d5911a79ac1fc1e6d4695 Mon Sep 17 00:00:00 2001 From: melabady1 <34304958+melabady1@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:37:56 +0200 Subject: [PATCH 2/2] add test_numpy_diff to frontend tests --- .../test_sums_products_differences.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_sums_products_differences.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_sums_products_differences.py index 15b057de121e5..d656b53f6030c 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_sums_products_differences.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_sums_products_differences.py @@ -327,3 +327,33 @@ def test_numpy_nansum( where=where, keepdims=keepdims, ) + + +# diff +@handle_frontend_test( + fn_tree="numpy.diff", + dtype_x_axis=helpers.dtype_values_axis( + available_dtypes=helpers.get_dtypes("valid"), + min_num_dims=1, + valid_axis=True, + force_int_axis=True, + ), +) +def test_numpy_diff( + dtype_x_axis, + frontend, + test_flags, + fn_tree, + on_device, +): + input_dtype, x, axis = dtype_x_axis + np_frontend_helpers.test_frontend_function( + input_dtypes=input_dtype, + frontend=frontend, + test_flags=test_flags, + fn_tree=fn_tree, + on_device=on_device, + x=x[0], + axis=axis, + ) +