Skip to content

Commit 79994c1

Browse files
Merge pull request #1307 from IntelPython/bitwise-elementwise-functions
2 parents 4339cf3 + 9a99003 commit 79994c1

17 files changed

+2769
-38
lines changed

dpctl/tensor/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@
100100
asinh,
101101
atan,
102102
atanh,
103+
bitwise_and,
104+
bitwise_invert,
105+
bitwise_left_shift,
106+
bitwise_or,
107+
bitwise_right_shift,
108+
bitwise_xor,
103109
ceil,
104110
conj,
105111
cos,
@@ -232,6 +238,12 @@
232238
"asinh",
233239
"atan",
234240
"atanh",
241+
"bitwise_and",
242+
"bitwise_invert",
243+
"bitwise_left_shift",
244+
"bitwise_or",
245+
"bitwise_right_shift",
246+
"bitwise_xor",
235247
"ceil",
236248
"conj",
237249
"cos",

dpctl/tensor/_elementwise_funcs.py

Lines changed: 184 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,200 @@
238238
)
239239

240240
# B03: ===== BITWISE_AND (x1, x2)
241-
# FIXME: implemetn B03
241+
_bitwise_and_docstring_ = """
242+
bitwise_and(x1, x2, out=None, order='K')
243+
244+
Computes the bitwise AND of the underlying binary representation of each
245+
element `x1_i` of the input array `x1` with the respective element `x2_i`
246+
of the input array `x2`.
247+
248+
Args:
249+
x1 (usm_ndarray):
250+
First input array, expected to have integer or boolean data type.
251+
x2 (usm_ndarray):
252+
Second input array, also expected to have integer or boolean data
253+
type.
254+
out ({None, usm_ndarray}, optional):
255+
Output array to populate.
256+
Array have the correct shape and the expected data type.
257+
order ("C","F","A","K", optional):
258+
Memory layout of the newly output array, if parameter `out` is `None`.
259+
Default: "K".
260+
Returns:
261+
usm_narray:
262+
An array containing the element-wise results. The data type
263+
of the returned array is determined by the Type Promotion Rules.
264+
"""
265+
266+
bitwise_and = BinaryElementwiseFunc(
267+
"bitwise_and",
268+
ti._bitwise_and_result_type,
269+
ti._bitwise_and,
270+
_bitwise_and_docstring_,
271+
)
242272

243273
# B04: ===== BITWISE_LEFT_SHIFT (x1, x2)
244-
# FIXME: implement B04
274+
_bitwise_left_shift_docstring_ = """
275+
bitwise_left_shift(x1, x2, out=None, order='K')
276+
277+
Shifts the bits of each element `x1_i` of the input array x1 to the left by
278+
appending `x2_i` (i.e., the respective element in the input array `x2`) zeros to
279+
the right of `x1_i`.
280+
281+
Args:
282+
x1 (usm_ndarray):
283+
First input array, expected to have integer data type.
284+
x2 (usm_ndarray):
285+
Second input array, also expected to have integer data type.
286+
Each element must be greater than or equal to 0.
287+
out ({None, usm_ndarray}, optional):
288+
Output array to populate.
289+
Array have the correct shape and the expected data type.
290+
order ("C","F","A","K", optional):
291+
Memory layout of the newly output array, if parameter `out` is `None`.
292+
Default: "K".
293+
Returns:
294+
usm_narray:
295+
An array containing the element-wise results. The data type
296+
of the returned array is determined by the Type Promotion Rules.
297+
"""
298+
299+
bitwise_left_shift = BinaryElementwiseFunc(
300+
"bitwise_left_shift",
301+
ti._bitwise_left_shift_result_type,
302+
ti._bitwise_left_shift,
303+
_bitwise_left_shift_docstring_,
304+
)
305+
245306

246307
# U08: ===== BITWISE_INVERT (x)
247-
# FIXME: implement U08
308+
_bitwise_invert_docstring = """
309+
bitwise_invert(x, out=None, order='K')
310+
311+
Inverts (flips) each bit for each element `x_i` of the input array `x`.
312+
313+
Args:
314+
x (usm_ndarray):
315+
Input array, expected to have integer or boolean data type.
316+
out ({None, usm_ndarray}, optional):
317+
Output array to populate.
318+
Array have the correct shape and the expected data type.
319+
order ("C","F","A","K", optional):
320+
Memory layout of the newly output array, if parameter `out` is `None`.
321+
Default: "K".
322+
Returns:
323+
usm_narray:
324+
An array containing the element-wise results.
325+
The data type of the returned array is same as the data type of the
326+
input array.
327+
"""
328+
329+
bitwise_invert = UnaryElementwiseFunc(
330+
"bitwise_invert",
331+
ti._bitwise_invert_result_type,
332+
ti._bitwise_invert,
333+
_bitwise_invert_docstring,
334+
)
248335

