Skip to content

Commit e24b129

Browse files
Move ti.bitwise_invert()/ceil()/conj() and reust them
1 parent e54114f commit e24b129

File tree

4 files changed

+103
-6
lines changed

4 files changed

+103
-6
lines changed

dpctl_ext/tensor/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
asinh,
9393
atan,
9494
atanh,
95+
bitwise_invert,
96+
ceil,
97+
conj,
9598
)
9699
from ._reduction import (
97100
argmax,
@@ -133,10 +136,13 @@
133136
"astype",
134137
"atan",
135138
"atanh",
139+
"bitwise_invert",
136140
"broadcast_arrays",
137141
"broadcast_to",
138142
"can_cast",
143+
"ceil",
139144
"concat",
145+
"conj",
140146
"copy",
141147
"count_nonzero",
142148
"clip",

dpctl_ext/tensor/_elementwise_funcs.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,94 @@
236236
)
237237
del _atanh_docstring
238238

239+
# U08: ===== BITWISE_INVERT (x)
240+
_bitwise_invert_docstring = r"""
241+
bitwise_invert(x, /, \*, out=None, order='K')
242+
243+
Inverts (flips) each bit for each element `x_i` of the input array `x`.
244+
245+
Args:
246+
x (usm_ndarray):
247+
Input array, expected to have integer or boolean data type.
248+
out (Union[usm_ndarray, None], optional):
249+
Output array to populate.
250+
Array must have the correct shape and the expected data type.
251+
order ("C","F","A","K", optional):
252+
Memory layout of the new output array, if parameter
253+
`out` is ``None``.
254+
Default: "K".
255+
256+
Returns:
257+
usm_ndarray:
258+
An array containing the element-wise results.
259+
The data type of the returned array is same as the data type of the
260+
input array.
261+
"""
262+
263+
bitwise_invert = UnaryElementwiseFunc(
264+
"bitwise_invert",
265+
ti._bitwise_invert_result_type,
266+
ti._bitwise_invert,
267+
_bitwise_invert_docstring,
268+
)
269+
del _bitwise_invert_docstring
270+
271+
# U09: ==== CEIL (x)
272+
_ceil_docstring = r"""
273+
ceil(x, /, \*, out=None, order='K')
274+
275+
Returns the ceiling for each element `x_i` for input array `x`.
276+
277+
The ceil of `x_i` is the smallest integer `n`, such that `n >= x_i`.
278+
279+
Args:
280+
x (usm_ndarray):
281+
Input array, expected to have a boolean or real-valued data type.
282+
out (Union[usm_ndarray, None], optional):
283+
Output array to populate.
284+
Array must have the correct shape and the expected data type.
285+
order ("C","F","A","K", optional):
286+
Memory layout of the new output array, if parameter
287+
`out` is ``None``.
288+
Default: "K".
289+
290+
Returns:
291+
usm_ndarray:
292+
An array containing the element-wise ceiling.
293+
"""
294+
295+
ceil = UnaryElementwiseFunc(
296+
"ceil", ti._ceil_result_type, ti._ceil, _ceil_docstring
297+
)
298+
del _ceil_docstring
299+
300+
# U10: ==== CONJ (x)
301+
_conj_docstring = r"""
302+
conj(x, /, \*, out=None, order='K')
303+
304+
Computes conjugate of each element `x_i` for input array `x`.
305+
306+
Args:
307+
x (usm_ndarray):
308+
Input array. May have any data type.
309+
out (Union[usm_ndarray, None], optional):
310+
Output array to populate.
311+
Array must have the correct shape and the expected data type.
312+
order ("C","F","A","K", optional):
313+
Memory layout of the new output array, if parameter
314+
`out` is ``None``.
315+
Default: "K".
316+
317+
Returns:
318+
usm_ndarray:
319+
An array containing the element-wise conjugate values.
320+
"""
321+
322+
conj = UnaryElementwiseFunc(
323+
"conj", ti._conj_result_type, ti._conj, _conj_docstring
324+
)
325+
del _conj_docstring
326+
239327
# U43: ==== ANGLE (x)
240328
_angle_docstring = r"""
241329
angle(x, /, \*, out=None, order='K')

dpnp/dpnp_iface_bitwise.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
import dpctl.tensor._tensor_elementwise_impl as ti
4747
import numpy
4848

49+
# TODO: revert to `import dpctl.tensor...`
50+
# when dpnp fully migrates dpctl/tensor
51+
import dpctl_ext.tensor._tensor_elementwise_impl as ti_ext
4952
import dpnp.backend.extensions.ufunc._ufunc_impl as ufi
5053
from dpnp.dpnp_algo.dpnp_elementwise_common import DPNPBinaryFunc, DPNPUnaryFunc
5154

@@ -514,8 +517,8 @@ def binary_repr(num, width=None):
514517

515518
invert = DPNPUnaryFunc(
516519
"invert",
517-
ti._bitwise_invert_result_type,
518-
ti._bitwise_invert,
520+
ti_ext._bitwise_invert_result_type,
521+
ti_ext._bitwise_invert,
519522
_INVERT_DOCSTRING,
520523
)
521524

dpnp/dpnp_iface_mathematical.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@ def around(x, /, decimals=0, out=None):
647647

648648
ceil = DPNPUnaryFunc(
649649
"ceil",
650-
ti._ceil_result_type,
651-
ti._ceil,
650+
ti_ext._ceil_result_type,
651+
ti_ext._ceil,
652652
_CEIL_DOCSTRING,
653653
mkl_fn_to_call="_mkl_ceil_to_call",
654654
mkl_impl_fn="_ceil",
@@ -782,8 +782,8 @@ def clip(a, /, min=None, max=None, *, out=None, order="K", **kwargs):
782782

783783
conj = DPNPUnaryFunc(
784784
"conj",
785-
ti._conj_result_type,
786-
ti._conj,
785+
ti_ext._conj_result_type,
786+
ti_ext._conj,
787787
_CONJ_DOCSTRING,
788788
mkl_fn_to_call="_mkl_conj_to_call",
789789
mkl_impl_fn="_conj",

0 commit comments

Comments
 (0)