Skip to content

Commit 9380514

Browse files
authored
Merge pull request #1234 from IntelPython/elementwise-hyper-and-trig-funcs
impl elementwise hyperbolic and trigonometric functions
2 parents 616c21e + 2f5a453 commit 9380514

File tree

19 files changed

+4141
-284
lines changed

19 files changed

+4141
-284
lines changed

.github/workflows/conda-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ jobs:
168168
run: |
169169
. $CONDA/etc/profile.d/conda.sh
170170
conda activate test_dpctl
171-
gdb --batch -ex r -ex 'info sharedlibrary' -ex 'set print elements 1000' -ex bt --args ${CONDA_PREFIX}/bin/python -m pytest -q -ra --disable-warnings --pyargs dpctl.tests.test_tensor_elementwise::test_cos_order -vv || true
171+
gdb --batch -ex r -ex 'info sharedlibrary' -ex 'set print elements 1000' -ex bt --args ${CONDA_PREFIX}/bin/python -m pytest -q -ra --disable-warnings --pyargs dpctl.tests.elementwise.test_trigonometric::test_trig_order -vv || true
172172
- name: Run tests
173173
env:
174174
SYCL_QUEUE_THREAD_POOL_SIZE: 6

dpctl/tensor/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,17 @@
9393
from ._constants import e, inf, nan, newaxis, pi
9494
from ._elementwise_funcs import (
9595
abs,
96+
acos,
97+
acosh,
9698
add,
99+
asin,
100+
asinh,
101+
atan,
102+
atanh,
97103
ceil,
98104
conj,
99105
cos,
106+
cosh,
100107
divide,
101108
equal,
102109
exp,
@@ -129,9 +136,12 @@
129136
proj,
130137
real,
131138
sin,
139+
sinh,
132140
sqrt,
133141
square,
134142
subtract,
143+
tan,
144+
tanh,
135145
trunc,
136146
)
137147
from ._reduction import sum
@@ -212,10 +222,17 @@
212222
"nan",
213223
"inf",
214224
"abs",
225+
"acos",
226+
"acosh",
215227
"add",
228+
"asin",
229+
"asinh",
230+
"atan",
231+
"atanh",
216232
"ceil",
217233
"conj",
218234
"cos",
235+
"cosh",
219236
"divide",
220237
"equal",
221238
"exp",
@@ -248,9 +265,14 @@
248265
"proj",
249266
"real",
250267
"sin",
268+
"sinh",
251269
"sqrt",
252270
"square",
253271
"subtract",
272+
"not_equal",
273+
"floor_divide",
254274
"sum",
275+
"tan",
276+
"tanh",
255277
"trunc",
256278
]

dpctl/tensor/_elementwise_funcs.py

Lines changed: 234 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,56 @@
4747
abs = UnaryElementwiseFunc("abs", ti._abs_result_type, ti._abs, _abs_docstring_)
4848

4949
# U02: ==== ACOS (x)
50-
# FIXME: implement U02
50+
_acos_docstring = """
51+
acos(x, out=None, order='K')
52+
53+
Computes inverse cosine for each element `x_i` for input array `x`.
54+
55+
Args:
56+
x (usm_ndarray):
57+
Input array, expected to have numeric data type.
58+
out ({None, usm_ndarray}, optional):
59+
Output array to populate.
60+
Array have the correct shape and the expected data type.
61+
order ("C","F","A","K", optional):
62+
Memory layout of the newly output array, if parameter `out` is `None`.
63+
Default: "K".
64+
Returns:
65+
usm_narray:
66+
An array containing the element-wise inverse cosine, in radians
67+
and in the closed interval `[-pi/2, pi/2]`. The data type
68+
of the returned array is determined by the Type Promotion Rules.
69+
"""
70+
71+
acos = UnaryElementwiseFunc(
72+
"acos", ti._acos_result_type, ti._acos, _acos_docstring
73+
)
5174

5275
# U03: ===== ACOSH (x)
53-
# FIXME: implement U03
76+
_acosh_docstring = """
77+
acosh(x, out=None, order='K')
78+
79+
Computes inverse hyperbolic cosine for each element `x_i` for input array `x`.
80+
81+
Args:
82+
x (usm_ndarray):
83+
Input array, expected to have numeric data type.
84+
out ({None, usm_ndarray}, optional):
85+
Output array to populate.
86+
Array have the correct shape and the expected data type.
87+
order ("C","F","A","K", optional):
88+
Memory layout of the newly output array, if parameter `out` is `None`.
89+
Default: "K".
90+
Returns:
91+
usm_narray:
92+
An array containing the element-wise inverse hyperbolic cosine.
93+
The data type of the returned array is determined by
94+
the Type Promotion Rules.
95+
"""
96+
97+
acosh = UnaryElementwiseFunc(
98+
"acosh", ti._acosh_result_type, ti._acosh, _acosh_docstring
99+
)
54100

