Skip to content

Commit 47e61de

Browse files
committed
Implements logical operators and, or, not, and xor
1 parent 0506a49 commit 47e61de

File tree

7 files changed

+1459
-12
lines changed

7 files changed

+1459
-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: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,119 @@
572572
# FIXME: implement B15
573573

574574
# B16: ==== LOGICAL_AND (x1, x2)
575-
# FIXME: implement B16
575+
_logical_and_docstring_ = """
576+
multiply(x1, x2, out=None, order='K')
577+
578+
Calculates the product 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, expected to have numeric data type.
584+
x2 (usm_ndarray):
585+
Second input array, also expected to have numeric data type.
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 products. The data type of
595+
the returned array is determined by the Type Promotion Rules.
596+
"""
597+
logical_and = BinaryElementwiseFunc(
598+
"logical_and",
599+
ti._logical_and_result_type,
600+
ti._logical_and,
601+
_logical_and_docstring_,
602+
)
576603

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

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

583659
# B18: ==== LOGICAL_XOR (x1, x2)
584-
# FIXME: implement B18
660+
_logical_xor_docstring_ = """
661+
multiply(x1, x2, out=None, order='K')
662+
663+
Calculates the product for each element `x1_i` of the input array `x1`
664+
with the respective element `x2_i` of the input array `x2`.
665+
666+
Args:
667+
x1 (usm_ndarray):
668+
First input array, expected to have numeric data type.
669+
x2 (usm_ndarray):
670+
Second input array, also expected to have numeric data type.
671+
out ({None, usm_ndarray}, optional):
672+
Output array to populate.
673+
Array have the correct shape and the expected data type.
674+
order ("C","F","A","K", optional):
675+
Memory layout of the newly output array, if parameter `out` is `None`.
676+
Default: "K".
677+
Returns:
678+
usm_narray:
679+
An array containing the element-wise products. The data type of
680+
the returned array is determined by the Type Promotion Rules.
681+
"""
682+
logical_xor = BinaryElementwiseFunc(
683+
"logical_xor",
684+
ti._logical_xor_result_type,
685+
ti._logical_xor,
686+
_logical_xor_docstring_,
687+
)
585688

586689
# B19: ==== MULTIPLY (x1, x2)
587690
_multiply_docstring_ = """

0 commit comments

Comments
 (0)