Skip to content

Commit 94c6b6c

Browse files
committed
impl elementwise hyperbolic and inverse trigonometric
1 parent 1596a13 commit 94c6b6c

File tree

15 files changed

+3000
-86
lines changed

15 files changed

+3000
-86
lines changed

dpctl/tensor/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,16 @@
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
conj,
98104
cos,
105+
cosh,
99106
divide,
100107
equal,
101108
exp,
@@ -110,8 +117,11 @@
110117
proj,
111118
real,
112119
sin,
120+
sinh,
113121
sqrt,
114122
subtract,
123+
tan,
124+
tanh,
115125
)
116126
from ._reduction import sum
117127

@@ -191,9 +201,18 @@
191201
"nan",
192202
"inf",
193203
"abs",
204+
"acos",
205+
"acosh",
194206
"add",
207+
"asin",
208+
"asinh",
209+
"atan",
210+
"atanh",
195211
"conj",
196212
"cos",
213+
"cosh",
214+
"divide",
215+
"equal",
197216
"exp",
198217
"expm1",
199218
"imag",
@@ -202,13 +221,14 @@
202221
"isfinite",
203222
"log",
204223
"log1p",
224+
"multiply",
205225
"proj",
206226
"real",
207227
"sin",
228+
"sinh",
208229
"sqrt",
209-
"divide",
210-
"multiply",
211230
"subtract",
212-
"equal",
213231
"sum",
232+
"tan",
233+
"tanh",
214234
]

dpctl/tensor/_elementwise_funcs.py

Lines changed: 216 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,52 @@
4343
abs = UnaryElementwiseFunc("abs", ti._abs_result_type, ti._abs, _abs_docstring_)
4444

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

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

5193
# B01: ===== ADD (x1, x2)
5294

@@ -77,19 +119,103 @@
77119
)
78120

79121
# U04: ===== ASIN (x)
80-
# FIXME: implement U04
122+
_asin_docstring = """
123+
asin(x, out=None, order='K')
124+
125+
Computes inverse sine for each element `x_i` for input array `x`.
126+
127+
Args:
128+
x (usm_ndarray):
129+
Input array, expected to have numeric data type.
130+
out ({None, usm_ndarray}, optional):
131+
Output array to populate.
132+
Array have the correct shape and the expected data type.
133+
order ("C","F","A","K", optional):
134+
Memory layout of the newly output array, if parameter `out` is `None`.
135+
Default: "K".
136+
Returns:
137+
usm_narray:
138+
An array containing the element-wise inverse sine, in radians
139+
and in the closed interval `[-pi/2, pi/2]`. The data type
140+
of the returned array is determined by the Type Promotion Rules.
141+
"""
142+
143+
asin = UnaryElementwiseFunc("asin", ti._asin_result_type, ti._asin, _asin_docstring)
81144

82145
# U05: ===== ASINH (x)
83-
# FIXME: implement U05
146+
_asinh_docstring = """
147+
asinh(x, out=None, order='K')
148+
149+
Computes inverse hyperbolic sine for each element `x_i` for input array `x`.
150+
151+
Args:
152+
x (usm_ndarray):
153+
Input array, expected to have numeric data type.
154+
out ({None, usm_ndarray}, optional):
155+
Output array to populate.
156+
Array have the correct shape and the expected data type.
157+
order ("C","F","A","K", optional):
158+
Memory layout of the newly output array, if parameter `out` is `None`.
159+
Default: "K".
160+
Returns:
161+
usm_narray:
162+
An array containing the element-wise inverse hyperbolic sine.
163+
The data type of the returned array is determined by
164+
the Type Promotion Rules.
165+
"""
166+
167+
asinh = UnaryElementwiseFunc("asinh", ti._asinh_result_type, ti._asinh, _asinh_docstring)
84168

85169
# U06: ===== ATAN (x)
86-
# FIXME: implement U06
170+
_atan_docstring = """
171+
atan(x, out=None, order='K')
172+
173+
Computes inverse tangent for each element `x_i` for input array `x`.
174+
175+
Args:
176+
x (usm_ndarray):
177+
Input array, expected to have numeric data type.
178+
out ({None, usm_ndarray}, optional):
179+
Output array to populate.
180+
Array have the correct shape and the expected data type.
181+
order ("C","F","A","K", optional):
182+
Memory layout of the newly output array, if parameter `out` is `None`.
183+
Default: "K".
184+
Returns:
185+
usm_narray:
186+
An array containing the element-wise inverse tangent, in radians
187+
and in the closed interval `[-pi/2, pi/2]`. The data type
188+
of the returned array is determined by the Type Promotion Rules.
189+
"""
190+
191+
atan = UnaryElementwiseFunc("atan", ti._atan_result_type, ti._atan, _atan_docstring)
87192

88193
# B02: ===== ATAN2 (x1, x2)
89194
# FIXME: implemetn B02
90195

