Skip to content

Commit 7bfc5a0

Browse files
authored
Merge pull request #1270 from IntelPython/logical-operators-impl
Implements logical operators and, or, xor, and not
2 parents 0506a49 + 1a0231e commit 7bfc5a0

File tree

11 files changed

+2513
-12
lines changed

11 files changed

+2513
-12
lines changed

dpctl/tensor/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
less_equal,
112112
log,
113113
log1p,
114+
logical_and,
115+
logical_not,
116+
logical_or,
117+
logical_xor,
114118
multiply,
115119
not_equal,
116120
proj,
@@ -211,6 +215,10 @@
211215
"less",
212216
"less_equal",
213217
"log",
218+
"logical_and",
219+
"logical_not",
220+
"logical_or",
221+
"logical_xor",
214222
"log1p",
215223
"proj",
216224
"real",

dpctl/tensor/_elementwise_funcs.py

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,116 @@
572572
# FIXME: implement B15
573573

574574
# B16: ==== LOGICAL_AND (x1, x2)
575-
# FIXME: implement B16
575+
_logical_and_docstring_ = """
576+
logical_and(x1, x2, out=None, order='K')
577+
578+
Computes the logical AND for each element `x1_i` of the input array `x1`
579+
with the respective element `x2_i` of the input array `x2`.
580+
581+
Args:
582+
x1 (usm_ndarray):
583+
First input array.
584+
x2 (usm_ndarray):
585+
Second input array.
586+
out ({None, usm_ndarray}, optional):
587+
Output array to populate.
588+
Array have the correct shape and the expected data type.
589+
order ("C","F","A","K", optional):
590+
Memory layout of the newly output array, if parameter `out` is `None`.
591+
Default: "K".
592+
Returns:
593+
usm_narray:
594+
An array containing the element-wise logical AND results.
595+
"""
596+
logical_and = BinaryElementwiseFunc(
597+
"logical_and",
598+
ti._logical_and_result_type,
599+
ti._logical_and,
600+
_logical_and_docstring_,
601+
)
576602

577603
# U24: ==== LOGICAL_NOT (x)
578-
# FIXME: implement U24
604+
_logical_not_docstring = """
605+
logical_not(x, out=None, order='K')
606+
Computes the logical NOT for each element `x_i` of input array `x`.
607+
Args:
608+
x (usm_ndarray):
609+
Input array.
610+
out (usm_ndarray):
611+
Output array to populate. Array must have the correct
612+
shape and the expected data type.
613+
order ("C","F","A","K", optional): memory layout of the new
614+
output array, if parameter `out` is `None`.
615+
Default: "K".
616+
Return:
617+
usm_ndarray:
618+
An array containing the element-wise logical NOT results.
619+
"""
620+
621+
logical_not = UnaryElementwiseFunc(
622+
"logical_not",
623+
ti._logical_not_result_type,
624+
ti._logical_not,
625+
_logical_not_docstring,
626+
)
579627

580628
# B17: ==== LOGICAL_OR (x1, x2)
581-
# FIXME: implement B17
629+
_logical_or_docstring_ = """
630+
logical_or(x1, x2, out=None, order='K')
631+
632+
Computes the logical OR for each element `x1_i` of the input array `x1`
633+
with the respective element `x2_i` of the input array `x2`.
634+
635+
Args:
636+
x1 (usm_ndarray):
637+
First input array.
638+
x2 (usm_ndarray):
639+
Second input array.
640+
out ({None, usm_ndarray}, optional):
641+
Output array to populate.
642+
Array have the correct shape and the expected data type.
643+
order ("C","F","A","K", optional):
644+
Memory layout of the newly output array, if parameter `out` is `None`.
645+
Default: "K".
646+
Returns:
647+
usm_narray:
648+
An array containing the element-wise logical OR results.
649+
"""
650+
logical_or = BinaryElementwiseFunc(
651+
"logical_or",
652+
ti._logical_or_result_type,
653+
ti._logical_or,
654+
_logical_or_docstring_,
655+
)
582656

583657
# B18: ==== LOGICAL_XOR (x1, x2)
584-
# FIXME: implement B18
658+
_logical_xor_docstring_ = """
659+
logical_xor(x1, x2, out=None, order='K')
660+
661+
Computes the logical XOR for each element `x1_i` of the input array `x1`
662+
with the respective element `x2_i` of the input array `x2`.
663+
664+
Args:
665+
x1 (usm_ndarray):
666+
First input array.
667+
x2 (usm_ndarray):
668+
Second input array.
669+
out ({None, usm_ndarray}, optional):
670+
Output array to populate.
671+
Array have the correct shape and the expected data type.
672+
order ("C","F","A","K", optional):
673+
Memory layout of the newly output array, if parameter `out` is `None`.
674+
Default: "K".
675+
Returns:
676+
usm_narray:
677+
An array containing the element-wise logical XOR results.
678+
"""
679+
logical_xor = BinaryElementwiseFunc(
680+
"logical_xor",
681+
ti._logical_xor_result_type,
682+
ti._logical_xor,
683+
_logical_xor_docstring_,
684+
)
585685

586686
# B19: ==== MULTIPLY (x1, x2)
587687
_multiply_docstring_ = """

0 commit comments

Comments
 (0)