55101
# B01: ===== ADD (x1, x2)
56102

@@ -85,19 +131,111 @@
85131
)
86132

87133
# U04: ===== ASIN (x)
88-
# FIXME: implement U04
134+
_asin_docstring = """
135+
asin(x, out=None, order='K')
136+
137+
Computes inverse sine for each element `x_i` for input array `x`.
138+
139+
Args:
140+
x (usm_ndarray):
141+
Input array, expected to have numeric data type.
142+
out ({None, usm_ndarray}, optional):
143+
Output array to populate.
144+
Array have the correct shape and the expected data type.
145+
order ("C","F","A","K", optional):
146+
Memory layout of the newly output array, if parameter `out` is `None`.
147+
Default: "K".
148+
Returns:
149+
usm_narray:
150+
An array containing the element-wise inverse sine, in radians
151+
and in the closed interval `[-pi/2, pi/2]`. The data type
152+
of the returned array is determined by the Type Promotion Rules.
153+
"""
154+
155+
asin = UnaryElementwiseFunc(
156+
"asin", ti._asin_result_type, ti._asin, _asin_docstring
157+
)
89158

90159
# U05: ===== ASINH (x)
91-
# FIXME: implement U05
160+
_asinh_docstring = """
161+
asinh(x, out=None, order='K')
162+
163+
Computes inverse hyperbolic sine for each element `x_i` for input array `x`.
164+
165+
Args:
166+
x (usm_ndarray):
167+
Input array, expected to have numeric data type.
168+
out ({None, usm_ndarray}, optional):
169+
Output array to populate.
170+
Array have the correct shape and the expected data type.
171+
order ("C","F","A","K", optional):
172+
Memory layout of the newly output array, if parameter `out` is `None`.
173+
Default: "K".
174+
Returns:
175+
usm_narray:
176+
An array containing the element-wise inverse hyperbolic sine.
177+
The data type of the returned array is determined by
178+
the Type Promotion Rules.
179+
"""
180+
181+
asinh = UnaryElementwiseFunc(
182+
"asinh", ti._asinh_result_type, ti._asinh, _asinh_docstring
183+
)
92184

93185
# U06: ===== ATAN (x)
94-
# FIXME: implement U06
186+
_atan_docstring = """
187+
atan(x, out=None, order='K')
188+
189+
Computes inverse tangent for each element `x_i` for input array `x`.
190+
191+
Args:
192+
x (usm_ndarray):
193+
Input array, expected to have numeric data type.
194+
out ({None, usm_ndarray}, optional):
195+
Output array to populate.
196+
Array have the correct shape and the expected data type.
197+
order ("C","F","A","K", optional):
198+
Memory layout of the newly output array, if parameter `out` is `None`.
199+
Default: "K".
200+
Returns:
201+
usm_narray:
202+
An array containing the element-wise inverse tangent, in radians
203+
and in the closed interval `[-pi/2, pi/2]`. The data type
204+
of the returned array is determined by the Type Promotion Rules.
205+
"""
206+
207+
atan = UnaryElementwiseFunc(
208+
"atan", ti._atan_result_type, ti._atan, _atan_docstring
209+
)
95210

96211
# B02: ===== ATAN2 (x1, x2)
97212
# FIXME: implemetn B02
98213

99214
# U07: ===== ATANH (x)
100-
# FIXME: implemetn U07
215+
_atanh_docstring = """
216+
atanh(x, out=None, order='K')
217+
218+
Computes hyperbolic inverse tangent for each element `x_i` for input array `x`.
219+
220+
Args:
221+
x (usm_ndarray):
222+
Input array, expected to have numeric data type.
223+
out ({None, usm_ndarray}, optional):
224+
Output array to populate.
225+
Array have the correct shape and the expected data type.
226+
order ("C","F","A","K", optional):
227+
Memory layout of the newly output array, if parameter `out` is `None`.
228+
Default: "K".
229+
Returns:
230+
usm_narray:
231+
An array containing the element-wise hyperbolic inverse tangent.
232+
The data type of the returned array is determined by
233+
the Type Promotion Rules.
234+
"""
235+
236+
atanh = UnaryElementwiseFunc(
237+
"atanh", ti._atanh_result_type, ti._atanh, _atanh_docstring
238+
)
101239

102240
# B03: ===== BITWISE_AND (x1, x2)
103241
# FIXME: implemetn B03
@@ -192,7 +330,29 @@
192330
cos = UnaryElementwiseFunc("cos", ti._cos_result_type, ti._cos, _cos_docstring)
193331

