Skip to content

Commit d8aab36

Browse files
Move ti.add() and reuse them
1 parent bdf3b18 commit d8aab36

File tree

8 files changed

+1019
-6
lines changed

8 files changed

+1019
-6
lines changed

dpctl_ext/tensor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ set(_elementwise_sources
7575
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/abs.cpp
7676
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/acos.cpp
7777
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/acosh.cpp
78-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/add.cpp
78+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/add.cpp
7979
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/angle.cpp
8080
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/asin.cpp
8181
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/asinh.cpp

dpctl_ext/tensor/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
abs,
9494
acos,
9595
acosh,
96+
add,
9697
angle,
9798
asin,
9899
asinh,
@@ -160,6 +161,7 @@
160161
"abs",
161162
"acos",
162163
"acosh",
164+
"add",
163165
"all",
164166
"angle",
165167
"any",

dpctl_ext/tensor/_elementwise_funcs.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# when dpnp fully migrates dpctl/tensor
3131
import dpctl_ext.tensor._tensor_elementwise_impl as ti
3232

33-
from ._elementwise_common import UnaryElementwiseFunc
33+
from ._elementwise_common import BinaryElementwiseFunc, UnaryElementwiseFunc
3434
from ._type_utils import (
3535
_acceptance_fn_negative,
3636
_acceptance_fn_reciprocal,
@@ -124,6 +124,41 @@
124124
)
125125
del _acosh_docstring
126126

127+
# B01: ===== ADD (x1, x2)
128+
129+
_add_docstring_ = r"""
130+
add(x1, x2, /, \*, out=None, order='K')
131+
132+
Calculates the sum for each element `x1_i` of the input array `x1` with
133+
the respective element `x2_i` of the input array `x2`.
134+
135+
Args:
136+
x1 (usm_ndarray):
137+
First input array. May have any data type.
138+
x2 (usm_ndarray):
139+
Second input array. May have any data type.
140+
out (Union[usm_ndarray, None], optional):
141+
Output array to populate.
142+
Array must have the correct shape and the expected data type.
143+
order ("C","F","A","K", optional):
144+
Memory layout of the new output array, if parameter
145+
`out` is ``None``.
146+
Default: "K".
147+
148+
Returns:
149+
usm_ndarray:
150+
An array containing the element-wise sums. The data type of the
151+
returned array is determined by the Type Promotion Rules.
152+
"""
153+
add = BinaryElementwiseFunc(
154+
"add",
155+
ti._add_result_type,
156+
ti._add,
157+
_add_docstring_,
158+
binary_inplace_fn=ti._add_inplace,
159+
)
160+
del _add_docstring_
161+
127162
# U04: ===== ASIN (x)
128163
_asin_docstring = r"""
129164
asin(x, /, \*, out=None, order='K')

0 commit comments

Comments
 (0)