Skip to content

Commit

Permalink
feat: add __iand__ for torch frontend Tensor method and the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishticode committed Feb 14, 2024
1 parent f63086d commit de4d23c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit de4d23c

Please sign in to comment.