Skip to content

Commit 0bc8973

Browse files
Move ti.sign()/signbit()/sin()/sinh() and reuse them
1 parent dbf021a commit 0bc8973

File tree

18 files changed

+1943
-20
lines changed

18 files changed

+1943
-20
lines changed

dpctl_ext/tensor/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ set(_elementwise_sources
132132
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/remainder.cpp
133133
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/round.cpp
134134
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/rsqrt.cpp
135-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/sign.cpp
136-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/signbit.cpp
137-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/sin.cpp
138-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/sinh.cpp
135+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/sign.cpp
136+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/signbit.cpp
137+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/sin.cpp
138+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/sinh.cpp
139139
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/sqrt.cpp
140140
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/square.cpp
141141
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/subtract.cpp

dpctl_ext/tensor/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@
114114
proj,
115115
real,
116116
round,
117+
sign,
118+
signbit,
119+
sin,
120+
sinh,
117121
)
118122
from ._reduction import (
119123
argmax,
@@ -221,6 +225,10 @@
221225
"roll",
222226
"round",
223227
"searchsorted",
228+
"sign",
229+
"signbit",
230+
"sin",
231+
"sinh",
224232
"sort",
225233
"squeeze",
226234
"stack",

dpctl_ext/tensor/_elementwise_funcs.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,93 @@
844844
)
845845
del _round_docstring
846846

847+
# U29: ==== SIGN (x)
848+
_sign_docstring = r"""
849+
sign(x, /, \*, out=None, order='K')
850+
851+
Computes an indication of the sign of each element `x_i` of input array `x`
852+
using the signum function.
853+
854+
The signum function returns `-1` if `x_i` is less than `0`,
855+
`0` if `x_i` is equal to `0`, and `1` if `x_i` is greater than `0`.
856+
857+
Args:
858+
x (usm_ndarray):
859+
Input array, expected to have a numeric data type.
860+
out (Union[usm_ndarray, None], optional):
861+
Output array to populate.
862+
Array must have the correct shape and the expected data type.
863+
order ("C","F","A","K", optional):
864+
Memory layout of the new output array, if parameter
865+
`out` is ``None``.
866+
Default: "K".
867+
868+
Returns:
869+
usm_ndarray:
870+
An array containing the element-wise result of the signum function. The
871+
data type of the returned array is determined by the Type Promotion
872+
Rules.
873+
"""
874+
875+
sign = UnaryElementwiseFunc(
876+
"sign", ti._sign_result_type, ti._sign, _sign_docstring
877+
)
878+
del _sign_docstring
879+
880+
# U30: ==== SIN (x)
881+
_sin_docstring = r"""
882+
sin(x, /, \*, out=None, order='K')
883+
884+
Computes sine for each element `x_i` of input array `x`.
885+
886+
Args:
887+
x (usm_ndarray):
888+
Input array, expected to have a real-valued floating-point data type.
889+
out (Union[usm_ndarray, None], optional):
890+
Output array to populate.
891+
Array must have the correct shape and the expected data type.
892+
order ("C","F","A","K", optional):
893+
Memory layout of the new output array, if parameter
894+
`out` is ``None``.
895+
Default: "K".
896+
897+
Returns:
898+
usm_ndarray:
899+
An array containing the element-wise sine. The data type of the
900+
returned array is determined by the Type Promotion Rules.
901+
"""
902+
903+
sin = UnaryElementwiseFunc("sin", ti._sin_result_type, ti._sin, _sin_docstring)
904+
del _sin_docstring
905+
906+
# U31: ==== SINH (x)
907+
_sinh_docstring = r"""
908+
sinh(x, /, \*, out=None, order='K')
909+
910+
Computes hyperbolic sine for each element `x_i` for input array `x`.
911+
912+
Args:
913+
x (usm_ndarray):
914+
Input array, expected to have a floating-point data type.
915+
out (Union[usm_ndarray, None], optional):
916+
Output array to populate.
917+
Array must have the correct shape and the expected data type.
918+
order ("C","F","A","K", optional):
919+
Memory layout of the new output array, if parameter
920+
`out` is ``None``.
921+
Default: "K".
922+
923+
Returns:
924+
usm_ndarray:
925+
An array containing the element-wise hyperbolic sine. The data type
926+
of the returned array is determined by the Type Promotion Rules.
927+
"""
928+
929+
sinh = UnaryElementwiseFunc(
930+
"sinh", ti._sinh_result_type, ti._sinh, _sinh_docstring
931+
)
932+
del _sinh_docstring
933+
847934
# U40: ==== PROJ (x)
848935
_proj_docstring = r"""
849936
proj(x, /, \*, out=None, order='K')
@@ -871,6 +958,35 @@
871958
)
872959
del _proj_docstring
873960

961+
# U41: ==== SIGNBIT (x)
962+
_signbit_docstring = r"""
963+
signbit(x, /, \*, out=None, order='K')
964+
965+
Computes an indication of whether the sign bit of each element `x_i` of
966+
input array `x` is set.
967+
968+
Args:
969+
x (usm_ndarray):
970+
Input array, expected to have a real-valued floating-point data type.
971+
out (Union[usm_ndarray, None], optional):
972+
Output array to populate.
973+
Array must have the correct shape and the expected data type.
974+
order ("C","F","A","K", optional):
975+
Memory layout of the new output array, if parameter
976+
`out` is ``None``.
977+
Default: "K".
978+
979+
Returns:
980+
usm_ndarray:
981+
An array containing the element-wise signbit results. The returned array
982+
must have a data type of `bool`.
983+
"""
984+
985+
signbit = UnaryElementwiseFunc(
986+
"signbit", ti._signbit_result_type, ti._signbit, _signbit_docstring
987+
)
988+
del _signbit_docstring
989+
874990
# U43: ==== ANGLE (x)
875991
_angle_docstring = r"""
876992
angle(x, /, \*, out=None, order='K')

0 commit comments

Comments
 (0)