From aa6dee017d7b6c63efd0b33b59050e98a45a0abc Mon Sep 17 00:00:00 2001 From: Bhushan Srivastava Date: Tue, 15 Aug 2023 23:15:16 +0530 Subject: [PATCH 1/6] add true_divide_ --- ivy/functional/frontends/torch/tensor.py | 4 ++ .../test_frontends/test_torch/test_tensor.py | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/ivy/functional/frontends/torch/tensor.py b/ivy/functional/frontends/torch/tensor.py index 09befc8f34280..56c41f01b4c0a 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -1411,6 +1411,10 @@ def div_(self, other, *, rounding_mode=None): self.ivy_array = self.div(other, rounding_mode=rounding_mode).ivy_array return self + def true_divide_(self, other, *, rounding_mode=None): + self.ivy_array = torch_frontend.div(self, other).ivy_array + return self + def normal_(self, mean=0, std=1, *, generator=None): self.ivy_array = ivy.random_normal( mean=mean, 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 6ba666b2f1ade..01dc872a83319 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 @@ -9098,6 +9098,47 @@ def test_torch_tensor_div_( ) +# true_divide_ +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="torch.tensor", + method_name="true_divide_", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("valid"), + num_arrays=2, + large_abs_safety_factor=2.5, + small_abs_safety_factor=2.5, + safety_factor_scale="log", + ), +) +def test_torch_tensor_true_divide_( + dtype_and_x, + frontend, + frontend_method_data, + init_flags, + method_flags, + on_device, + backend_fw, +): + input_dtype, x = dtype_and_x + assume(not np.any(np.isclose(x[1], 0))) + + 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, + ) + + # normal_ @handle_frontend_method( class_tree=CLASS_TREE, From ad657d3e3c5c1d0f17d4ca9f22f6925f44a8a15e Mon Sep 17 00:00:00 2001 From: Bhushan Srivastava <59949692+he11owthere@users.noreply.github.com> Date: Wed, 16 Aug 2023 02:10:48 +0530 Subject: [PATCH 2/6] Update tensor.py --- ivy/functional/frontends/torch/tensor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ivy/functional/frontends/torch/tensor.py b/ivy/functional/frontends/torch/tensor.py index 56c41f01b4c0a..857acdca23f03 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -1411,6 +1411,7 @@ def div_(self, other, *, rounding_mode=None): self.ivy_array = self.div(other, rounding_mode=rounding_mode).ivy_array return self + @with_supported_dtypes({"2.0.1 and below": ("float16","float32","float64")}, "torch") def true_divide_(self, other, *, rounding_mode=None): self.ivy_array = torch_frontend.div(self, other).ivy_array return self From 4e83a7696ca521f497ef3f73ff7cc7ca49540186 Mon Sep 17 00:00:00 2001 From: Bhushan Srivastava <59949692+he11owthere@users.noreply.github.com> Date: Wed, 16 Aug 2023 02:14:32 +0530 Subject: [PATCH 3/6] adding "bfloat16" dtype since PyTorch supports it --- ivy/functional/frontends/torch/tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy/functional/frontends/torch/tensor.py b/ivy/functional/frontends/torch/tensor.py index 857acdca23f03..22b62ba338f6d 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -1411,7 +1411,7 @@ def div_(self, other, *, rounding_mode=None): self.ivy_array = self.div(other, rounding_mode=rounding_mode).ivy_array return self - @with_supported_dtypes({"2.0.1 and below": ("float16","float32","float64")}, "torch") + @with_supported_dtypes({"2.0.1 and below": ("float16", "float32", "float64", "bfloat16")}, "torch") def true_divide_(self, other, *, rounding_mode=None): self.ivy_array = torch_frontend.div(self, other).ivy_array return self From 5b77dbf8f672cb5f0d129a16bb6c911c5520c677 Mon Sep 17 00:00:00 2001 From: Bhushan Srivastava <59949692+he11owthere@users.noreply.github.com> Date: Wed, 16 Aug 2023 23:15:07 +0530 Subject: [PATCH 4/6] Update tensor.py --- ivy/functional/frontends/torch/tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy/functional/frontends/torch/tensor.py b/ivy/functional/frontends/torch/tensor.py index 22b62ba338f6d..31888c4510181 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -1413,7 +1413,7 @@ def div_(self, other, *, rounding_mode=None): @with_supported_dtypes({"2.0.1 and below": ("float16", "float32", "float64", "bfloat16")}, "torch") def true_divide_(self, other, *, rounding_mode=None): - self.ivy_array = torch_frontend.div(self, other).ivy_array + self.ivy_array = self.div(other).ivy_array return self def normal_(self, mean=0, std=1, *, generator=None): From 8715cf96ab1548d6b9c4f319dada726ba3c8b271 Mon Sep 17 00:00:00 2001 From: Bhushan Srivastava <59949692+he11owthere@users.noreply.github.com> Date: Wed, 16 Aug 2023 23:33:06 +0530 Subject: [PATCH 5/6] Update tensor.py --- ivy/functional/frontends/torch/tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy/functional/frontends/torch/tensor.py b/ivy/functional/frontends/torch/tensor.py index 31888c4510181..e2b6f2b9b44f7 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -1412,7 +1412,7 @@ def div_(self, other, *, rounding_mode=None): return self @with_supported_dtypes({"2.0.1 and below": ("float16", "float32", "float64", "bfloat16")}, "torch") - def true_divide_(self, other, *, rounding_mode=None): + def true_divide_(self, other): self.ivy_array = self.div(other).ivy_array return self From 2a8b38d0886099c10cd6c1adbe6ada877f6c778e Mon Sep 17 00:00:00 2001 From: Bhushan Srivastava <59949692+he11owthere@users.noreply.github.com> Date: Thu, 17 Aug 2023 09:02:12 +0530 Subject: [PATCH 6/6] Update tensor.py --- ivy/functional/frontends/torch/tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy/functional/frontends/torch/tensor.py b/ivy/functional/frontends/torch/tensor.py index e2b6f2b9b44f7..d0e42fd3e898f 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -1413,7 +1413,7 @@ def div_(self, other, *, rounding_mode=None): @with_supported_dtypes({"2.0.1 and below": ("float16", "float32", "float64", "bfloat16")}, "torch") def true_divide_(self, other): - self.ivy_array = self.div(other).ivy_array + self.ivy_array = self.div(other, rounding_mode=None).ivy_array return self def normal_(self, mean=0, std=1, *, generator=None):