From de4d23cf4a25be31dc26fb11325447adde9dc47f Mon Sep 17 00:00:00 2001 From: Ishtiaq Hussain <53497039+Ishticode@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:02:04 +0000 Subject: [PATCH] feat: add `__iand__` for torch frontend Tensor method and the test --- 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 39a31acbdf5c..a8645b3cc36b 100644 --- a/ivy/functional/frontends/torch/tensor.py +++ b/ivy/functional/frontends/torch/tensor.py @@ -1402,6 +1402,10 @@ def __invert__(self): def __and__(self, other): return torch_frontend.bitwise_and(self, other) + def __iand__(self, other): + self.ivy_array = self.bitwise_and(other).ivy_array + return self + def __array__(self, dtype=None): if dtype is None: return ivy.to_numpy(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 42516a37a047..d2e44049ba87 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 @@ -777,6 +777,47 @@ def test_torch___gt__( raise +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="torch.tensor", + method_name="__iand__", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=st.one_of(st.just(("bool",)), helpers.get_dtypes("integer")), + num_arrays=2, + min_value=-1e04, + max_value=1e04, + allow_inf=False, + ), + test_inplace=st.just(True), +) +def test_torch___iand__( + 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, + ) + + # __invert__ @handle_frontend_method( class_tree=CLASS_TREE,