91196
# U07: ===== ATANH (x)
92-
# FIXME: implemetn U07
197+
_atanh_docstring = """
198+
atanh(x, out=None, order='K')
199+
200+
Computes hyperbolic inverse tangent for each element `x_i` for input array `x`.
201+
202+
Args:
203+
x (usm_ndarray):
204+
Input array, expected to have numeric data type.
205+
out ({None, usm_ndarray}, optional):
206+
Output array to populate.
207+
Array have the correct shape and the expected data type.
208+
order ("C","F","A","K", optional):
209+
Memory layout of the newly output array, if parameter `out` is `None`.
210+
Default: "K".
211+
Returns:
212+
usm_narray:
213+
An array containing the element-wise hyperbolic inverse tangent.
214+
The data type of the returned array is determined by
215+
the Type Promotion Rules.
216+
"""
217+
218+
atanh = UnaryElementwiseFunc("atanh", ti._atanh_result_type, ti._atanh, _atanh_docstring)
93219

94220
# B03: ===== BITWISE_AND (x1, x2)
95221
# FIXME: implemetn B03
@@ -161,7 +287,27 @@
161287
cos = UnaryElementwiseFunc("cos", ti._cos_result_type, ti._cos, _cos_docstring)
162288

163289
# U12: ==== COSH (x)
164-
# FIXME: implement U12
290+
_cosh_docstring = """
291+
cosh(x, out=None, order='K')
292+
293+
Computes hyperbolic cosine for each element `x_i` for input array `x`.
294+
295+
Args:
296+
x (usm_ndarray):
297+
Input array, expected to have numeric data type.
298+
out ({None, usm_ndarray}, optional):
299+
Output array to populate.
300+
Array have the correct shape and the expected data type.
301+
order ("C","F","A","K", optional):
302+
Memory layout of the newly output array, if parameter `out` is `None`.
303+
Default: "K".
304+
Returns:
305+
usm_narray:
306+
An array containing the element-wise hyperbolic cosine. The data type
307+
of the returned array is determined by the Type Promotion Rules.
308+
"""
309+
310+
cosh = UnaryElementwiseFunc("cosh", ti._cosh_result_type, ti._cosh, _cosh_docstring)
165311

166312
# B08: ==== DIVIDE (x1, x2)
167313
_divide_docstring_ = """
@@ -571,7 +717,27 @@
571717
sin = UnaryElementwiseFunc("sin", ti._sin_result_type, ti._sin, _sin_docstring)
572718

573719
# U31: ==== SINH (x)
574-
# FIXME: implement U31
720+
_sinh_docstring = """
721+
sinh(x, out=None, order='K')
722+
723+
Computes hyperbolic sine for each element `x_i` for input array `x`.
724+
725+
Args:
726+
x (usm_ndarray):
727+
Input array, expected to have numeric data type.
728+
out ({None, usm_ndarray}, optional):
729+
Output array to populate.
730+
Array have the correct shape and the expected data type.
731+
order ("C","F","A","K", optional):
732+
Memory layout of the newly output array, if parameter `out` is `None`.
733+
Default: "K".
734+
Returns:
735+
usm_narray:
736+
An array containing the element-wise hyperbolic sine. The data type
737+
of the returned array is determined by the Type Promotion Rules.
738+
"""
739+
740+
sinh = UnaryElementwiseFunc("sinh", ti._sinh_result_type, ti._sinh, _sinh_docstring)
575741

576742
# U32: ==== SQUARE (x)
577743
# FIXME: implement U32
@@ -631,10 +797,50 @@
631797

632798

633799
# U34: ==== TAN (x)
634-
# FIXME: implement U34
800+
_tan_docstring = """
801+
tan(x, out=None, order='K')
802+
803+
Computes tangent for each element `x_i` for input array `x`.
804+
805+
Args:
806+
x (usm_ndarray):
807+
Input array, expected to have numeric data type.
808+
out ({None, usm_ndarray}, optional):
809+
Output array to populate.
810+
Array have the correct shape and the expected data type.
811+
order ("C","F","A","K", optional):
812+
Memory layout of the newly output array, if parameter `out` is `None`.
813+
Default: "K".
814+
Returns:
815+
usm_narray:
816+
An array containing the element-wise tangent. The data type
817+
of the returned array is determined by the Type Promotion Rules.
818+
"""
819+
820+
tan = UnaryElementwiseFunc("tan", ti._tan_result_type, ti._tan, _tan_docstring)
635821

636822
# U35: ==== TANH (x)
637-
# FIXME: implement U35
823+
_tanh_docstring = """
824+
tanh(x, out=None, order='K')
825+
826+
Computes hyperbolic tangent for each element `x_i` for input array `x`.
827+
828+
Args:
829+
x (usm_ndarray):
830+
Input array, expected to have numeric data type.
831+
out ({None, usm_ndarray}, optional):
832+
Output array to populate.
833+
Array have the correct shape and the expected data type.
834+
order ("C","F","A","K", optional):
835+
Memory layout of the newly output array, if parameter `out` is `None`.
836+
Default: "K".
837+
Returns:
838+
usm_narray:
839+
An array containing the element-wise hyperbolic tangent. The data type
840+
of the returned array is determined by the Type Promotion Rules.
841+
"""
842+
843+
tanh = UnaryElementwiseFunc("tanh", ti._tanh_result_type, ti._tanh, _tanh_docstring)
638844

639845
# U36: ==== TRUNC (x)
640846
# FIXME: implement U36

0 commit comments

Comments
 (0)