Skip to content

impl elementwise hyperbolic and trigonometric functions #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:
run: |
. $CONDA/etc/profile.d/conda.sh
conda activate test_dpctl
gdb --batch -ex r -ex 'info sharedlibrary' -ex 'set print elements 1000' -ex bt --args ${CONDA_PREFIX}/bin/python -m pytest -q -ra --disable-warnings --pyargs dpctl.tests.test_tensor_elementwise::test_cos_order -vv || true
gdb --batch -ex r -ex 'info sharedlibrary' -ex 'set print elements 1000' -ex bt --args ${CONDA_PREFIX}/bin/python -m pytest -q -ra --disable-warnings --pyargs dpctl.tests.elementwise.test_trigonometric::test_trig_order -vv || true
- name: Run tests
env:
SYCL_QUEUE_THREAD_POOL_SIZE: 6
Expand Down
22 changes: 22 additions & 0 deletions dpctl/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@
from ._constants import e, inf, nan, newaxis, pi
from ._elementwise_funcs import (
abs,
acos,
acosh,
add,
asin,
asinh,
atan,
atanh,
ceil,
conj,
cos,
cosh,
divide,
equal,
exp,
Expand Down Expand Up @@ -127,9 +134,12 @@
proj,
real,
sin,
sinh,
sqrt,
square,
subtract,
tan,
tanh,
trunc,
)
from ._reduction import sum
Expand Down Expand Up @@ -210,10 +220,17 @@
"nan",
"inf",
"abs",
"acos",
"acosh",
"add",
"asin",
"asinh",
"atan",
"atanh",
"ceil",
"conj",
"cos",
"cosh",
"divide",
"equal",
"exp",
Expand Down Expand Up @@ -244,9 +261,14 @@
"proj",
"real",
"sin",
"sinh",
"sqrt",
"square",
"subtract",
"not_equal",
"floor_divide",
"sum",
"tan",
"tanh",
"trunc",
]
244 changes: 234 additions & 10 deletions dpctl/tensor/_elementwise_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,56 @@
abs = UnaryElementwiseFunc("abs", ti._abs_result_type, ti._abs, _abs_docstring_)

# U02: ==== ACOS (x)
# FIXME: implement U02
_acos_docstring = """
acos(x, out=None, order='K')

Computes inverse cosine for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise inverse cosine, in radians
and in the closed interval `[-pi/2, pi/2]`. The data type
of the returned array is determined by the Type Promotion Rules.
"""

acos = UnaryElementwiseFunc(
"acos", ti._acos_result_type, ti._acos, _acos_docstring
)

# U03: ===== ACOSH (x)
# FIXME: implement U03
_acosh_docstring = """
acosh(x, out=None, order='K')

Computes inverse hyperbolic cosine for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise inverse hyperbolic cosine.
The data type of the returned array is determined by
the Type Promotion Rules.
"""

acosh = UnaryElementwiseFunc(
"acosh", ti._acosh_result_type, ti._acosh, _acosh_docstring
)

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

Expand Down Expand Up @@ -81,19 +127,111 @@
)

# U04: ===== ASIN (x)
# FIXME: implement U04
_asin_docstring = """
asin(x, out=None, order='K')

Computes inverse sine for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise inverse sine, in radians
and in the closed interval `[-pi/2, pi/2]`. The data type
of the returned array is determined by the Type Promotion Rules.
"""

asin = UnaryElementwiseFunc(
"asin", ti._asin_result_type, ti._asin, _asin_docstring
)

# U05: ===== ASINH (x)
# FIXME: implement U05
_asinh_docstring = """
asinh(x, out=None, order='K')

Computes inverse hyperbolic sine for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise inverse hyperbolic sine.
The data type of the returned array is determined by
the Type Promotion Rules.
"""

asinh = UnaryElementwiseFunc(
"asinh", ti._asinh_result_type, ti._asinh, _asinh_docstring
)

# U06: ===== ATAN (x)
# FIXME: implement U06
_atan_docstring = """
atan(x, out=None, order='K')

Computes inverse tangent for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise inverse tangent, in radians
and in the closed interval `[-pi/2, pi/2]`. The data type
of the returned array is determined by the Type Promotion Rules.
"""

atan = UnaryElementwiseFunc(
"atan", ti._atan_result_type, ti._atan, _atan_docstring
)

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

# U07: ===== ATANH (x)
# FIXME: implemetn U07
_atanh_docstring = """
atanh(x, out=None, order='K')

Computes hyperbolic inverse tangent for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise hyperbolic inverse tangent.
The data type of the returned array is determined by
the Type Promotion Rules.
"""

atanh = UnaryElementwiseFunc(
"atanh", ti._atanh_result_type, ti._atanh, _atanh_docstring
)

# B03: ===== BITWISE_AND (x1, x2)
# FIXME: implemetn B03
Expand Down Expand Up @@ -188,7 +326,29 @@
cos = UnaryElementwiseFunc("cos", ti._cos_result_type, ti._cos, _cos_docstring)

# U12: ==== COSH (x)
# FIXME: implement U12
_cosh_docstring = """
cosh(x, out=None, order='K')

Computes hyperbolic cosine for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise hyperbolic cosine. The data type
of the returned array is determined by the Type Promotion Rules.
"""

cosh = UnaryElementwiseFunc(
"cosh", ti._cosh_result_type, ti._cosh, _cosh_docstring
)

# B08: ==== DIVIDE (x1, x2)
_divide_docstring_ = """
Expand Down Expand Up @@ -985,7 +1145,29 @@
sin = UnaryElementwiseFunc("sin", ti._sin_result_type, ti._sin, _sin_docstring)

# U31: ==== SINH (x)
# FIXME: implement U31
_sinh_docstring = """
sinh(x, out=None, order='K')

Computes hyperbolic sine for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise hyperbolic sine. The data type
of the returned array is determined by the Type Promotion Rules.
"""

sinh = UnaryElementwiseFunc(
"sinh", ti._sinh_result_type, ti._sinh, _sinh_docstring
)

# U32: ==== SQUARE (x)
_square_docstring_ = """
Expand Down Expand Up @@ -1071,10 +1253,52 @@


# U34: ==== TAN (x)
# FIXME: implement U34
_tan_docstring = """
tan(x, out=None, order='K')

Computes tangent for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise tangent. The data type
of the returned array is determined by the Type Promotion Rules.
"""

tan = UnaryElementwiseFunc("tan", ti._tan_result_type, ti._tan, _tan_docstring)

# U35: ==== TANH (x)
# FIXME: implement U35
_tanh_docstring = """
tanh(x, out=None, order='K')

Computes hyperbolic tangent for each element `x_i` for input array `x`.

Args:
x (usm_ndarray):
Input array, expected to have numeric data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
usm_narray:
An array containing the element-wise hyperbolic tangent. The data type
of the returned array is determined by the Type Promotion Rules.
"""

tanh = UnaryElementwiseFunc(
"tanh", ti._tanh_result_type, ti._tanh, _tanh_docstring
)

# U36: ==== TRUNC (x)
_trunc_docstring = """
Expand Down
Loading