Skip to content

Commit

Permalink
Merge pull request #1270 from IntelPython/logical-operators-impl
Browse files Browse the repository at this point in the history
Implements logical operators and, or, xor, and not
  • Loading branch information
ndgrigorian authored Jun 30, 2023
2 parents 0506a49 + 1a0231e commit 7bfc5a0
Show file tree
Hide file tree
Showing 11 changed files with 2,513 additions and 12 deletions.
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

0 comments on commit 7bfc5a0

Please sign in to comment.