Skip to content

Commit 739ea9e

Browse files
committed
impl elementwise hyperbolic and inverse trigonometric
1 parent f032154 commit 739ea9e

File tree

17 files changed

+3859
-87
lines changed

17 files changed

+3859
-87
lines changed

dpctl/tensor/__init__.py

Lines changed: 24 additions & 2 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,
@@ -125,9 +132,12 @@
125132
proj,
126133
real,
127134
sin,
135+
sinh,
128136
sqrt,
129137
square,
130138
subtract,
139+
tan,
140+
tanh,
131141
)
132142
from ._reduction import sum
133143

@@ -207,9 +217,18 @@
207217
"nan",
208218
"inf",
209219
"abs",
220+
"acos",
221+
"acosh",
210222
"add",
223+
"asin",
224+
"asinh",
225+
"atan",
226+
"atanh",
211227
"conj",
212228
"cos",
229+
"cosh",
230+
"divide",
231+
"equal",
213232
"exp",
214233
"expm1",
215234
"greater",
@@ -228,19 +247,22 @@
228247
"log1p",
229248
"log2",
230249
"log10",
250+
"multiply",
231251
"negative",
232252
"positive",
233253
"proj",
234254
"real",
235255
"sin",
256+
"sinh",
236257
"sqrt",
237258
"square",
238259
"divide",
239260
"multiply",
240261
"pow",
241262
"subtract",
242-
"equal",
243263
"not_equal",
244-
"sum",
245264
"floor_divide",
265+
"sum",
266+
"tan",
267+
"tanh",
246268
]

dpctl/tensor/_elementwise_funcs.py

Lines changed: 234 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,56 @@
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(
68+
"acos", ti._acos_result_type, ti._acos, _acos_docstring
69+
)
4770

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

5197
# B01: ===== ADD (x1, x2)
5298

@@ -81,19 +127,111 @@
81127
)
82128

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

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

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

92207
# B02: ===== ATAN2 (x1, x2)
93208
# FIXME: implemetn B02
94209

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

98236
# B03: ===== BITWISE_AND (x1, x2)
99237
# FIXME: implemetn B03
@@ -165,7 +303,29 @@
165303
cos = UnaryElementwiseFunc("cos", ti._cos_result_type, ti._cos, _cos_docstring)
166304

167305
# U12: ==== COSH (x)
168-
# FIXME: implement U12
306+
_cosh_docstring = """
307+
cosh(x, out=None, order='K')
308+
309+
Computes hyperbolic cosine for each element `x_i` for input array `x`.
310+
311+
Args:
312+
x (usm_ndarray):
313+
Input array, expected to have numeric data type.
314+
out ({None, usm_ndarray}, optional):
315+
Output array to populate.
316+
Array have the correct shape and the expected data type.
317+
order ("C","F","A","K", optional):
318+
Memory layout of the newly output array, if parameter `out` is `None`.
319+
Default: "K".
320+
Returns:
321+
usm_narray:
322+
An array containing the element-wise hyperbolic cosine. The data type
323+
of the returned array is determined by the Type Promotion Rules.
324+
"""
325+
326+
cosh = UnaryElementwiseFunc(
327+
"cosh", ti._cosh_result_type, ti._cosh, _cosh_docstring
328+
)
169329

170330
# B08: ==== DIVIDE (x1, x2)
171331
_divide_docstring_ = """
@@ -939,7 +1099,29 @@
9391099
sin = UnaryElementwiseFunc("sin", ti._sin_result_type, ti._sin, _sin_docstring)
9401100

9411101
# U31: ==== SINH (x)
942-
# FIXME: implement U31
1102+
_sinh_docstring = """
1103+
sinh(x, out=None, order='K')
1104+
1105+
Computes hyperbolic sine for each element `x_i` for input array `x`.
1106+
1107+
Args:
1108+
x (usm_ndarray):
1109+
Input array, expected to have numeric data type.
1110+
out ({None, usm_ndarray}, optional):
1111+
Output array to populate.
1112+
Array have the correct shape and the expected data type.
1113+
order ("C","F","A","K", optional):
1114+
Memory layout of the newly output array, if parameter `out` is `None`.
1115+
Default: "K".
1116+
Returns:
1117+
usm_narray:
1118+
An array containing the element-wise hyperbolic sine. The data type
1119+
of the returned array is determined by the Type Promotion Rules.
1120+
"""
1121+
1122+
sinh = UnaryElementwiseFunc(
1123+
"sinh", ti._sinh_result_type, ti._sinh, _sinh_docstring
1124+
)
9431125

9441126
# U32: ==== SQUARE (x)
9451127
_square_docstring_ = """
@@ -1025,10 +1207,52 @@
10251207

10261208

10271209
# U34: ==== TAN (x)
1028-
# FIXME: implement U34
1210+
_tan_docstring = """
1211+
tan(x, out=None, order='K')
1212+
1213+
Computes tangent for each element `x_i` for input array `x`.
1214+
1215+
Args:
1216+
x (usm_ndarray):
1217+
Input array, expected to have numeric data type.
1218+
out ({None, usm_ndarray}, optional):
1219+
Output array to populate.
1220+
Array have the correct shape and the expected data type.
1221+
order ("C","F","A","K", optional):
1222+
Memory layout of the newly output array, if parameter `out` is `None`.
1223+
Default: "K".
1224+
Returns:
1225+
usm_narray:
1226+
An array containing the element-wise tangent. The data type
1227+
of the returned array is determined by the Type Promotion Rules.
1228+
"""
1229+
1230+
tan = UnaryElementwiseFunc("tan", ti._tan_result_type, ti._tan, _tan_docstring)
10291231

10301232
# U35: ==== TANH (x)
1031-
# FIXME: implement U35
1233+
_tanh_docstring = """
1234+
tanh(x, out=None, order='K')
1235+
1236+
Computes hyperbolic tangent for each element `x_i` for input array `x`.
1237+
1238+
Args:
1239+
x (usm_ndarray):
1240+
Input array, expected to have numeric data type.
1241+
out ({None, usm_ndarray}, optional):
1242+
Output array to populate.
1243+
Array have the correct shape and the expected data type.
1244+
order ("C","F","A","K", optional):
1245+
Memory layout of the newly output array, if parameter `out` is `None`.
1246+
Default: "K".
1247+
Returns:
1248+
usm_narray:
1249+
An array containing the element-wise hyperbolic tangent. The data type
1250+
of the returned array is determined by the Type Promotion Rules.
1251+
"""
1252+
1253+
tanh = UnaryElementwiseFunc(
1254+
"tanh", ti._tanh_result_type, ti._tanh, _tanh_docstring
1255+
)
10321256

10331257
# U36: ==== TRUNC (x)
10341258
# FIXME: implement U36

0 commit comments

Comments
 (0)