From 641663a30c92c770d68ce218db1e7c08bb9b1ec7 Mon Sep 17 00:00:00 2001 From: Mohamed Essam Date: Wed, 30 Aug 2023 19:20:46 +0300 Subject: [PATCH 1/2] add torch tensor maximum instance method with its test --- ivy/functional/frontends/torch/tensor.py | 18 ++++++- .../test_frontends/test_torch/test_tensor.py | 50 +++++++++++++++---- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/ivy/functional/frontends/torch/tensor.py b/ivy/functional/frontends/torch/tensor.py index ab0181c72606f..c963e8df40caf 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -486,8 +486,6 @@ def floor(self, *, out=None): def not_equal(self, other, *, out=None): return torch_frontend.not_equal(self, other, out=out) - ne = not_equal - def equal(self, other): return torch_frontend.equal(self, other) @@ -773,6 +771,22 @@ def long(self, memory_format=None): def max(self, dim=None, keepdim=False): return torch_frontend.max(self, dim=dim, keepdim=keepdim) + @with_unsupported_dtypes( + { + "2.0.1 and below": ( + "complex", + "bfloat16", + "bool", + "uint16", + "uint32", + "uint64", + ) + }, + "torch", + ) + def maximum(self, other, *, out=None): + return torch_frontend.maximum(self, other=other, out=out) + @property def is_quantized(self): return "q" in ivy.dtype(self.ivy_array) diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py index 01f37d3419a29..6a0c7b6b499d3 100644 --- a/ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py +++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py @@ -288,16 +288,6 @@ def _get_dtype_and_multiplicative_matrices(draw): ) -@st.composite -def _get_dtype_and_multiplicative_matrices(draw): - return draw( - st.one_of( - _get_dtype_input_and_matrices(), - _get_dtype_and_3dbatch_matrices(), - ) - ) - - @st.composite def _get_dtype_input_and_vectors(draw, with_input=False, same_size=False): dim_size1 = draw(helpers.ints(min_value=2, max_value=5)) @@ -5269,7 +5259,7 @@ def test_torch_tensor_cos_( init_input_dtypes=input_dtype, backend_to_test=backend_fw, init_all_as_kwargs_np={ - "data": list(x[0]) if type(x[0]) == int else x[0], + "data": list(x[0]) if type(x[0]) is int else x[0], }, method_input_dtypes=input_dtype, method_all_as_kwargs_np={}, @@ -8636,6 +8626,44 @@ def test_torch_tensor_max( ) +# maximum +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="torch.tensor", + method_name="maximum", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("valid"), + num_arrays=2, + ), +) +def test_torch_tensor_maximum( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtype, x = dtype_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtype, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "data": x[0], + }, + method_input_dtypes=input_dtype, + method_all_as_kwargs_np={ + "other": x[1], + }, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + ) + + # mean @handle_frontend_method( class_tree=CLASS_TREE, From 3bfc6b1b8906fedf01d0d9ac87a58a0f40c5eff9 Mon Sep 17 00:00:00 2001 From: Kareem Morsy Date: Thu, 31 Aug 2023 08:03:30 +0000 Subject: [PATCH 2/2] revert: clean up unrelated changed --- ivy/functional/frontends/torch/tensor.py | 2 ++ .../test_frontends/test_torch/test_tensor.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ivy/functional/frontends/torch/tensor.py b/ivy/functional/frontends/torch/tensor.py index c963e8df40caf..165ae0dcb9e7f 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -486,6 +486,8 @@ def floor(self, *, out=None): def not_equal(self, other, *, out=None): return torch_frontend.not_equal(self, other, out=out) + ne = not_equal + def equal(self, other): return torch_frontend.equal(self, other) diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py index 6a0c7b6b499d3..e9c520fe3240c 100644 --- a/ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py +++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py @@ -288,6 +288,16 @@ def _get_dtype_and_multiplicative_matrices(draw): ) +@st.composite +def _get_dtype_and_multiplicative_matrices(draw): + return draw( + st.one_of( + _get_dtype_input_and_matrices(), + _get_dtype_and_3dbatch_matrices(), + ) + ) + + @st.composite def _get_dtype_input_and_vectors(draw, with_input=False, same_size=False): dim_size1 = draw(helpers.ints(min_value=2, max_value=5)) @@ -5259,7 +5269,7 @@ def test_torch_tensor_cos_( init_input_dtypes=input_dtype, backend_to_test=backend_fw, init_all_as_kwargs_np={ - "data": list(x[0]) if type(x[0]) is int else x[0], + "data": list(x[0]) if type(x[0]) == int else x[0], }, method_input_dtypes=input_dtype, method_all_as_kwargs_np={},