Skip to content

Commit

Permalink
Implemented torch.Tensor.__and__
Browse files Browse the repository at this point in the history
  • Loading branch information
fspyridakos committed Mar 22, 2023
1 parent bc95858 commit 6187f60
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,9 @@ def __or__(self, other):
def __invert__(self):
return torch_frontend.bitwise_not(self._ivy_array)

def __and__(self, other):
return torch_frontend.bitwise_and(self, other)

# Method aliases
absolute, absolute_ = abs, abs_
ndimension = dim
39 changes: 39 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 @@ -5695,3 +5695,42 @@ def test_torch_instance_bitwise_and_(
frontend=frontend,
on_device=on_device,
)


# __and__
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="torch.tensor",
method_name="__and__",
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,
),
)
def test_torch_special_and(
dtype_and_x,
frontend_method_data,
init_flags,
method_flags,
frontend,
on_device,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
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,
)

0 comments on commit 6187f60

Please sign in to comment.