Skip to content

Commit caf503d

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

File tree

17 files changed

+3848
-88
lines changed

17 files changed

+3848
-88
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: 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

@@ -77,19 +123,111 @@
77123
)
78124

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

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

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

88203
# B02: ===== ATAN2 (x1, x2)
89204
# FIXME: implemetn B02
90205

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

94232
# B03: ===== BITWISE_AND (x1, x2)
95233
# FIXME: implemetn B03
@@ -161,7 +299,29 @@
161299
cos = UnaryElementwiseFunc("cos", ti._cos_result_type, ti._cos, _cos_docstring)
162300

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

166326
# B08: ==== DIVIDE (x1, x2)
167327
_divide_docstring_ = """
@@ -571,7 +731,29 @@
571731
sin = UnaryElementwiseFunc("sin", ti._sin_result_type, ti._sin, _sin_docstring)
572732

573733
# U31: ==== SINH (x)
574-
# FIXME: implement U31
734+
_sinh_docstring = """
735+
sinh(x, out=None, order='K')
736+
737+
Computes hyperbolic sine for each element `x_i` for input array `x`.
738+
739+
Args:
740+
x (usm_ndarray):
741+
Input array, expected to have numeric data type.
742+
out ({None, usm_ndarray}, optional):
743+
Output array to populate.
744+
Array have the correct shape and the expected data type.
745+
order ("C","F","A","K", optional):
746+
Memory layout of the newly output array, if parameter `out` is `None`.
747+
Default: "K".
748+
Returns:
749+
usm_narray:
750+
An array containing the element-wise hyperbolic sine. The data type
751+
of the returned array is determined by the Type Promotion Rules.
752+
"""
753+
754+
sinh = UnaryElementwiseFunc(
755+
"sinh", ti._sinh_result_type, ti._sinh, _sinh_docstring
756+
)
575757

576758
# U32: ==== SQUARE (x)
577759
# FIXME: implement U32
@@ -631,10 +813,52 @@
631813

632814

633815
# U34: ==== TAN (x)
634-
# FIXME: implement U34
816+
_tan_docstring = """
817+
tan(x, out=None, order='K')
818+
819+
Computes tangent for each element `x_i` for input array `x`.
820+
821+
Args:
822+
x (usm_ndarray):
823+
Input array, expected to have numeric data type.
824+
out ({None, usm_ndarray}, optional):
825+
Output array to populate.
826+
Array have the correct shape and the expected data type.
827+
order ("C","F","A","K", optional):
828+
Memory layout of the newly output array, if parameter `out` is `None`.
829+
Default: "K".
830+
Returns:
831+
usm_narray:
832+
An array containing the element-wise tangent. The data type
833+
of the returned array is determined by the Type Promotion Rules.
834+
"""
835+
836+
tan = UnaryElementwiseFunc("tan", ti._tan_result_type, ti._tan, _tan_docstring)
635837

636838
# U35: ==== TANH (x)
637-
# FIXME: implement U35
839+
_tanh_docstring = """
840+
tanh(x, out=None, order='K')
841+
842+
Computes hyperbolic tangent for each element `x_i` for input array `x`.
843+
844+
Args:
845+
x (usm_ndarray):
846+
Input array, expected to have numeric data type.
847+
out ({None, usm_ndarray}, optional):
848+
Output array to populate.
849+
Array have the correct shape and the expected data type.
850+
order ("C","F","A","K", optional):
851+
Memory layout of the newly output array, if parameter `out` is `None`.
852+
Default: "K".
853+
Returns:
854+
usm_narray:
855+
An array containing the element-wise hyperbolic tangent. The data type
856+
of the returned array is determined by the Type Promotion Rules.
857+
"""
858+
859+
tanh = UnaryElementwiseFunc(
860+
"tanh", ti._tanh_result_type, ti._tanh, _tanh_docstring
861+
)
638862

639863
# U36: ==== TRUNC (x)
640864
# FIXME: implement U36

0 commit comments

Comments
 (0)