From c4be140e0df5925cdfd244570a3e93d65d8c2ed8 Mon Sep 17 00:00:00 2001 From: Sanjay Suthar Date: Wed, 9 Aug 2023 16:14:52 +0530 Subject: [PATCH 01/14] first commit --- duplicate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/duplicate.py b/duplicate.py index e7ac5767d8b2c..46483abad6242 100644 --- a/duplicate.py +++ b/duplicate.py @@ -3,6 +3,7 @@ import glob + def get_all_functions_from_directory(root_dir, startswith="test"): if not os.path.exists(root_dir): print("Invalid directory") From b6bce7181518b7e96fb2df885c7dc57d26b2a611 Mon Sep 17 00:00:00 2001 From: Sanjay Suthar Date: Tue, 3 Oct 2023 03:42:44 +0530 Subject: [PATCH 02/14] Added the simplelinearalgebra function for histogram --- .../test_numpy/test_fft/test_discrete_fourier_transform.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py index e245aacee0487..fb6f723dc9682 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py @@ -16,7 +16,7 @@ fn_tree="numpy.fft.ifft", dtype_and_x=x_and_ifft(), ) -def test_numpy_iftt(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): +def test_numpy_ifft(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): input_dtype, x, dim, norm, n = dtype_and_x helpers.test_frontend_function( input_dtypes=input_dtype, @@ -39,7 +39,7 @@ def test_numpy_iftt(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_d available_dtypes=helpers.get_dtypes("float"), shape=(4,), array_api_dtypes=True ), ) -def test_numpy_ifttshift( +def test_numpy_ifftshift( dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device ): input_dtype, arr = dtype_and_x @@ -92,7 +92,7 @@ def test_numpy_fft( available_dtypes=helpers.get_dtypes("float"), shape=(4,), array_api_dtypes=True ), ) -def test_numpy_fttshift( +def fttshift( dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device ): input_dtype, arr = dtype_and_x From df8715eb39d7cddb0c66fc69827e81ae2a081656 Mon Sep 17 00:00:00 2001 From: Sanjay Suthar Date: Tue, 3 Oct 2023 03:47:43 +0530 Subject: [PATCH 03/14] added the linear algebra fun for histogram --- determine_tests.py | 4 +++- .../frontends/paddle/tensor/linalg.py | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/determine_tests.py b/determine_tests.py index ad79fd8526060..e712463123970 100644 --- a/determine_tests.py +++ b/determine_tests.py @@ -4,13 +4,15 @@ from pydriller import Repository import os # noqa import bz2 -import _pickle as cPickle +import pickle as cPickle import sys from run_tests_CLI.get_all_tests import get_all_tests MAX_TESTS = 10 + + def get_tests(_tests_file, _line): tests_file_line = set() if 0 <= _line < len(_tests_file): diff --git a/ivy/functional/frontends/paddle/tensor/linalg.py b/ivy/functional/frontends/paddle/tensor/linalg.py index a9bcbfa29ec55..7a9c70472a7e7 100644 --- a/ivy/functional/frontends/paddle/tensor/linalg.py +++ b/ivy/functional/frontends/paddle/tensor/linalg.py @@ -6,7 +6,6 @@ to_ivy_arrays_and_back, ) - @with_supported_dtypes( {"2.5.0 and below": ("float32", "float64", "int32", "int64")}, "paddle" ) @@ -183,3 +182,19 @@ def bincount(x, weights=None, minlength=0, name=None): def dist(x, y, p=2): ret = ivy.vector_norm(ivy.subtract(x, y), ord=p) return ivy.reshape(ret, (1,)) + +@with_supported_dtypes({"2.4.1 and above": ("int64",)}, "paddle") +@to_ivy_arrays_and_back +def linear_algebra_histogram(d, num_bins): + min_value = ivy.min(d) + max_value = ivy.max(d) + bin_width = (max_value - min_value) / num_bins + bin_edges = ivy.arange(min_value, max_value + bin_width, bin_width) + + # Count the number of values in each bin. + bin_counts = ivy.zeros(num_bins) + for value in d: + bin_index = ivy.searchsorted(bin_edges, value) + bin_counts[bin_index] += 1 + return ivy.bin_counts + \ No newline at end of file From e65c7cf9bd541a16cc5abd6bebcedec62ddd1ca0 Mon Sep 17 00:00:00 2001 From: Sanjay Suthar Date: Wed, 4 Oct 2023 11:01:25 +0530 Subject: [PATCH 04/14] created function fot slicing,joining manipulations --- .../array/experimental/manipulation.py | 26 +++++++++++++++ .../container/experimental/manipulation.py | 26 +++++++++++++++ .../backends/jax/experimental/manipulation.py | 25 +++++++++++++++ .../numpy/experimental/manipulation.py | 26 +++++++++++++++ .../tensorflow/experimental/manipulation.py | 25 +++++++++++++++ .../torch/experimental/manipulation.py | 25 +++++++++++++++ .../indexing_slicing_joining_mutating_ops.py | 32 +++++++++++++++++++ .../ivy/experimental/manipulation.py | 25 +++++++++++++++ ...t_indexing_slicing_joining_mutating_ops.py | 25 +++++++++++++++ 9 files changed, 235 insertions(+) diff --git a/ivy/data_classes/array/experimental/manipulation.py b/ivy/data_classes/array/experimental/manipulation.py index bc6d61c2c67cc..75a8b0b566c0f 100644 --- a/ivy/data_classes/array/experimental/manipulation.py +++ b/ivy/data_classes/array/experimental/manipulation.py @@ -1080,3 +1080,29 @@ def fill_diagonal( ivy.fill_diag also applies to this method with minimal changes. """ return ivy.fill_diagonal(self._data, v, wrap=wrap) + + +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError diff --git a/ivy/data_classes/container/experimental/manipulation.py b/ivy/data_classes/container/experimental/manipulation.py index 7832070e3f2e3..5e5a8964a7dff 100644 --- a/ivy/data_classes/container/experimental/manipulation.py +++ b/ivy/data_classes/container/experimental/manipulation.py @@ -2996,3 +2996,29 @@ def fill_diagonal( v, wrap=wrap, ) + +@staticmethod +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError \ No newline at end of file diff --git a/ivy/functional/backends/jax/experimental/manipulation.py b/ivy/functional/backends/jax/experimental/manipulation.py index 323f0736930fa..193c725ede37d 100644 --- a/ivy/functional/backends/jax/experimental/manipulation.py +++ b/ivy/functional/backends/jax/experimental/manipulation.py @@ -416,3 +416,28 @@ def fill_diagonal( a = a.at[:end:step].set(jnp.array(v).astype(a.dtype)) a = jnp.reshape(a, shape) return a + +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError \ No newline at end of file diff --git a/ivy/functional/backends/numpy/experimental/manipulation.py b/ivy/functional/backends/numpy/experimental/manipulation.py index 3cbd7a3d471d6..cc55021f1fc65 100644 --- a/ivy/functional/backends/numpy/experimental/manipulation.py +++ b/ivy/functional/backends/numpy/experimental/manipulation.py @@ -505,3 +505,29 @@ def fill_diagonal( ) -> np.ndarray: np.fill_diagonal(a, v, wrap=wrap) return a + + +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError \ No newline at end of file diff --git a/ivy/functional/backends/tensorflow/experimental/manipulation.py b/ivy/functional/backends/tensorflow/experimental/manipulation.py index ec8b4bd367ee3..84f049e7527ba 100644 --- a/ivy/functional/backends/tensorflow/experimental/manipulation.py +++ b/ivy/functional/backends/tensorflow/experimental/manipulation.py @@ -367,3 +367,28 @@ def fill_diagonal( a = tf.tensor_scatter_nd_update(a, indices, ups) a = tf.reshape(a, shape) return a + +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError \ No newline at end of file diff --git a/ivy/functional/backends/torch/experimental/manipulation.py b/ivy/functional/backends/torch/experimental/manipulation.py index e0d07dc57020c..e956c1f1cb062 100644 --- a/ivy/functional/backends/torch/experimental/manipulation.py +++ b/ivy/functional/backends/torch/experimental/manipulation.py @@ -395,3 +395,28 @@ def fill_diagonal( a = torch.where(w, v, a) a = torch.reshape(a, shape) return a + +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError \ No newline at end of file diff --git a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py index c38e1ab8153d4..46dfa60b54c42 100644 --- a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py +++ b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py @@ -366,3 +366,35 @@ def select(input, dim, index): slices = [slice(None)] * num_dims slices[dim] = index return input[tuple(slices)] + +@to_ivy_arrays_and_back +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError + + + + + + \ No newline at end of file diff --git a/ivy/functional/ivy/experimental/manipulation.py b/ivy/functional/ivy/experimental/manipulation.py index 85179235be665..8f46fc201c2d8 100644 --- a/ivy/functional/ivy/experimental/manipulation.py +++ b/ivy/functional/ivy/experimental/manipulation.py @@ -2152,3 +2152,28 @@ def fill_diagonal( Array with the diagonal filled. """ return ivy.current_backend(a).fill_diag(a, v, wrap=wrap) + +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError \ No newline at end of file diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py index 34cac1299f919..29ffde009976b 100644 --- a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py +++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py @@ -1593,3 +1593,28 @@ def test_torch_select( dim=axis, index=idx, ) + +def tensor_ops(tensor, operation_type, *args): + if operation_type == 'index': + if len(args) != 1: + raise ValueError + index = args[0] + return tensor[index] + elif operation_type == 'slice': + if len(args) != 2: + raise ValueError + start, end = args + return tensor[start:end] + elif operation_type == 'join': + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return tensor.cat((tensor, other_tensor), dim=0) + elif operation_type == 'mutate': + if len(args) != 1: + raise ValueError + factor = args[0] + tensor.mul_(factor) + return tensor + else: + raise ValueError \ No newline at end of file From 3960cdd3094048789a4d2de6740eff4c8abd389f Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Wed, 4 Oct 2023 05:41:26 +0000 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=A4=96=20Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- determine_tests.py | 2 -- duplicate.py | 1 - .../array/experimental/manipulation.py | 10 +++++----- .../container/experimental/manipulation.py | 13 +++++++------ .../backends/jax/experimental/manipulation.py | 11 ++++++----- .../backends/numpy/experimental/manipulation.py | 10 +++++----- .../tensorflow/experimental/manipulation.py | 11 ++++++----- .../backends/torch/experimental/manipulation.py | 11 ++++++----- ivy/functional/frontends/paddle/tensor/linalg.py | 5 +++-- .../indexing_slicing_joining_mutating_ops.py | 15 +++++---------- ivy/functional/ivy/experimental/manipulation.py | 11 ++++++----- .../test_fft/test_discrete_fourier_transform.py | 4 +--- .../test_indexing_slicing_joining_mutating_ops.py | 11 ++++++----- 13 files changed, 56 insertions(+), 59 deletions(-) diff --git a/determine_tests.py b/determine_tests.py index e712463123970..1df9628595625 100644 --- a/determine_tests.py +++ b/determine_tests.py @@ -11,8 +11,6 @@ MAX_TESTS = 10 - - def get_tests(_tests_file, _line): tests_file_line = set() if 0 <= _line < len(_tests_file): diff --git a/duplicate.py b/duplicate.py index 46483abad6242..e7ac5767d8b2c 100644 --- a/duplicate.py +++ b/duplicate.py @@ -3,7 +3,6 @@ import glob - def get_all_functions_from_directory(root_dir, startswith="test"): if not os.path.exists(root_dir): print("Invalid directory") diff --git a/ivy/data_classes/array/experimental/manipulation.py b/ivy/data_classes/array/experimental/manipulation.py index 75a8b0b566c0f..d93fc18239af4 100644 --- a/ivy/data_classes/array/experimental/manipulation.py +++ b/ivy/data_classes/array/experimental/manipulation.py @@ -1080,25 +1080,25 @@ def fill_diagonal( ivy.fill_diag also applies to this method with minimal changes. """ return ivy.fill_diagonal(self._data, v, wrap=wrap) - + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] diff --git a/ivy/data_classes/container/experimental/manipulation.py b/ivy/data_classes/container/experimental/manipulation.py index 5e5a8964a7dff..73e2b1f7ea6a3 100644 --- a/ivy/data_classes/container/experimental/manipulation.py +++ b/ivy/data_classes/container/experimental/manipulation.py @@ -2996,29 +2996,30 @@ def fill_diagonal( v, wrap=wrap, ) - + + @staticmethod def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/backends/jax/experimental/manipulation.py b/ivy/functional/backends/jax/experimental/manipulation.py index 193c725ede37d..29c9b12ddb93b 100644 --- a/ivy/functional/backends/jax/experimental/manipulation.py +++ b/ivy/functional/backends/jax/experimental/manipulation.py @@ -417,27 +417,28 @@ def fill_diagonal( a = jnp.reshape(a, shape) return a + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/backends/numpy/experimental/manipulation.py b/ivy/functional/backends/numpy/experimental/manipulation.py index cc55021f1fc65..ee0d10ecc4ca2 100644 --- a/ivy/functional/backends/numpy/experimental/manipulation.py +++ b/ivy/functional/backends/numpy/experimental/manipulation.py @@ -508,26 +508,26 @@ def fill_diagonal( def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/backends/tensorflow/experimental/manipulation.py b/ivy/functional/backends/tensorflow/experimental/manipulation.py index 84f049e7527ba..217ec50dc19cd 100644 --- a/ivy/functional/backends/tensorflow/experimental/manipulation.py +++ b/ivy/functional/backends/tensorflow/experimental/manipulation.py @@ -368,27 +368,28 @@ def fill_diagonal( a = tf.reshape(a, shape) return a + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/backends/torch/experimental/manipulation.py b/ivy/functional/backends/torch/experimental/manipulation.py index e956c1f1cb062..dfd236dadda7a 100644 --- a/ivy/functional/backends/torch/experimental/manipulation.py +++ b/ivy/functional/backends/torch/experimental/manipulation.py @@ -396,27 +396,28 @@ def fill_diagonal( a = torch.reshape(a, shape) return a + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/frontends/paddle/tensor/linalg.py b/ivy/functional/frontends/paddle/tensor/linalg.py index 7a9c70472a7e7..26e374d3111ac 100644 --- a/ivy/functional/frontends/paddle/tensor/linalg.py +++ b/ivy/functional/frontends/paddle/tensor/linalg.py @@ -6,6 +6,7 @@ to_ivy_arrays_and_back, ) + @with_supported_dtypes( {"2.5.0 and below": ("float32", "float64", "int32", "int64")}, "paddle" ) @@ -183,6 +184,7 @@ def dist(x, y, p=2): ret = ivy.vector_norm(ivy.subtract(x, y), ord=p) return ivy.reshape(ret, (1,)) + @with_supported_dtypes({"2.4.1 and above": ("int64",)}, "paddle") @to_ivy_arrays_and_back def linear_algebra_histogram(d, num_bins): @@ -191,10 +193,9 @@ def linear_algebra_histogram(d, num_bins): bin_width = (max_value - min_value) / num_bins bin_edges = ivy.arange(min_value, max_value + bin_width, bin_width) - # Count the number of values in each bin. + # Count the number of values in each bin. bin_counts = ivy.zeros(num_bins) for value in d: bin_index = ivy.searchsorted(bin_edges, value) bin_counts[bin_index] += 1 return ivy.bin_counts - \ No newline at end of file diff --git a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py index 46dfa60b54c42..cf91586a63ce9 100644 --- a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py +++ b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py @@ -367,24 +367,25 @@ def select(input, dim, index): slices[dim] = index return input[tuple(slices)] + @to_ivy_arrays_and_back def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] @@ -392,9 +393,3 @@ def tensor_ops(tensor, operation_type, *args): return tensor else: raise ValueError - - - - - - \ No newline at end of file diff --git a/ivy/functional/ivy/experimental/manipulation.py b/ivy/functional/ivy/experimental/manipulation.py index 8f46fc201c2d8..5f28f2a629c49 100644 --- a/ivy/functional/ivy/experimental/manipulation.py +++ b/ivy/functional/ivy/experimental/manipulation.py @@ -2153,27 +2153,28 @@ def fill_diagonal( """ return ivy.current_backend(a).fill_diag(a, v, wrap=wrap) + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py index fb6f723dc9682..09405ed65e3d7 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py @@ -92,9 +92,7 @@ def test_numpy_fft( available_dtypes=helpers.get_dtypes("float"), shape=(4,), array_api_dtypes=True ), ) -def fttshift( - dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device -): +def fttshift(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): input_dtype, arr = dtype_and_x helpers.test_frontend_function( input_dtypes=input_dtype, diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py index 29ffde009976b..eb0e8a583fabc 100644 --- a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py +++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py @@ -1594,27 +1594,28 @@ def test_torch_select( index=idx, ) + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return tensor.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError From 82a3d164b3a121fd27cbf97deffe9cbd4ea280be Mon Sep 17 00:00:00 2001 From: Sanjay <121057369+Sanjay8602@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:12:10 +0530 Subject: [PATCH 06/14] Delete determine_tests.py --- determine_tests.py | 193 --------------------------------------------- 1 file changed, 193 deletions(-) delete mode 100644 determine_tests.py diff --git a/determine_tests.py b/determine_tests.py deleted file mode 100644 index 1df9628595625..0000000000000 --- a/determine_tests.py +++ /dev/null @@ -1,193 +0,0 @@ -import pickle # noqa -import subprocess - -from pydriller import Repository -import os # noqa -import bz2 -import pickle as cPickle -import sys -from run_tests_CLI.get_all_tests import get_all_tests - -MAX_TESTS = 10 - - -def get_tests(_tests_file, _line): - tests_file_line = set() - if 0 <= _line < len(_tests_file): - tests_file_line = _tests_file[_line] - return set() if len(tests_file_line) >= MAX_TESTS else tests_file_line - - -def determine_tests_line(_tests_file, _line, _tests_to_run): - tests_file_line = get_tests(_tests_file, _line) - tests_file_prev = get_tests(_tests_file, _line - 1) - tests_file_next = get_tests(_tests_file, _line + 1) - _tests_to_run.update(tests_file_line) - _tests_to_run.update(tests_file_prev) - _tests_to_run.update(tests_file_next) - return _tests_to_run - - -def main(): - tests = bz2.BZ2File("tests.pbz2", "rb") - tests = cPickle.load(tests) - ref_commit_hash = tests["commit"] - print("Reference Commit: ", ref_commit_hash) - tests_to_run = set() - for commit in Repository(".", single=ref_commit_hash).traverse_commits(): - ref_commit = commit._c_object - break - - for commit in Repository(".", order="reverse").traverse_commits(): - tests["commit"] = commit.hash - diff_index = ref_commit.diff(commit._c_object, create_patch=True) - modified_files = commit._parse_diff(diff_index) - for file in modified_files: - try: - file_name = file.new_path + ",cover" - except: # noqa - continue - if file_name not in tests.keys(): - continue - tests_file = tests[file_name] - change = file.diff_parsed - added = set([x - 1 for (x, _) in change["added"]]) - deleted = set([x - 1 for (x, _) in change["deleted"]]) - updated = added.intersection(deleted) - added = added.difference(updated) - deleted = deleted.difference(updated) - # Now Update the Mapping and compute the tests to run - for line in deleted: - tests_to_run = determine_tests_line(tests_file, line, tests_to_run) - for line in sorted(deleted, reverse=True): - if line < len(tests_file): - del tests_file[line] - for line in added: - top = -1 - bottom = -1 - if 0 <= line - 1 < len(tests_file): - top = tests_file[line - 1] - if 0 <= line + 1 < len(tests_file): - bottom = tests_file[line + 1] - tests_line = set() - if top != -1 and bottom != -1: - tests_line = top.intersection(bottom) - elif top != -1: - tests_line = top - elif bottom != -1: - tests_line = bottom - tests_file.insert(line, tests_line) - tests[file_name] = tests_file - # Now Compute the Tests to Run - for line in updated: - tests_to_run = determine_tests_line(tests_file, line, tests_to_run) - for line in added: - tests_to_run = determine_tests_line(tests_file, line, tests_to_run) - break - - if len(sys.argv) >= 2 and sys.argv[1] == "1": - print("Checking for any new tests added!") - new_tests = get_all_tests() - print("Done!") - # Check for any new tests present - old_tests = tests["index_mapping"] - added_tests = set(new_tests) - set(old_tests) - removed_tests = set(old_tests) - set(new_tests) - with open("tests_to_remove", "w") as f: - for test in removed_tests: - f.write(test + "\n") - added_tests = list(added_tests) - # if it is a PR, we must check that the tests added were in the files_changes - if len(sys.argv) >= 3 and sys.argv[2] == "pr": - relevant_added_tests = [] - subprocess.run( - ["git", "remote", "add", "upstream", "https://github.com/unifyai/ivy"] - ) - subprocess.run(["git", "fetch", "upstream"]) - lca_sha = subprocess.check_output( - ["git", "merge-base", "HEAD", "upstream/master"] - ) - lca_hash = lca_sha.decode().strip() - for commit in Repository(".", single=lca_hash).traverse_commits(): - lca_commit = commit._c_object - break - for commit in Repository(".", order="reverse").traverse_commits(): - diff_index = lca_commit.diff(commit._c_object, create_patch=True) - modified_files = commit._parse_diff(diff_index) - break - for test in added_tests: - for file in modified_files: - if file.new_path.strip() in test: - relevant_added_tests.append(test) - break - added_tests = relevant_added_tests - else: - if len(added_tests) > 50: - added_tests = added_tests[:50] - # Add these new_tests in the Mapping - old_num_tests = len(old_tests) - tests["index_mapping"] += added_tests - new_tests = tests["index_mapping"] - num_tests = len(new_tests) - for i in range(old_num_tests, num_tests): - tests["tests_mapping"][new_tests[i]] = i - directories = ( - [x[0] for x in os.walk("ivy")] - + [x[0] for x in os.walk("ivy_tests/test_ivy")] - + ["ivy_tests"] - ) - directories_filtered = [ - x - for x in directories - if not (x.endswith("__pycache__") or "hypothesis" in x) - ] - directories = set(directories_filtered) - for test_backend in new_tests[old_num_tests:num_tests]: - tests_to_run.add(tests["tests_mapping"][test_backend]) - if len(sys.argv) < 3: - print("Computing Coverage:", test_backend) - test_name, backend = test_backend.split(",") - command = ( - f'docker run -v "$(pwd)":/ivy unifyai/ivy:latest /bin/bash -c "coverage run --source=ivy,' # noqa - f"ivy_tests -m pytest {test_name} --backend {backend} --disable-warnings > coverage_output;coverage " # noqa - f'annotate > coverage_output" ' - ) - os.system(command) - for directory in directories: - for file_name in os.listdir(directory): - if file_name.endswith("cover"): - file_name = directory + "/" + file_name - if file_name not in tests: - tests[file_name] = [] - with open(file_name) as f: - for line in f: - tests[file_name].append(set()) - with open(file_name) as f: - i = 0 - for line in f: - if i >= len(tests[file_name]): - tests[file_name].append(set()) - if line[0] == ">": - tests[file_name][i].add( - tests["tests_mapping"][test_backend] - ) - i += 1 - os.system("find . -name \\*cover -type f -delete") - - with bz2.BZ2File("tests.pbz2", "w") as f: - cPickle.dump(tests, f) - - print("----- Determined Tests -----") - print(len(tests_to_run)) - for test_index in tests_to_run: - print(tests["index_mapping"][test_index]) - print("----------------------------") - - with open("tests_to_run", "w") as f: - for test_index in tests_to_run: - test = tests["index_mapping"][test_index] - f.write(test + "\n") - - -if __name__ == "__main__": - main() From 00d6d21c10a65cb5b5266eb138b6a0e0fdccd0bb Mon Sep 17 00:00:00 2001 From: Sanjay <121057369+Sanjay8602@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:12:56 +0530 Subject: [PATCH 07/14] Delete ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py --- .../test_discrete_fourier_transform.py | 252 ------------------ 1 file changed, 252 deletions(-) delete mode 100644 ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py deleted file mode 100644 index 09405ed65e3d7..0000000000000 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py +++ /dev/null @@ -1,252 +0,0 @@ -# global -from hypothesis import strategies as st - -# local -import ivy_tests.test_ivy.helpers as helpers -from ivy_tests.test_ivy.helpers import handle_frontend_test -from ivy_tests.test_ivy.test_functional.test_experimental.test_nn.test_layers import ( - x_and_ifft, - x_and_rfftn, -) - -# ivy_tests/test_ivy/test_functional/test_experimental/test_nn/test_layers.py - - -@handle_frontend_test( - fn_tree="numpy.fft.ifft", - dtype_and_x=x_and_ifft(), -) -def test_numpy_ifft(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): - input_dtype, x, dim, norm, n = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x, - n=n, - axis=dim, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.ifftshift", - dtype_and_x=helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("float"), shape=(4,), array_api_dtypes=True - ), -) -def test_numpy_ifftshift( - dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device -): - input_dtype, arr = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - x=arr[0], - axes=None, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.fft", - dtype_input_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("float_and_complex"), - shape=(2,), - min_axis=-1, - force_int_axis=True, - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), - n=st.integers(min_value=2, max_value=10), -) -def test_numpy_fft( - dtype_input_axis, norm, n, backend_fw, frontend, test_flags, fn_tree, on_device -): - input_dtype, x, axis = dtype_input_axis - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x[0], - n=n, - axis=axis, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.fftshift", - dtype_and_x=helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("float"), shape=(4,), array_api_dtypes=True - ), -) -def fttshift(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): - input_dtype, arr = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - x=arr[0], - axes=None, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.rfft", - dtype_input_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("float_and_complex"), - shape=(2,), - min_axis=-1, - force_int_axis=True, - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), - n=st.integers(min_value=2, max_value=5), -) -def test_numpy_rfft( - dtype_input_axis, norm, n, backend_fw, frontend, test_flags, fn_tree, on_device -): - input_dtype, x, axis = dtype_input_axis - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x[0], - n=n, - axis=axis, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.ihfft", - dtype_input_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("float_and_complex"), - shape=(2,), - min_axis=-1, - force_int_axis=True, - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), - n=st.integers(min_value=2, max_value=5), -) -def test_numpy_ihfft( - dtype_input_axis, norm, n, backend_fw, frontend, test_flags, fn_tree, on_device -): - input_dtype, x, axis = dtype_input_axis - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x[0], - n=n, - axis=axis, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.fftfreq", - n=st.integers(min_value=10, max_value=100), - sample_rate=st.integers(min_value=1, max_value=10), -) -def test_numpy_fftfreq( - n, sample_rate, backend_fw, frontend, test_flags, fn_tree, on_device -): - d = 1 / sample_rate - helpers.test_frontend_function( - input_dtypes=[int], - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - n=n, - d=d, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.rfftfreq", - n=st.integers(min_value=10, max_value=100), - sample_rate=st.integers(min_value=1, max_value=10), -) -def test_numpy_rfftfreq( - n, sample_rate, backend_fw, frontend, test_flags, fn_tree, on_device -): - d = 1 / sample_rate - helpers.test_frontend_function( - input_dtypes=[int], - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - n=n, - d=d, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.ifftn", - dtype_and_x=x_and_ifft(), -) -def test_numpy_ifftn(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): - input_dtype, x, dim, norm, n = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x, - s=None, - axes=None, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.rfftn", - dtype_and_x=x_and_rfftn(), -) -def test_numpy_rfftn(dtype_and_x, frontend, test_flags, fn_tree, on_device): - dtype, x, s, axes, norm = dtype_and_x - helpers.test_frontend_function( - input_dtypes=dtype, - frontend=frontend, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x, - s=s, - axes=axes, - norm=norm, - ) From 7337c7f069c0fa2cb036917de0ad022411616d0d Mon Sep 17 00:00:00 2001 From: Sanjay <121057369+Sanjay8602@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:41:56 +0530 Subject: [PATCH 08/14] Delete duplicate.py --- duplicate.py | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 duplicate.py diff --git a/duplicate.py b/duplicate.py deleted file mode 100644 index e7ac5767d8b2c..0000000000000 --- a/duplicate.py +++ /dev/null @@ -1,43 +0,0 @@ -import importlib -import os -import glob - - -def get_all_functions_from_directory(root_dir, startswith="test"): - if not os.path.exists(root_dir): - print("Invalid directory") - exit(1) - functions_names = [] - for filename in glob.iglob(root_dir + "/**/*.py", recursive=True): - if len(filename) >= 2 and filename[:2] == "./": - filename = filename[2:] - filename = filename.replace(".py", "") - filename = filename.replace("/", ".") - module = importlib.import_module(filename) - module_functions_names = [ - obj for obj in dir(module) if obj.startswith(startswith) - ] - functions_names.extend(module_functions_names) - return functions_names - - -def check_duplicate(): - fn_test_core = get_all_functions_from_directory( - "ivy_tests/test_ivy/test_functional/test_core" - ) - fn_test_nn = get_all_functions_from_directory( - "ivy_tests/test_ivy/test_functional/test_nn" - ) - fn_test_experimental = get_all_functions_from_directory( - "ivy_tests/test_ivy/test_functional/test_experimental" - ) - fn_ivy_test = set(fn_test_core).union(set(fn_test_nn)) - common_list = fn_ivy_test.intersection(set(fn_test_experimental)) - return common_list - - -if __name__ == "__main__": - common_set = check_duplicate() - if len(common_set) != 0: - print("This function already exists in the functional API.") - exit(1) From 0061c011a86db23ac4ca5ee0ff19f1aad16cf3d3 Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Wed, 4 Oct 2023 05:41:26 +0000 Subject: [PATCH 09/14] =?UTF-8?q?=F0=9F=A4=96=20Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: added the tensor operations --- determine_tests.py | 2 -- duplicate.py | 1 - .../array/experimental/manipulation.py | 10 ++++---- .../container/experimental/manipulation.py | 13 +++++----- .../backends/jax/experimental/manipulation.py | 11 ++++---- .../numpy/experimental/manipulation.py | 10 ++++---- .../tensorflow/experimental/manipulation.py | 11 ++++---- .../torch/experimental/manipulation.py | 11 ++++---- .../frontends/paddle/tensor/linalg.py | 5 ++-- .../indexing_slicing_joining_mutating_ops.py | 25 ++++++++----------- .../ivy/experimental/manipulation.py | 11 ++++---- .../test_discrete_fourier_transform.py | 4 +-- ...t_indexing_slicing_joining_mutating_ops.py | 11 ++++---- 13 files changed, 61 insertions(+), 64 deletions(-) diff --git a/determine_tests.py b/determine_tests.py index e712463123970..1df9628595625 100644 --- a/determine_tests.py +++ b/determine_tests.py @@ -11,8 +11,6 @@ MAX_TESTS = 10 - - def get_tests(_tests_file, _line): tests_file_line = set() if 0 <= _line < len(_tests_file): diff --git a/duplicate.py b/duplicate.py index 46483abad6242..e7ac5767d8b2c 100644 --- a/duplicate.py +++ b/duplicate.py @@ -3,7 +3,6 @@ import glob - def get_all_functions_from_directory(root_dir, startswith="test"): if not os.path.exists(root_dir): print("Invalid directory") diff --git a/ivy/data_classes/array/experimental/manipulation.py b/ivy/data_classes/array/experimental/manipulation.py index 75a8b0b566c0f..d93fc18239af4 100644 --- a/ivy/data_classes/array/experimental/manipulation.py +++ b/ivy/data_classes/array/experimental/manipulation.py @@ -1080,25 +1080,25 @@ def fill_diagonal( ivy.fill_diag also applies to this method with minimal changes. """ return ivy.fill_diagonal(self._data, v, wrap=wrap) - + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] diff --git a/ivy/data_classes/container/experimental/manipulation.py b/ivy/data_classes/container/experimental/manipulation.py index 5e5a8964a7dff..73e2b1f7ea6a3 100644 --- a/ivy/data_classes/container/experimental/manipulation.py +++ b/ivy/data_classes/container/experimental/manipulation.py @@ -2996,29 +2996,30 @@ def fill_diagonal( v, wrap=wrap, ) - + + @staticmethod def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/backends/jax/experimental/manipulation.py b/ivy/functional/backends/jax/experimental/manipulation.py index 193c725ede37d..29c9b12ddb93b 100644 --- a/ivy/functional/backends/jax/experimental/manipulation.py +++ b/ivy/functional/backends/jax/experimental/manipulation.py @@ -417,27 +417,28 @@ def fill_diagonal( a = jnp.reshape(a, shape) return a + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/backends/numpy/experimental/manipulation.py b/ivy/functional/backends/numpy/experimental/manipulation.py index cc55021f1fc65..ee0d10ecc4ca2 100644 --- a/ivy/functional/backends/numpy/experimental/manipulation.py +++ b/ivy/functional/backends/numpy/experimental/manipulation.py @@ -508,26 +508,26 @@ def fill_diagonal( def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/backends/tensorflow/experimental/manipulation.py b/ivy/functional/backends/tensorflow/experimental/manipulation.py index 84f049e7527ba..217ec50dc19cd 100644 --- a/ivy/functional/backends/tensorflow/experimental/manipulation.py +++ b/ivy/functional/backends/tensorflow/experimental/manipulation.py @@ -368,27 +368,28 @@ def fill_diagonal( a = tf.reshape(a, shape) return a + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/backends/torch/experimental/manipulation.py b/ivy/functional/backends/torch/experimental/manipulation.py index e956c1f1cb062..dfd236dadda7a 100644 --- a/ivy/functional/backends/torch/experimental/manipulation.py +++ b/ivy/functional/backends/torch/experimental/manipulation.py @@ -396,27 +396,28 @@ def fill_diagonal( a = torch.reshape(a, shape) return a + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy/functional/frontends/paddle/tensor/linalg.py b/ivy/functional/frontends/paddle/tensor/linalg.py index 7a9c70472a7e7..26e374d3111ac 100644 --- a/ivy/functional/frontends/paddle/tensor/linalg.py +++ b/ivy/functional/frontends/paddle/tensor/linalg.py @@ -6,6 +6,7 @@ to_ivy_arrays_and_back, ) + @with_supported_dtypes( {"2.5.0 and below": ("float32", "float64", "int32", "int64")}, "paddle" ) @@ -183,6 +184,7 @@ def dist(x, y, p=2): ret = ivy.vector_norm(ivy.subtract(x, y), ord=p) return ivy.reshape(ret, (1,)) + @with_supported_dtypes({"2.4.1 and above": ("int64",)}, "paddle") @to_ivy_arrays_and_back def linear_algebra_histogram(d, num_bins): @@ -191,10 +193,9 @@ def linear_algebra_histogram(d, num_bins): bin_width = (max_value - min_value) / num_bins bin_edges = ivy.arange(min_value, max_value + bin_width, bin_width) - # Count the number of values in each bin. + # Count the number of values in each bin. bin_counts = ivy.zeros(num_bins) for value in d: bin_index = ivy.searchsorted(bin_edges, value) bin_counts[bin_index] += 1 return ivy.bin_counts - \ No newline at end of file diff --git a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py index 46dfa60b54c42..c15e2d13439f0 100644 --- a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py +++ b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py @@ -367,34 +367,29 @@ def select(input, dim, index): slices[dim] = index return input[tuple(slices)] + @to_ivy_arrays_and_back -def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': +def tensor_ops(tensor, operations_type, *args): + if operations_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operations_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': - if len(args) != 1: - raise ValueError - other_tensor = args[0] - return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operations_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) + elif operations_type == "join": + if len(args) != 1: + raise ValueError + other_tensor = args[0] + return ivy.cat((tensor, other_tensor), dim=0) return tensor else: raise ValueError - - - - - - \ No newline at end of file diff --git a/ivy/functional/ivy/experimental/manipulation.py b/ivy/functional/ivy/experimental/manipulation.py index 8f46fc201c2d8..5f28f2a629c49 100644 --- a/ivy/functional/ivy/experimental/manipulation.py +++ b/ivy/functional/ivy/experimental/manipulation.py @@ -2153,27 +2153,28 @@ def fill_diagonal( """ return ivy.current_backend(a).fill_diag(a, v, wrap=wrap) + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return ivy.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py index fb6f723dc9682..09405ed65e3d7 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py @@ -92,9 +92,7 @@ def test_numpy_fft( available_dtypes=helpers.get_dtypes("float"), shape=(4,), array_api_dtypes=True ), ) -def fttshift( - dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device -): +def fttshift(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): input_dtype, arr = dtype_and_x helpers.test_frontend_function( input_dtypes=input_dtype, diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py index 29ffde009976b..eb0e8a583fabc 100644 --- a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py +++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py @@ -1594,27 +1594,28 @@ def test_torch_select( index=idx, ) + def tensor_ops(tensor, operation_type, *args): - if operation_type == 'index': + if operation_type == "index": if len(args) != 1: raise ValueError index = args[0] return tensor[index] - elif operation_type == 'slice': + elif operation_type == "slice": if len(args) != 2: raise ValueError start, end = args return tensor[start:end] - elif operation_type == 'join': + elif operation_type == "join": if len(args) != 1: raise ValueError other_tensor = args[0] return tensor.cat((tensor, other_tensor), dim=0) - elif operation_type == 'mutate': + elif operation_type == "mutate": if len(args) != 1: raise ValueError factor = args[0] tensor.mul_(factor) return tensor else: - raise ValueError \ No newline at end of file + raise ValueError From f280b52fe42b4aafc38ef83b82ca70172196d05f Mon Sep 17 00:00:00 2001 From: Sanjay <121057369+Sanjay8602@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:23:15 +0530 Subject: [PATCH 10/14] Delete ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py --- .../test_discrete_fourier_transform.py | 252 ------------------ 1 file changed, 252 deletions(-) delete mode 100644 ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py deleted file mode 100644 index 09405ed65e3d7..0000000000000 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_fft/test_discrete_fourier_transform.py +++ /dev/null @@ -1,252 +0,0 @@ -# global -from hypothesis import strategies as st - -# local -import ivy_tests.test_ivy.helpers as helpers -from ivy_tests.test_ivy.helpers import handle_frontend_test -from ivy_tests.test_ivy.test_functional.test_experimental.test_nn.test_layers import ( - x_and_ifft, - x_and_rfftn, -) - -# ivy_tests/test_ivy/test_functional/test_experimental/test_nn/test_layers.py - - -@handle_frontend_test( - fn_tree="numpy.fft.ifft", - dtype_and_x=x_and_ifft(), -) -def test_numpy_ifft(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): - input_dtype, x, dim, norm, n = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x, - n=n, - axis=dim, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.ifftshift", - dtype_and_x=helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("float"), shape=(4,), array_api_dtypes=True - ), -) -def test_numpy_ifftshift( - dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device -): - input_dtype, arr = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - x=arr[0], - axes=None, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.fft", - dtype_input_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("float_and_complex"), - shape=(2,), - min_axis=-1, - force_int_axis=True, - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), - n=st.integers(min_value=2, max_value=10), -) -def test_numpy_fft( - dtype_input_axis, norm, n, backend_fw, frontend, test_flags, fn_tree, on_device -): - input_dtype, x, axis = dtype_input_axis - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x[0], - n=n, - axis=axis, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.fftshift", - dtype_and_x=helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("float"), shape=(4,), array_api_dtypes=True - ), -) -def fttshift(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): - input_dtype, arr = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - x=arr[0], - axes=None, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.rfft", - dtype_input_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("float_and_complex"), - shape=(2,), - min_axis=-1, - force_int_axis=True, - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), - n=st.integers(min_value=2, max_value=5), -) -def test_numpy_rfft( - dtype_input_axis, norm, n, backend_fw, frontend, test_flags, fn_tree, on_device -): - input_dtype, x, axis = dtype_input_axis - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x[0], - n=n, - axis=axis, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.ihfft", - dtype_input_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("float_and_complex"), - shape=(2,), - min_axis=-1, - force_int_axis=True, - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), - n=st.integers(min_value=2, max_value=5), -) -def test_numpy_ihfft( - dtype_input_axis, norm, n, backend_fw, frontend, test_flags, fn_tree, on_device -): - input_dtype, x, axis = dtype_input_axis - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x[0], - n=n, - axis=axis, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.fftfreq", - n=st.integers(min_value=10, max_value=100), - sample_rate=st.integers(min_value=1, max_value=10), -) -def test_numpy_fftfreq( - n, sample_rate, backend_fw, frontend, test_flags, fn_tree, on_device -): - d = 1 / sample_rate - helpers.test_frontend_function( - input_dtypes=[int], - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - n=n, - d=d, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.rfftfreq", - n=st.integers(min_value=10, max_value=100), - sample_rate=st.integers(min_value=1, max_value=10), -) -def test_numpy_rfftfreq( - n, sample_rate, backend_fw, frontend, test_flags, fn_tree, on_device -): - d = 1 / sample_rate - helpers.test_frontend_function( - input_dtypes=[int], - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - n=n, - d=d, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.ifftn", - dtype_and_x=x_and_ifft(), -) -def test_numpy_ifftn(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device): - input_dtype, x, dim, norm, n = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x, - s=None, - axes=None, - norm=norm, - ) - - -@handle_frontend_test( - fn_tree="numpy.fft.rfftn", - dtype_and_x=x_and_rfftn(), -) -def test_numpy_rfftn(dtype_and_x, frontend, test_flags, fn_tree, on_device): - dtype, x, s, axes, norm = dtype_and_x - helpers.test_frontend_function( - input_dtypes=dtype, - frontend=frontend, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - test_values=True, - a=x, - s=s, - axes=axes, - norm=norm, - ) From 7bae7a2ca647a90e1a2cc337a84cfbc9144d0a72 Mon Sep 17 00:00:00 2001 From: Sanjay <121057369+Sanjay8602@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:24:06 +0530 Subject: [PATCH 11/14] Delete ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_norm.py --- .../test_nn/test_functional/test_norm.py | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_norm.py diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_norm.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_norm.py deleted file mode 100644 index 67bf5a6a4ff6e..0000000000000 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_norm.py +++ /dev/null @@ -1,49 +0,0 @@ -# global -from typing import Literal -from hypothesis import strategies as st - -# local -import ivy_tests.test_ivy.helpers as helpers -from ivy_tests.test_ivy.helpers.testing_helpers import handle_frontend_test - -from ivy_tests.test_ivy.test_functional.test_nn.test_norms import ( - _generate_data_layer_norm, -) - -from ivy import ivy - - -# layer_norm -@handle_frontend_test( - fn_tree="paddle.nn.functional.layer_norm", - values_tuple=_generate_data_layer_norm( - available_dtypes=helpers.get_dtypes("float"), - ), - eps=st.floats(min_value=0.01, max_value=0.1), -) -def test_paddle_layer_norm( - *, - values_tuple, - normalized_shape, - eps, - test_flags, - frontend: Literal['paddle'], - on_device, - fn_tree, -): - (dtype, x, normalized_shape, scale, offset) = values_tuple - helpers.test_frontend_function( - input_dtypes=dtype, - frontend=frontend, - test_flags=test_flags, - on_device=on_device, - fn_tree=fn_tree, - x=x[0], - normalized_shape=normalized_shape, - weight=scale[0], - bias=offset[0], - epsilon=eps, - ) - -def batch_norm(x, gamma, beta, moving_mean, moving_var, epsilon=1e-5): - return ivy.batch_norm(x, gamma, beta, moving_mean, moving_var, epsilon) From c3d51e1ce1a5a31e6e5d2d1f8af7ff21d798ea95 Mon Sep 17 00:00:00 2001 From: Sanjay <121057369+Sanjay8602@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:24:37 +0530 Subject: [PATCH 12/14] Delete determine_tests.py --- determine_tests.py | 193 --------------------------------------------- 1 file changed, 193 deletions(-) delete mode 100644 determine_tests.py diff --git a/determine_tests.py b/determine_tests.py deleted file mode 100644 index 1df9628595625..0000000000000 --- a/determine_tests.py +++ /dev/null @@ -1,193 +0,0 @@ -import pickle # noqa -import subprocess - -from pydriller import Repository -import os # noqa -import bz2 -import pickle as cPickle -import sys -from run_tests_CLI.get_all_tests import get_all_tests - -MAX_TESTS = 10 - - -def get_tests(_tests_file, _line): - tests_file_line = set() - if 0 <= _line < len(_tests_file): - tests_file_line = _tests_file[_line] - return set() if len(tests_file_line) >= MAX_TESTS else tests_file_line - - -def determine_tests_line(_tests_file, _line, _tests_to_run): - tests_file_line = get_tests(_tests_file, _line) - tests_file_prev = get_tests(_tests_file, _line - 1) - tests_file_next = get_tests(_tests_file, _line + 1) - _tests_to_run.update(tests_file_line) - _tests_to_run.update(tests_file_prev) - _tests_to_run.update(tests_file_next) - return _tests_to_run - - -def main(): - tests = bz2.BZ2File("tests.pbz2", "rb") - tests = cPickle.load(tests) - ref_commit_hash = tests["commit"] - print("Reference Commit: ", ref_commit_hash) - tests_to_run = set() - for commit in Repository(".", single=ref_commit_hash).traverse_commits(): - ref_commit = commit._c_object - break - - for commit in Repository(".", order="reverse").traverse_commits(): - tests["commit"] = commit.hash - diff_index = ref_commit.diff(commit._c_object, create_patch=True) - modified_files = commit._parse_diff(diff_index) - for file in modified_files: - try: - file_name = file.new_path + ",cover" - except: # noqa - continue - if file_name not in tests.keys(): - continue - tests_file = tests[file_name] - change = file.diff_parsed - added = set([x - 1 for (x, _) in change["added"]]) - deleted = set([x - 1 for (x, _) in change["deleted"]]) - updated = added.intersection(deleted) - added = added.difference(updated) - deleted = deleted.difference(updated) - # Now Update the Mapping and compute the tests to run - for line in deleted: - tests_to_run = determine_tests_line(tests_file, line, tests_to_run) - for line in sorted(deleted, reverse=True): - if line < len(tests_file): - del tests_file[line] - for line in added: - top = -1 - bottom = -1 - if 0 <= line - 1 < len(tests_file): - top = tests_file[line - 1] - if 0 <= line + 1 < len(tests_file): - bottom = tests_file[line + 1] - tests_line = set() - if top != -1 and bottom != -1: - tests_line = top.intersection(bottom) - elif top != -1: - tests_line = top - elif bottom != -1: - tests_line = bottom - tests_file.insert(line, tests_line) - tests[file_name] = tests_file - # Now Compute the Tests to Run - for line in updated: - tests_to_run = determine_tests_line(tests_file, line, tests_to_run) - for line in added: - tests_to_run = determine_tests_line(tests_file, line, tests_to_run) - break - - if len(sys.argv) >= 2 and sys.argv[1] == "1": - print("Checking for any new tests added!") - new_tests = get_all_tests() - print("Done!") - # Check for any new tests present - old_tests = tests["index_mapping"] - added_tests = set(new_tests) - set(old_tests) - removed_tests = set(old_tests) - set(new_tests) - with open("tests_to_remove", "w") as f: - for test in removed_tests: - f.write(test + "\n") - added_tests = list(added_tests) - # if it is a PR, we must check that the tests added were in the files_changes - if len(sys.argv) >= 3 and sys.argv[2] == "pr": - relevant_added_tests = [] - subprocess.run( - ["git", "remote", "add", "upstream", "https://github.com/unifyai/ivy"] - ) - subprocess.run(["git", "fetch", "upstream"]) - lca_sha = subprocess.check_output( - ["git", "merge-base", "HEAD", "upstream/master"] - ) - lca_hash = lca_sha.decode().strip() - for commit in Repository(".", single=lca_hash).traverse_commits(): - lca_commit = commit._c_object - break - for commit in Repository(".", order="reverse").traverse_commits(): - diff_index = lca_commit.diff(commit._c_object, create_patch=True) - modified_files = commit._parse_diff(diff_index) - break - for test in added_tests: - for file in modified_files: - if file.new_path.strip() in test: - relevant_added_tests.append(test) - break - added_tests = relevant_added_tests - else: - if len(added_tests) > 50: - added_tests = added_tests[:50] - # Add these new_tests in the Mapping - old_num_tests = len(old_tests) - tests["index_mapping"] += added_tests - new_tests = tests["index_mapping"] - num_tests = len(new_tests) - for i in range(old_num_tests, num_tests): - tests["tests_mapping"][new_tests[i]] = i - directories = ( - [x[0] for x in os.walk("ivy")] - + [x[0] for x in os.walk("ivy_tests/test_ivy")] - + ["ivy_tests"] - ) - directories_filtered = [ - x - for x in directories - if not (x.endswith("__pycache__") or "hypothesis" in x) - ] - directories = set(directories_filtered) - for test_backend in new_tests[old_num_tests:num_tests]: - tests_to_run.add(tests["tests_mapping"][test_backend]) - if len(sys.argv) < 3: - print("Computing Coverage:", test_backend) - test_name, backend = test_backend.split(",") - command = ( - f'docker run -v "$(pwd)":/ivy unifyai/ivy:latest /bin/bash -c "coverage run --source=ivy,' # noqa - f"ivy_tests -m pytest {test_name} --backend {backend} --disable-warnings > coverage_output;coverage " # noqa - f'annotate > coverage_output" ' - ) - os.system(command) - for directory in directories: - for file_name in os.listdir(directory): - if file_name.endswith("cover"): - file_name = directory + "/" + file_name - if file_name not in tests: - tests[file_name] = [] - with open(file_name) as f: - for line in f: - tests[file_name].append(set()) - with open(file_name) as f: - i = 0 - for line in f: - if i >= len(tests[file_name]): - tests[file_name].append(set()) - if line[0] == ">": - tests[file_name][i].add( - tests["tests_mapping"][test_backend] - ) - i += 1 - os.system("find . -name \\*cover -type f -delete") - - with bz2.BZ2File("tests.pbz2", "w") as f: - cPickle.dump(tests, f) - - print("----- Determined Tests -----") - print(len(tests_to_run)) - for test_index in tests_to_run: - print(tests["index_mapping"][test_index]) - print("----------------------------") - - with open("tests_to_run", "w") as f: - for test_index in tests_to_run: - test = tests["index_mapping"][test_index] - f.write(test + "\n") - - -if __name__ == "__main__": - main() From 857e841bc8018a4602336bb862c4d8688057b520 Mon Sep 17 00:00:00 2001 From: Sanjay <121057369+Sanjay8602@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:25:40 +0530 Subject: [PATCH 13/14] Delete ivy/functional/frontends/paddle/tensor/linalg.py --- .../frontends/paddle/tensor/linalg.py | 201 ------------------ 1 file changed, 201 deletions(-) delete mode 100644 ivy/functional/frontends/paddle/tensor/linalg.py diff --git a/ivy/functional/frontends/paddle/tensor/linalg.py b/ivy/functional/frontends/paddle/tensor/linalg.py deleted file mode 100644 index 26e374d3111ac..0000000000000 --- a/ivy/functional/frontends/paddle/tensor/linalg.py +++ /dev/null @@ -1,201 +0,0 @@ -# global -import ivy -from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes -from ivy.functional.frontends.paddle import promote_types_of_paddle_inputs -from ivy.functional.frontends.paddle.func_wrapper import ( - to_ivy_arrays_and_back, -) - - -@with_supported_dtypes( - {"2.5.0 and below": ("float32", "float64", "int32", "int64")}, "paddle" -) -@to_ivy_arrays_and_back -def cross(x, y, /, *, axis=9, name=None): - x, y = promote_types_of_paddle_inputs(x, y) - return ivy.cross(x, y, axis=axis) - - -# matmul -@with_unsupported_dtypes({"2.5.0 and below": ("float16", "bfloat16")}, "paddle") -@to_ivy_arrays_and_back -def matmul(x, y, transpose_x=False, transpose_y=False, name=None): - x, y = promote_types_of_paddle_inputs(x, y) - return ivy.matmul(x, y, transpose_a=transpose_x, transpose_b=transpose_y) - - -# norm -@with_supported_dtypes({"2.5.0 and below": ("float32", "float64")}, "paddle") -@to_ivy_arrays_and_back -def norm(x, p="fro", axis=None, keepdim=False, name=None): - if axis is None and p is not None: - if p == "fro": - p = 2 - ret = ivy.vector_norm(x.flatten(), ord=p, axis=-1) - if keepdim: - ret = ret.reshape([1] * len(x.shape)) - if len(ret.shape) == 0: - return ivy.array([ret]) - return ret - - if isinstance(axis, tuple): - axis = list(axis) - if isinstance(axis, list) and len(axis) == 1: - axis = axis[0] - - if isinstance(axis, int): - if p == "fro": - p = 2 - if p in [0, 1, 2, ivy.inf, -ivy.inf]: - ret = ivy.vector_norm(x, ord=p, axis=axis, keepdims=keepdim) - elif isinstance(p, (int, float)): - ret = ivy.pow( - ivy.sum(ivy.pow(ivy.abs(x), p), axis=axis, keepdims=keepdim), - float(1.0 / p), - ) - - elif isinstance(axis, list) and len(axis) == 2: - if p == 0: - raise ValueError - elif p == 1: - ret = ivy.sum(ivy.abs(x), axis=axis, keepdims=keepdim) - elif p == 2 or p == "fro": - ret = ivy.matrix_norm(x, ord="fro", axis=axis, keepdims=keepdim) - elif p == ivy.inf: - ret = ivy.max(ivy.abs(x), axis=axis, keepdims=keepdim) - elif p == -ivy.inf: - ret = ivy.min(ivy.abs(x), axis=axis, keepdims=keepdim) - elif isinstance(p, (int, float)) and p > 0: - ret = ivy.pow( - ivy.sum(ivy.pow(ivy.abs(x), p), axis=axis, keepdims=keepdim), - float(1.0 / p), - ) - else: - raise ValueError - - else: - raise ValueError - - if len(ret.shape) == 0: - ret = ivy.array( - [ret] - ) # this is done so as to match shape of output from paddle - return ret - - -# eig -@to_ivy_arrays_and_back -def eig(x, name=None): - return ivy.eig(x) - - -# eigvals -@to_ivy_arrays_and_back -def eigvals(x, name=None): - return ivy.eigvals(x) - - -# eigvalsh -@to_ivy_arrays_and_back -def eigvalsh(x, UPLO="L", name=None): - return ivy.eigvalsh(x, UPLO=UPLO) - - -# eigh -@to_ivy_arrays_and_back -def eigh(x, UPLO="L", name=None): - return ivy.eigh(x, UPLO=UPLO) - - -# pinv -@with_unsupported_dtypes({"2.5.0 and below": ("float16", "bfloat16")}, "paddle") -@to_ivy_arrays_and_back -def pinv(x, rcond=1e-15, hermitian=False, name=None): - # TODO: Add hermitian functionality - return ivy.pinv(x, rtol=rcond) - - -# solve -@with_unsupported_dtypes({"2.5.0 and below": ("float16", "bfloat16")}, "paddle") -@to_ivy_arrays_and_back -def solve(x1, x2, name=None): - return ivy.solve(x1, x2) - - -# cholesky -@with_supported_dtypes({"2.5.0 and below": ("float32", "float64")}, "paddle") -@to_ivy_arrays_and_back -def cholesky(x, /, *, upper=False, name=None): - return ivy.cholesky(x, upper=upper) - - -# bmm -@with_unsupported_dtypes({"2.5.0 and below": ("float16", "bfloat16")}, "paddle") -@to_ivy_arrays_and_back -def bmm(x, y, transpose_x=False, transpose_y=False, name=None): - if len(ivy.shape(x)) != 3 or len(ivy.shape(y)) != 3: - raise RuntimeError("input must be 3D matrices") - x, y = promote_types_of_paddle_inputs(x, y) - return ivy.matmul(x, y, transpose_a=transpose_x, transpose_b=transpose_y) - - -# matrix_power -@with_unsupported_dtypes({"2.5.0 and below": ("float16", "bfloat16")}, "paddle") -@to_ivy_arrays_and_back -def matrix_power(x, n, name=None): - return ivy.matrix_power(x, n) - - -# cond -@with_supported_dtypes({"2.5.0 and below": ("float32", "float64")}, "paddle") -@to_ivy_arrays_and_back -def cond(x, p=None, name=None): - ret = ivy.cond(x, p=p, out=name) - if ret.shape == (): - ret = ret.reshape((1,)) - return ret - - -# dot -@with_supported_dtypes({"2.5.0 and below": ("float32", "float64")}, "paddle") -@to_ivy_arrays_and_back -def dot(x, y, name=None): - x, y = promote_types_of_paddle_inputs(x, y) - out = ivy.multiply(x, y) - return ivy.sum(out, axis=ivy.get_num_dims(x) - 1, keepdims=False) - - -# transpose -@with_unsupported_dtypes({"2.5.0 and below": ("uint8", "int8", "int16")}, "paddle") -@to_ivy_arrays_and_back -def transpose(x, perm, name=None): - return ivy.permute_dims(x, axes=perm) - - -@with_supported_dtypes({"2.4.1 and above": ("int64",)}, "paddle") -@to_ivy_arrays_and_back -def bincount(x, weights=None, minlength=0, name=None): - return ivy.bincount(x, weights=weights, minlength=minlength) - - -@with_supported_dtypes({"2.4.1 and above": ("float64", "float32")}, "paddle") -@to_ivy_arrays_and_back -def dist(x, y, p=2): - ret = ivy.vector_norm(ivy.subtract(x, y), ord=p) - return ivy.reshape(ret, (1,)) - - -@with_supported_dtypes({"2.4.1 and above": ("int64",)}, "paddle") -@to_ivy_arrays_and_back -def linear_algebra_histogram(d, num_bins): - min_value = ivy.min(d) - max_value = ivy.max(d) - bin_width = (max_value - min_value) / num_bins - bin_edges = ivy.arange(min_value, max_value + bin_width, bin_width) - - # Count the number of values in each bin. - bin_counts = ivy.zeros(num_bins) - for value in d: - bin_index = ivy.searchsorted(bin_edges, value) - bin_counts[bin_index] += 1 - return ivy.bin_counts From 6b88b046b54ffbd9b7ac0c36f605644694c17ff0 Mon Sep 17 00:00:00 2001 From: Sanjay <121057369+Sanjay8602@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:27:27 +0530 Subject: [PATCH 14/14] Delete ivy/functional/frontends/paddle/nn/functional/norm.py --- .../frontends/paddle/nn/functional/norm.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 ivy/functional/frontends/paddle/nn/functional/norm.py diff --git a/ivy/functional/frontends/paddle/nn/functional/norm.py b/ivy/functional/frontends/paddle/nn/functional/norm.py deleted file mode 100644 index 8e9decfe31b4b..0000000000000 --- a/ivy/functional/frontends/paddle/nn/functional/norm.py +++ /dev/null @@ -1,16 +0,0 @@ -# local -import ivy -from ivy.func_wrapper import with_supported_dtypes -from ivy.functional.frontends.paddle.func_wrapper import to_ivy_arrays_and_back - - -@to_ivy_arrays_and_back -@with_supported_dtypes({"2.5.0 and below": ("float32", "float64")}, "paddle") -def layer_norm(x, normalized_shape, weight=None, bias=None, epsilon=1e-05, name=None): - return ivy.layer_norm(x, normalized_shape, weight, bias, epsilon) - -@to_ivy_arrays_and_back -@with_supported_dtypes({"2.5.0 and below": ("float32", "float64")}, "paddle") -def batch_norm(x, gamma, beta, moving_mean, moving_var, epsilon=1e-5): - return ivy.batch_norm(x, gamma, beta, moving_mean, moving_var, epsilon) - \ No newline at end of file