249336
# B05: ===== BITWISE_OR (x1, x2)
250-
# FIXME: implement B05
337+
_bitwise_or_docstring_ = """
338+
bitwise_or(x1, x2, out=None, order='K')
339+
340+
Computes the bitwise OR of the underlying binary representation of each
341+
element `x1_i` of the input array `x1` with the respective element `x2_i`
342+
of the input array `x2`.
343+
344+
Args:
345+
x1 (usm_ndarray):
346+
First input array, expected to have integer or boolean data type.
347+
x2 (usm_ndarray):
348+
Second input array, also expected to have integer or boolean data
349+
type.
350+
out ({None, usm_ndarray}, optional):
351+
Output array to populate.
352+
Array have the correct shape and the expected data type.
353+
order ("C","F","A","K", optional):
354+
Memory layout of the newly output array, if parameter `out` is `None`.
355+
Default: "K".
356+
Returns:
357+
usm_narray:
358+
An array containing the element-wise results. The data type
359+
of the returned array is determined by the Type Promotion Rules.
360+
"""
361+
362+
bitwise_or = BinaryElementwiseFunc(
363+
"bitwise_or",
364+
ti._bitwise_or_result_type,
365+
ti._bitwise_or,
366+
_bitwise_or_docstring_,
367+
)
251368

252369
# B06: ===== BITWISE_RIGHT_SHIFT (x1, x2)
253-
# FIXME: implement B06
370+
_bitwise_right_shift_docstring_ = """
371+
bitwise_right_shift(x1, x2, out=None, order='K')
372+
373+
Shifts the bits of each element `x1_i` of the input array `x1` to the right
374+
according to the respective element `x2_i` of the input array `x2`.
375+
376+
Args:
377+
x1 (usm_ndarray):
378+
First input array, expected to have integer data type.
379+
x2 (usm_ndarray):
380+
Second input array, also expected to have integer data type.
381+
Each element must be greater than or equal to 0.
382+
out ({None, usm_ndarray}, optional):
383+
Output array to populate.
384+
Array have the correct shape and the expected data type.
385+
order ("C","F","A","K", optional):
386+
Memory layout of the newly output array, if parameter `out` is `None`.
387+
Default: "K".
388+
Returns:
389+
usm_narray:
390+
An array containing the element-wise results. The data type
391+
of the returned array is determined by the Type Promotion Rules.
392+
"""
393+
394+
bitwise_right_shift = BinaryElementwiseFunc(
395+
"bitwise_right_shift",
396+
ti._bitwise_right_shift_result_type,
397+
ti._bitwise_right_shift,
398+
_bitwise_right_shift_docstring_,
399+
)
400+
254401

255402
# B07: ===== BITWISE_XOR (x1, x2)
256-
# FIXME: implement B07
403+
_bitwise_xor_docstring_ = """
404+
bitwise_xor(x1, x2, out=None, order='K')
405+
406+
Computes the bitwise XOR of the underlying binary representation of each
407+
element `x1_i` of the input array `x1` with the respective element `x2_i`
408+
of the input array `x2`.
409+
410+
Args:
411+
x1 (usm_ndarray):
412+
First input array, expected to have integer or boolean data type.
413+
x2 (usm_ndarray):
414+
Second input array, also expected to have integer or boolean data
415+
type.
416+
out ({None, usm_ndarray}, optional):
417+
Output array to populate.
418+
Array have the correct shape and the expected data type.
419+
order ("C","F","A","K", optional):
420+
Memory layout of the newly output array, if parameter `out` is `None`.
421+
Default: "K".
422+
Returns:
423+
usm_narray:
424+
An array containing the element-wise results. The data type
425+
of the returned array is determined by the Type Promotion Rules.
426+
"""
427+
428+
bitwise_xor = BinaryElementwiseFunc(
429+
"bitwise_xor",
430+
ti._bitwise_xor_result_type,
431+
ti._bitwise_xor,
432+
_bitwise_xor_docstring_,
433+
)
434+
257435

258436
# U09: ==== CEIL (x)
259437
_ceil_docstring = """

0 commit comments

Comments
 (0)