Skip to content

Commit 1fb889d

Browse files
Move all binary logical_ functions and reuse them
1 parent 28288ae commit 1fb889d

14 files changed

Lines changed: 1563 additions & 15 deletions

File tree

dpctl_ext/tensor/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ set(_elementwise_sources
114114
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/log2.cpp
115115
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/log10.cpp
116116
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/logaddexp.cpp
117-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/logical_and.cpp
117+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/logical_and.cpp
118118
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/logical_not.cpp
119-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/logical_or.cpp
120-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/logical_xor.cpp
119+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/logical_or.cpp
120+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/logical_xor.cpp
121121
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/maximum.cpp
122122
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/minimum.cpp
123123
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/multiply.cpp

dpctl_ext/tensor/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@
131131
log1p,
132132
log2,
133133
log10,
134+
logical_and,
134135
logical_not,
136+
logical_or,
137+
logical_xor,
135138
negative,
136139
positive,
137140
proj,
@@ -244,7 +247,10 @@
244247
"less_equal",
245248
"linspace",
246249
"log",
250+
"logical_and",
247251
"logical_not",
252+
"logical_or",
253+
"logical_xor",
248254
"logsumexp",
249255
"log1p",
250256
"log2",

dpctl_ext/tensor/_elementwise_funcs.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,102 @@
12431243
)
12441244
del _logaddexp_docstring_
12451245

1246+
# B16: ==== LOGICAL_AND (x1, x2)
1247+
_logical_and_docstring_ = r"""
1248+
logical_and(x1, x2, /, \*, out=None, order='K')
1249+
1250+
Computes the logical AND for each element `x1_i` of the input array `x1` with
1251+
the respective element `x2_i` of the input array `x2`.
1252+
1253+
Args:
1254+
x1 (usm_ndarray):
1255+
First input array. May have any data type.
1256+
x2 (usm_ndarray):
1257+
Second input array. May have any data type.
1258+
out (Union[usm_ndarray, None], optional):
1259+
Output array to populate.
1260+
Array must have the correct shape and the expected data type.
1261+
order ("C","F","A","K", optional):
1262+
Memory layout of the new output array, if parameter
1263+
`out` is ``None``.
1264+
Default: "K".
1265+
1266+
Returns:
1267+
usm_ndarray:
1268+
An array containing the element-wise logical AND results.
1269+
"""
1270+
logical_and = BinaryElementwiseFunc(
1271+
"logical_and",
1272+
ti._logical_and_result_type,
1273+
ti._logical_and,
1274+
_logical_and_docstring_,
1275+
)
1276+
del _logical_and_docstring_
1277+
1278+
# B17: ==== LOGICAL_OR (x1, x2)
1279+
_logical_or_docstring_ = r"""
1280+
logical_or(x1, x2, /, \*, out=None, order='K')
1281+
1282+
Computes the logical OR for each element `x1_i` of the input array `x1`
1283+
with the respective element `x2_i` of the input array `x2`.
1284+
1285+
Args:
1286+
x1 (usm_ndarray):
1287+
First input array. May have any data type.
1288+
x2 (usm_ndarray):
1289+
Second input array. May have any data type.
1290+
out (Union[usm_ndarray, None], optional):
1291+
Output array to populate.
1292+
Array must have the correct shape and the expected data type.
1293+
order ("C","F","A","K", optional):
1294+
Memory layout of the new output array, if parameter
1295+
`out` is ``None``.
1296+
Default: "K".
1297+
1298+
Returns:
1299+
usm_ndarray:
1300+
An array containing the element-wise logical OR results.
1301+
"""
1302+
logical_or = BinaryElementwiseFunc(
1303+
"logical_or",
1304+
ti._logical_or_result_type,
1305+
ti._logical_or,
1306+
_logical_or_docstring_,
1307+
)
1308+
del _logical_or_docstring_
1309+
1310+
# B18: ==== LOGICAL_XOR (x1, x2)
1311+
_logical_xor_docstring_ = r"""
1312+
logical_xor(x1, x2, /, \*, out=None, order='K')
1313+
1314+
Computes the logical XOR for each element `x1_i` of the input array `x1`
1315+
with the respective element `x2_i` of the input array `x2`.
1316+
1317+
Args:
1318+
x1 (usm_ndarray):
1319+
First input array. May have any data type.
1320+
x2 (usm_ndarray):
1321+
Second input array. May have any data type.
1322+
out (Union[usm_ndarray, None], optional):
1323+
Output array to populate.
1324+
Array must have the correct shape and the expected data type.
1325+
order ("C","F","A","K", optional):
1326+
Memory layout of the new output array, if parameter
1327+
`out` is ``None``.
1328+
Default: "K".
1329+
1330+
Returns:
1331+
usm_ndarray:
1332+
An array containing the element-wise logical XOR results.
1333+
"""
1334+
logical_xor = BinaryElementwiseFunc(
1335+
"logical_xor",
1336+
ti._logical_xor_result_type,
1337+
ti._logical_xor,
1338+
_logical_xor_docstring_,
1339+
)
1340+
del _logical_xor_docstring_
1341+
12461342
# U24: ==== LOGICAL_NOT (x)
12471343
_logical_not_docstring = r"""
12481344
logical_not(x, /, \*, out=None, order='K')

0 commit comments

Comments
 (0)