Skip to content

Implements logical operators and, or, xor, and not #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dpctl/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
less_equal,
log,
log1p,
logical_and,
logical_not,
logical_or,
logical_xor,
multiply,
not_equal,
proj,
Expand Down Expand Up @@ -211,6 +215,10 @@
"less",
"less_equal",
"log",
"logical_and",
"logical_not",
"logical_or",
"logical_xor",
"log1p",
"proj",
"real",
Expand Down
108 changes: 104 additions & 4 deletions dpctl/tensor/_elementwise_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,116 @@
# FIXME: implement B15

# B16: ==== LOGICAL_AND (x1, x2)
# FIXME: implement B16
_logical_and_docstring_ = """
logical_and(x1, x2, out=None, order='K')

Computes the logical AND for each element `x1_i` of the input array `x1`
with the respective element `x2_i` of the input array `x2`.

Args:
x1 (usm_ndarray):
First input array.
x2 (usm_ndarray):
Second input array.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise logical AND results.
"""
logical_and = BinaryElementwiseFunc(
"logical_and",
ti._logical_and_result_type,
ti._logical_and,
_logical_and_docstring_,
)

# U24: ==== LOGICAL_NOT (x)
# FIXME: implement U24
_logical_not_docstring = """
logical_not(x, out=None, order='K')
Computes the logical NOT for each element `x_i` of input array `x`.
Args:
x (usm_ndarray):
Input array.
out (usm_ndarray):
Output array to populate. Array must have the correct
shape and the expected data type.
order ("C","F","A","K", optional): memory layout of the new
output array, if parameter `out` is `None`.
Default: "K".
Return:
usm_ndarray:
An array containing the element-wise logical NOT results.
"""

logical_not = UnaryElementwiseFunc(
"logical_not",
ti._logical_not_result_type,
ti._logical_not,
_logical_not_docstring,
)

# B17: ==== LOGICAL_OR (x1, x2)
# FIXME: implement B17
_logical_or_docstring_ = """
logical_or(x1, x2, out=None, order='K')

Computes the logical OR for each element `x1_i` of the input array `x1`
with the respective element `x2_i` of the input array `x2`.

Args:
x1 (usm_ndarray):
First input array.
x2 (usm_ndarray):
Second input array.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise logical OR results.
"""
logical_or = BinaryElementwiseFunc(
"logical_or",
ti._logical_or_result_type,
ti._logical_or,
_logical_or_docstring_,
)

# B18: ==== LOGICAL_XOR (x1, x2)
# FIXME: implement B18
_logical_xor_docstring_ = """
logical_xor(x1, x2, out=None, order='K')

Computes the logical XOR for each element `x1_i` of the input array `x1`
with the respective element `x2_i` of the input array `x2`.

Args:
x1 (usm_ndarray):
First input array.
x2 (usm_ndarray):
Second input array.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise logical XOR results.
"""
logical_xor = BinaryElementwiseFunc(
"logical_xor",
ti._logical_xor_result_type,
ti._logical_xor,
_logical_xor_docstring_,
)

# B19: ==== MULTIPLY (x1, x2)
_multiply_docstring_ = """
Expand Down
Loading