Skip to content

Commit b6597ff

Browse files
committed
impl elementwise hyperbolic and inverse trigonometric
1 parent 179ce15 commit b6597ff

File tree

17 files changed

+3859
-89
lines changed

17 files changed

+3859
-89
lines changed

dpctl/tensor/__init__.py

Lines changed: 24 additions & 4 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,
@@ -116,8 +123,11 @@
116123
proj,
117124
real,
118125
sin,
126+
sinh,
119127
sqrt,
120128
subtract,
129+
tan,
130+
tanh,
121131
)
122132
from ._reduction import sum
123133

@@ -197,9 +207,18 @@
197207
"nan",
198208
"inf",
199209
"abs",
210+
"acos",
211+
"acosh",
200212
"add",
213+
"asin",
214+
"asinh",
215+
"atan",
216+
"atanh",
201217
"conj",
202218
"cos",
219+
"cosh",
220+
"divide",
221+
"equal",
203222
"exp",
204223
"expm1",
205224
"greater",
@@ -212,15 +231,16 @@
212231
"less_equal",
213232
"log",
214233
"log1p",
234+
"multiply",
215235
"proj",
216236
"real",
217237
"sin",
238+
"sinh",
218239
"sqrt",
219-
"divide",
220-
"multiply",
221240
"subtract",
222-
"equal",
223241
"not_equal",
224-
"sum",
225242
"floor_divide",
243+
"sum",
244+
"tan",
245+
"tanh",
226246
]

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_ = """
@@ -735,7 +895,29 @@
735895
sin = UnaryElementwiseFunc("sin", ti._sin_result_type, ti._sin, _sin_docstring)
736896

737897
# U31: ==== SINH (x)
738-
# FIXME: implement U31
898+
_sinh_docstring = """
899+
sinh(x, out=None, order='K')
900+
901+
Computes hyperbolic sine for each element `x_i` for input array `x`.
902+
903+
Args:
904+
x (usm_ndarray):
905+
Input array, expected to have numeric data type.
906+
out ({None, usm_ndarray}, optional):
907+
Output array to populate.
908+
Array have the correct shape and the expected data type.
909+
order ("C","F","A","K", optional):
910+
Memory layout of the newly output array, if parameter `out` is `None`.
911+
Default: "K".
912+
Returns:
913+
usm_narray:
914+
An array containing the element-wise hyperbolic sine. The data type
915+
of the returned array is determined by the Type Promotion Rules.
916+
"""
917+
918+
sinh = UnaryElementwiseFunc(
919+
"sinh", ti._sinh_result_type, ti._sinh, _sinh_docstring
920+
)
739921

740922
# U32: ==== SQUARE (x)
741923
# FIXME: implement U32
@@ -799,10 +981,52 @@
799981

800982

801983
# U34: ==== TAN (x)
802-
# FIXME: implement U34
984+
_tan_docstring = """
985+
tan(x, out=None, order='K')
986+
987+
Computes tangent for each element `x_i` for input array `x`.
988+
989+
Args:
990+
x (usm_ndarray):
991+
Input array, expected to have numeric data type.
992+
out ({None, usm_ndarray}, optional):
993+
Output array to populate.
994+
Array have the correct shape and the expected data type.
995+
order ("C","F","A","K", optional):
996+
Memory layout of the newly output array, if parameter `out` is `None`.
997+
Default: "K".
998+
Returns:
999+
usm_narray:
1000+
An array containing the element-wise tangent. The data type
1001+
of the returned array is determined by the Type Promotion Rules.
1002+
"""
1003+
1004+
tan = UnaryElementwiseFunc("tan", ti._tan_result_type, ti._tan, _tan_docstring)
8031005

8041006
# U35: ==== TANH (x)
805-
# FIXME: implement U35
1007+
_tanh_docstring = """
1008+
tanh(x, out=None, order='K')
1009+
1010+
Computes hyperbolic tangent for each element `x_i` for input array `x`.
1011+
1012+
Args:
1013+
x (usm_ndarray):
1014+
Input array, expected to have numeric data type.
1015+
out ({None, usm_ndarray}, optional):
1016+
Output array to populate.
1017+
Array have the correct shape and the expected data type.
1018+
order ("C","F","A","K", optional):
1019+
Memory layout of the newly output array, if parameter `out` is `None`.
1020+
Default: "K".
1021+
Returns:
1022+
usm_narray:
1023+
An array containing the element-wise hyperbolic tangent. The data type
1024+
of the returned array is determined by the Type Promotion Rules.
1025+
"""
1026+
1027+
tanh = UnaryElementwiseFunc(
1028+
"tanh", ti._tanh_result_type, ti._tanh, _tanh_docstring
1029+
)
8061030

8071031
# U36: ==== TRUNC (x)
8081032
# FIXME: implement U36

0 commit comments

Comments
 (0)