From 717ac8c0c64fc601aef50b052fd5f022b3ba5661 Mon Sep 17 00:00:00 2001 From: Michalis Date: Wed, 9 Aug 2023 16:50:16 +0100 Subject: [PATCH 1/9] Add failing test for standard_t function --- .../test_numpy/test_random/test_functions.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py index 1814196e69973..657a14a092411 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py @@ -410,6 +410,34 @@ def test_numpy_standard_gamma( ) +@handle_frontend_test( + fn_tree="numpy.random.standard_t", + df_dtypes=helpers.get_dtypes("integer", full=False), + size_dtypes=helpers.get_dtypes("integer", full=False), + test_with_out=st.just(False), +) +def test_numpy_standard_t( + df, + df_dtypes, + size, + size_dtypes, + frontend, + test_flags, + fn_tree, + backend_fw, + on_device, +): + helpers.test_frontend_function( + input_dtypes=df_dtypes + size_dtypes, + backend_to_test=backend_fw, + test_flags=test_flags, + frontend=frontend, + fn_tree=fn_tree, + on_device=on_device, + test_values=False, + ) + + # binomial @handle_frontend_test( fn_tree="numpy.random.binomial", From 4528b4c5ef5947c6ea8c06dccdf53606f9ff3218 Mon Sep 17 00:00:00 2001 From: Michalis Date: Wed, 9 Aug 2023 17:18:23 +0100 Subject: [PATCH 2/9] Implement standard_t function --- ivy/functional/frontends/numpy/random/functions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ivy/functional/frontends/numpy/random/functions.py b/ivy/functional/frontends/numpy/random/functions.py index 16217f59e3ebb..7054addcf093f 100644 --- a/ivy/functional/frontends/numpy/random/functions.py +++ b/ivy/functional/frontends/numpy/random/functions.py @@ -97,6 +97,14 @@ def standard_gamma(shape, size=None): return ivy.gamma(shape, 1.0, shape=size, dtype="float64") +@to_ivy_arrays_and_back +@from_zero_dim_arrays_to_scalar +def standard_t(df, size=None): + numerator = ivy.random_normal(mean=0.0, std=1.0, shape=size, dtype="float64") + denominator = ivy.gamma(df / 2, 1.0, shape=size, dtype="float64") + return ivy.sqrt(df / 2) * ivy.divide(numerator, ivy.sqrt(denominator)) + + @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def binomial(n, p, size=None): From 9c6e53405904bf8ad459ee3dec0cbd3a2c1d1ee0 Mon Sep 17 00:00:00 2001 From: Michalis Date: Wed, 9 Aug 2023 17:18:48 +0100 Subject: [PATCH 3/9] Add test for standard_t function --- .../test_frontends/test_numpy/test_random/test_functions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py index 657a14a092411..717e028ad7f3b 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py @@ -412,7 +412,11 @@ def test_numpy_standard_gamma( @handle_frontend_test( fn_tree="numpy.random.standard_t", + df=st.floats(min_value=0, max_value=20, exclude_min=True), df_dtypes=helpers.get_dtypes("integer", full=False), + size=st.tuples( + st.integers(min_value=2, max_value=5), st.integers(min_value=2, max_value=5) + ), size_dtypes=helpers.get_dtypes("integer", full=False), test_with_out=st.just(False), ) @@ -435,6 +439,8 @@ def test_numpy_standard_t( fn_tree=fn_tree, on_device=on_device, test_values=False, + df=df, + size=size, ) From 4bd46e09c9f8a104b3df7b79620e6066ab1dfd71 Mon Sep 17 00:00:00 2001 From: Michalis Date: Tue, 22 Aug 2023 13:53:52 +0300 Subject: [PATCH 4/9] Change min value of `df` from 0 to 1 in test --- .../test_frontends/test_numpy/test_random/test_functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py index 717e028ad7f3b..8b3092f9dc336 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py @@ -1,5 +1,5 @@ # global, -from hypothesis import strategies as st, assume +from hypothesis import strategies as st, assume, reproduce_failure import numpy as np # local @@ -412,7 +412,7 @@ def test_numpy_standard_gamma( @handle_frontend_test( fn_tree="numpy.random.standard_t", - df=st.floats(min_value=0, max_value=20, exclude_min=True), + df=st.floats(min_value=1, max_value=20), df_dtypes=helpers.get_dtypes("integer", full=False), size=st.tuples( st.integers(min_value=2, max_value=5), st.integers(min_value=2, max_value=5) From 0b0989a3e4e8b5712d95814ed9e222636f7cb828 Mon Sep 17 00:00:00 2001 From: Michalis Date: Tue, 22 Aug 2023 14:32:20 +0300 Subject: [PATCH 5/9] Remove temporary import to reproduce failed test --- .../test_frontends/test_numpy/test_random/test_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py index 8b3092f9dc336..eafbf57a2e8b5 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py @@ -1,5 +1,5 @@ # global, -from hypothesis import strategies as st, assume, reproduce_failure +from hypothesis import strategies as st, assume import numpy as np # local From bc6942c0b3be5d4eb6de20c9129f023c09e83558 Mon Sep 17 00:00:00 2001 From: Michalis Date: Tue, 29 Aug 2023 10:02:07 +0100 Subject: [PATCH 6/9] Remove duplicate functions --- .../frontends/numpy/random/functions.py | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/ivy/functional/frontends/numpy/random/functions.py b/ivy/functional/frontends/numpy/random/functions.py index b874723a8bef1..24ab05c3dd3c0 100644 --- a/ivy/functional/frontends/numpy/random/functions.py +++ b/ivy/functional/frontends/numpy/random/functions.py @@ -125,12 +125,6 @@ def permutation(x, /): return ivy.shuffle(x) -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def beta(a, b, size=None): - return ivy.beta(a, b, shape=size) - - @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def shuffle(x, axis=0, /): @@ -190,14 +184,6 @@ def pareto(a, size=None): return ivy.pow(1 / (1 - u), 1 / a) -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def permutation(x, /): - if isinstance(x, int): - x = ivy.arange(x) - return ivy.shuffle(x) - - @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def poisson(lam=1.0, size=None): @@ -219,14 +205,6 @@ def rayleigh(scale, size=None): return x -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def shuffle(x, axis=0, /): - if isinstance(x, int): - x = ivy.arange(x) - return ivy.shuffle(x, axis) - - @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def standard_cauchy(size=None): @@ -234,18 +212,6 @@ def standard_cauchy(size=None): return ivy.tan(ivy.pi * (u - 0.5)) -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def standard_gamma(shape, size=None): - return ivy.gamma(shape, 1.0, shape=size, dtype="float64") - - -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def standard_normal(size=None): - return ivy.random_normal(mean=0.0, std=1.0, shape=size, dtype="float64") - - @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def triangular(left, mode, right, size=None): From ae58f520016105b307ab957b9c17a77b4812392c Mon Sep 17 00:00:00 2001 From: Michalis Date: Tue, 29 Aug 2023 10:12:42 +0100 Subject: [PATCH 7/9] Order functions alphabetically --- .../frontends/numpy/random/functions.py | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/ivy/functional/frontends/numpy/random/functions.py b/ivy/functional/frontends/numpy/random/functions.py index 24ab05c3dd3c0..e0c390d059f29 100644 --- a/ivy/functional/frontends/numpy/random/functions.py +++ b/ivy/functional/frontends/numpy/random/functions.py @@ -117,42 +117,6 @@ def multinomial(n, pvals, size=None): return ivy.multinomial(n, num_samples, batch_size=batch_size, probs=pvals) -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def permutation(x, /): - if isinstance(x, int): - x = ivy.arange(x) - return ivy.shuffle(x) - - -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def shuffle(x, axis=0, /): - if isinstance(x, int): - x = ivy.arange(x) - return ivy.shuffle(x, axis) - - -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def standard_normal(size=None): - return ivy.random_normal(mean=0.0, std=1.0, shape=size, dtype="float64") - - -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def standard_gamma(shape, size=None): - return ivy.gamma(shape, 1.0, shape=size, dtype="float64") - - -@to_ivy_arrays_and_back -@from_zero_dim_arrays_to_scalar -def standard_t(df, size=None): - numerator = ivy.random_normal(mean=0.0, std=1.0, shape=size, dtype="float64") - denominator = ivy.gamma(df / 2, 1.0, shape=size, dtype="float64") - return ivy.sqrt(df / 2) * ivy.divide(numerator, ivy.sqrt(denominator)) - - @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def negative_binomial(n, p, size=None): @@ -184,6 +148,14 @@ def pareto(a, size=None): return ivy.pow(1 / (1 - u), 1 / a) +@to_ivy_arrays_and_back +@from_zero_dim_arrays_to_scalar +def permutation(x, /): + if isinstance(x, int): + x = ivy.arange(x) + return ivy.shuffle(x) + + @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def poisson(lam=1.0, size=None): @@ -205,6 +177,14 @@ def rayleigh(scale, size=None): return x +@to_ivy_arrays_and_back +@from_zero_dim_arrays_to_scalar +def shuffle(x, axis=0, /): + if isinstance(x, int): + x = ivy.arange(x) + return ivy.shuffle(x, axis) + + @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def standard_cauchy(size=None): @@ -212,6 +192,26 @@ def standard_cauchy(size=None): return ivy.tan(ivy.pi * (u - 0.5)) +@to_ivy_arrays_and_back +@from_zero_dim_arrays_to_scalar +def standard_gamma(shape, size=None): + return ivy.gamma(shape, 1.0, shape=size, dtype="float64") + + +@to_ivy_arrays_and_back +@from_zero_dim_arrays_to_scalar +def standard_normal(size=None): + return ivy.random_normal(mean=0.0, std=1.0, shape=size, dtype="float64") + + +@to_ivy_arrays_and_back +@from_zero_dim_arrays_to_scalar +def standard_t(df, size=None): + numerator = ivy.random_normal(mean=0.0, std=1.0, shape=size, dtype="float64") + denominator = ivy.gamma(df / 2, 1.0, shape=size, dtype="float64") + return ivy.sqrt(df / 2) * ivy.divide(numerator, ivy.sqrt(denominator)) + + @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def triangular(left, mode, right, size=None): From 5b53f80a7ea58af55245a1b423e11776cc6ac1a2 Mon Sep 17 00:00:00 2001 From: Michalis Date: Thu, 31 Aug 2023 18:31:24 +0100 Subject: [PATCH 8/9] Comment "standard_t" before the test --- .../test_frontends/test_numpy/test_random/test_functions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py index c4d7f0511b495..d0c7138cf147c 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py @@ -508,6 +508,7 @@ def test_numpy_multinomial( ) +# standard_t @handle_frontend_test( fn_tree="numpy.random.standard_t", df=st.floats(min_value=1, max_value=20), From 1689679f98a58c1ddb507fbd35730cf7b917350f Mon Sep 17 00:00:00 2001 From: Michalis Date: Thu, 31 Aug 2023 18:37:03 +0100 Subject: [PATCH 9/9] Order tests alphabetically --- .../test_numpy/test_random/test_functions.py | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py index d0c7138cf147c..7054f4aa74961 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py @@ -508,41 +508,6 @@ def test_numpy_multinomial( ) -# standard_t -@handle_frontend_test( - fn_tree="numpy.random.standard_t", - df=st.floats(min_value=1, max_value=20), - df_dtypes=helpers.get_dtypes("integer", full=False), - size=st.tuples( - st.integers(min_value=2, max_value=5), st.integers(min_value=2, max_value=5) - ), - size_dtypes=helpers.get_dtypes("integer", full=False), - test_with_out=st.just(False), -) -def test_numpy_standard_t( - df, - df_dtypes, - size, - size_dtypes, - frontend, - test_flags, - fn_tree, - backend_fw, - on_device, -): - helpers.test_frontend_function( - input_dtypes=df_dtypes + size_dtypes, - backend_to_test=backend_fw, - test_flags=test_flags, - frontend=frontend, - fn_tree=fn_tree, - on_device=on_device, - test_values=False, - df=df, - size=size, - ) - - # negative_binomial @handle_frontend_test( fn_tree="numpy.random.negative_binomial", @@ -917,6 +882,41 @@ def test_numpy_standard_normal( ) +# standard_t +@handle_frontend_test( + fn_tree="numpy.random.standard_t", + df=st.floats(min_value=1, max_value=20), + df_dtypes=helpers.get_dtypes("integer", full=False), + size=st.tuples( + st.integers(min_value=2, max_value=5), st.integers(min_value=2, max_value=5) + ), + size_dtypes=helpers.get_dtypes("integer", full=False), + test_with_out=st.just(False), +) +def test_numpy_standard_t( + df, + df_dtypes, + size, + size_dtypes, + frontend, + test_flags, + fn_tree, + backend_fw, + on_device, +): + helpers.test_frontend_function( + input_dtypes=df_dtypes + size_dtypes, + backend_to_test=backend_fw, + test_flags=test_flags, + frontend=frontend, + fn_tree=fn_tree, + on_device=on_device, + test_values=False, + df=df, + size=size, + ) + + @handle_frontend_test( fn_tree="numpy.random.triangular", input_dtypes=helpers.get_dtypes("float"),