194332
# U12: ==== COSH (x)
195-
# FIXME: implement U12
333+
_cosh_docstring = """
334+
cosh(x, out=None, order='K')
335+
336+
Computes hyperbolic cosine for each element `x_i` for input array `x`.
337+
338+
Args:
339+
x (usm_ndarray):
340+
Input array, expected to have numeric data type.
341+
out ({None, usm_ndarray}, optional):
342+
Output array to populate.
343+
Array have the correct shape and the expected data type.
344+
order ("C","F","A","K", optional):
345+
Memory layout of the newly output array, if parameter `out` is `None`.
346+
Default: "K".
347+
Returns:
348+
usm_narray:
349+
An array containing the element-wise hyperbolic cosine. The data type
350+
of the returned array is determined by the Type Promotion Rules.
351+
"""
352+
353+
cosh = UnaryElementwiseFunc(
354+
"cosh", ti._cosh_result_type, ti._cosh, _cosh_docstring
355+
)
196356

197357
# B08: ==== DIVIDE (x1, x2)
198358
_divide_docstring_ = """
@@ -1021,7 +1181,29 @@
10211181
sin = UnaryElementwiseFunc("sin", ti._sin_result_type, ti._sin, _sin_docstring)
10221182

10231183
# U31: ==== SINH (x)
1024-
# FIXME: implement U31
1184+
_sinh_docstring = """
1185+
sinh(x, out=None, order='K')
1186+
1187+
Computes hyperbolic sine for each element `x_i` for input array `x`.
1188+
1189+
Args:
1190+
x (usm_ndarray):
1191+
Input array, expected to have numeric data type.
1192+
out ({None, usm_ndarray}, optional):
1193+
Output array to populate.
1194+
Array have the correct shape and the expected data type.
1195+
order ("C","F","A","K", optional):
1196+
Memory layout of the newly output array, if parameter `out` is `None`.
1197+
Default: "K".
1198+
Returns:
1199+
usm_narray:
1200+
An array containing the element-wise hyperbolic sine. The data type
1201+
of the returned array is determined by the Type Promotion Rules.
1202+
"""
1203+
1204+
sinh = UnaryElementwiseFunc(
1205+
"sinh", ti._sinh_result_type, ti._sinh, _sinh_docstring
1206+
)
10251207

10261208
# U32: ==== SQUARE (x)
10271209
_square_docstring_ = """
@@ -1107,10 +1289,52 @@
11071289

11081290

11091291
# U34: ==== TAN (x)
1110-
# FIXME: implement U34
1292+
_tan_docstring = """
1293+
tan(x, out=None, order='K')
1294+
1295+
Computes tangent for each element `x_i` for input array `x`.
1296+
1297+
Args:
1298+
x (usm_ndarray):
1299+
Input array, expected to have numeric data type.
1300+
out ({None, usm_ndarray}, optional):
1301+
Output array to populate.
1302+
Array have the correct shape and the expected data type.
1303+
order ("C","F","A","K", optional):
1304+
Memory layout of the newly output array, if parameter `out` is `None`.
1305+
Default: "K".
1306+
Returns:
1307+
usm_narray:
1308+
An array containing the element-wise tangent. The data type
1309+
of the returned array is determined by the Type Promotion Rules.
1310+
"""
1311+
1312+
tan = UnaryElementwiseFunc("tan", ti._tan_result_type, ti._tan, _tan_docstring)
11111313

11121314
# U35: ==== TANH (x)
1113-
# FIXME: implement U35
1315+
_tanh_docstring = """
1316+
tanh(x, out=None, order='K')
1317+
1318+
Computes hyperbolic tangent for each element `x_i` for input array `x`.
1319+
1320+
Args:
1321+
x (usm_ndarray):
1322+
Input array, expected to have numeric data type.
1323+
out ({None, usm_ndarray}, optional):
1324+
Output array to populate.
1325+
Array have the correct shape and the expected data type.
1326+
order ("C","F","A","K", optional):
1327+
Memory layout of the newly output array, if parameter `out` is `None`.
1328+
Default: "K".
1329+
Returns:
1330+
usm_narray:
1331+
An array containing the element-wise hyperbolic tangent. The data type
1332+
of the returned array is determined by the Type Promotion Rules.
1333+
"""
1334+
1335+
tanh = UnaryElementwiseFunc(
1336+
"tanh", ti._tanh_result_type, ti._tanh, _tanh_docstring
1337+
)
11141338

11151339
# U36: ==== TRUNC (x)
11161340
_trunc_docstring = """

0 commit comments

Comments
 (0)