Skip to content

Commit e6d0d6f

Browse files
Move ti.cos()/cosh() and reuse them
1 parent a6100b8 commit e6d0d6f

3 files changed

Lines changed: 62 additions & 4 deletions

File tree

dpctl_ext/tensor/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
bitwise_invert,
9696
ceil,
9797
conj,
98+
cos,
99+
cosh,
98100
)
99101
from ._reduction import (
100102
argmax,
@@ -144,6 +146,8 @@
144146
"concat",
145147
"conj",
146148
"copy",
149+
"cos",
150+
"cosh",
147151
"count_nonzero",
148152
"clip",
149153
"cumulative_logsumexp",

dpctl_ext/tensor/_elementwise_funcs.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,60 @@
324324
)
325325
del _conj_docstring
326326

327+
# U11: ==== COS (x)
328+
_cos_docstring = r"""
329+
cos(x, /, \*, out=None, order='K')
330+
331+
Computes cosine for each element `x_i` for input array `x`.
332+
333+
Args:
334+
x (usm_ndarray):
335+
Input array, expected to have a floating-point data type.
336+
out (Union[usm_ndarray, None], optional):
337+
Output array to populate.
338+
Array must have the correct shape and the expected data type.
339+
order ("C","F","A","K", optional):
340+
Memory layout of the new output array, if parameter
341+
`out` is ``None``.
342+
Default: "K".
343+
344+
Returns:
345+
usm_ndarray:
346+
An array containing the element-wise cosine. The data type
347+
of the returned array is determined by the Type Promotion Rules.
348+
"""
349+
350+
cos = UnaryElementwiseFunc("cos", ti._cos_result_type, ti._cos, _cos_docstring)
351+
del _cos_docstring
352+
353+
# U12: ==== COSH (x)
354+
_cosh_docstring = r"""
355+
cosh(x, /, \*, out=None, order='K')
356+
357+
Computes hyperbolic cosine for each element `x_i` for input array `x`.
358+
359+
Args:
360+
x (usm_ndarray):
361+
Input array, expected to have a floating-point data type.
362+
out (Union[usm_ndarray, None], optional):
363+
Output array to populate.
364+
Array must have the correct shape and the expected data type.
365+
order ("C","F","A","K", optional):
366+
Memory layout of the new output array, if parameter
367+
`out` is ``None``.
368+
Default: "K".
369+
370+
Returns:
371+
usm_ndarray:
372+
An array containing the element-wise hyperbolic cosine. The data type
373+
of the returned array is determined by the Type Promotion Rules.
374+
"""
375+
376+
cosh = UnaryElementwiseFunc(
377+
"cosh", ti._cosh_result_type, ti._cosh, _cosh_docstring
378+
)
379+
del _cosh_docstring
380+
327381
# U43: ==== ANGLE (x)
328382
_angle_docstring = r"""
329383
angle(x, /, \*, out=None, order='K')

dpnp/dpnp_iface_trigonometric.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,8 @@ def _get_accumulation_res_dt(a, dtype):
777777

778778
cos = DPNPUnaryFunc(
779779
"cos",
780-
ti._cos_result_type,
781-
ti._cos,
780+
ti_ext._cos_result_type,
781+
ti_ext._cos,
782782
_COS_DOCSTRING,
783783
mkl_fn_to_call="_mkl_cos_to_call",
784784
mkl_impl_fn="_cos",
@@ -841,8 +841,8 @@ def _get_accumulation_res_dt(a, dtype):
841841

842842
cosh = DPNPUnaryFunc(
843843
"cosh",
844-
ti._cosh_result_type,
845-
ti._cosh,
844+
ti_ext._cosh_result_type,
845+
ti_ext._cosh,
846846
_COSH_DOCSTRING,
847847
mkl_fn_to_call="_mkl_cosh_to_call",
848848
mkl_impl_fn="_cosh",

0 commit comments

Comments
 (0)