Skip to content

Commit c73df9c

Browse files
Move ti.greater()/greater_equal()/hypot() and reuse them
1 parent fe7778d commit c73df9c

File tree

15 files changed

+1584
-15
lines changed

15 files changed

+1584
-15
lines changed

dpctl_ext/tensor/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ set(_elementwise_sources
100100
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/expm1.cpp
101101
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/floor_divide.cpp
102102
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/floor.cpp
103-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/greater_equal.cpp
104-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/greater.cpp
105-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/hypot.cpp
103+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/greater_equal.cpp
104+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/greater.cpp
105+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/hypot.cpp
106106
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/imag.cpp
107107
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/isfinite.cpp
108108
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/isinf.cpp

dpctl_ext/tensor/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
expm1,
119119
floor,
120120
floor_divide,
121+
greater,
122+
greater_equal,
123+
hypot,
121124
imag,
122125
isfinite,
123126
isinf,
@@ -225,6 +228,9 @@
225228
"from_numpy",
226229
"full",
227230
"full_like",
231+
"greater",
232+
"greater_equal",
233+
"hypot",
228234
"iinfo",
229235
"imag",
230236
"isfinite",

dpctl_ext/tensor/_elementwise_funcs.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,77 @@
775775
)
776776
del _floor_divide_docstring_
777777

778+
# B11: ==== GREATER (x1, x2)
779+
_greater_docstring_ = r"""
780+
greater(x1, x2, /, \*, out=None, order='K')
781+
782+
Computes the greater-than test results for each element `x1_i` of
783+
the input array `x1` with the respective element `x2_i` of the input array `x2`.
784+
785+
Args:
786+
x1 (usm_ndarray):
787+
First input array. May have any data type.
788+
x2 (usm_ndarray):
789+
Second input array. May have any data type.
790+
out (Union[usm_ndarray, None], optional):
791+
Output array to populate.
792+
Array must have the correct shape and the expected data type.
793+
order ("C","F","A","K", optional):
794+
Memory layout of the new output array, if parameter
795+
`out` is ``None``.
796+
Default: "K".
797+
798+
Returns:
799+
usm_ndarray:
800+
An array containing the result of element-wise greater-than comparison.
801+
The returned array has a data type of `bool`.
802+
"""
803+
804+
greater = BinaryElementwiseFunc(
805+
"greater",
806+
ti._greater_result_type,
807+
ti._greater,
808+
_greater_docstring_,
809+
weak_type_resolver=_resolve_weak_types_all_py_ints,
810+
)
811+
del _greater_docstring_
812+
813+
# B12: ==== GREATER_EQUAL (x1, x2)
814+
_greater_equal_docstring_ = r"""
815+
greater_equal(x1, x2, /, \*, out=None, order='K')
816+
817+
Computes the greater-than or equal-to test results for each element `x1_i` of
818+
the input array `x1` with the respective element `x2_i` of the input array `x2`.
819+
820+
Args:
821+
x1 (usm_ndarray):
822+
First input array. May have any data type.
823+
x2 (usm_ndarray):
824+
Second input array. May have any data type.
825+
out (Union[usm_ndarray, None], optional):
826+
Output array to populate.
827+
Array must have the correct shape and the expected data type.
828+
order ("C","F","A","K", optional):
829+
Memory layout of the new output array, if parameter
830+
`out` is ``None``.
831+
Default: "K".
832+
833+
Returns:
834+
usm_ndarray:
835+
An array containing the result of element-wise greater-than or equal-to
836+
comparison.
837+
The returned array has a data type of `bool`.
838+
"""
839+
840+
greater_equal = BinaryElementwiseFunc(
841+
"greater_equal",
842+
ti._greater_equal_result_type,
843+
ti._greater_equal,
844+
_greater_equal_docstring_,
845+
weak_type_resolver=_resolve_weak_types_all_py_ints,
846+
)
847+
del _greater_equal_docstring_
848+
778849
# U14: ==== EXPM1 (x)
779850
_expm1_docstring = r"""
780851
expm1(x, /, \*, out=None, order='K')
@@ -1440,6 +1511,39 @@
14401511
)
14411512
del _trunc_docstring
14421513

1514+
# B24: ==== HYPOT (x1, x2)
1515+
_hypot_docstring_ = r"""
1516+
hypot(x1, x2, /, \*, out=None, order='K')
1517+
1518+
Computes the square root of the sum of squares for each element `x1_i` of the
1519+
input array `x1` with the respective element `x2_i` of the input array `x2`.
1520+
1521+
Args:
1522+
x1 (usm_ndarray):
1523+
First input array, expected to have a real-valued floating-point data
1524+
type.
1525+
x2 (usm_ndarray):
1526+
Second input array, also expected to have a real-valued floating-point
1527+
data type.
1528+
out (Union[usm_ndarray, None], optional):
1529+
Output array to populate.
1530+
Array must have the correct shape and the expected data type.
1531+
order ("C","F","A","K", optional):
1532+
Memory layout of the new output array, if parameter
1533+
`out` is ``None``.
1534+
Default: "K".
1535+
1536+
Returns:
1537+
usm_ndarray:
1538+
An array containing the element-wise hypotenuse. The data type
1539+
of the returned array is determined by the Type Promotion Rules.
1540+
"""
1541+
1542+
hypot = BinaryElementwiseFunc(
1543+
"hypot", ti._hypot_result_type, ti._hypot, _hypot_docstring_
1544+
)
1545+
del _hypot_docstring_
1546+
14431547
# U37: ==== CBRT (x)
14441548
_cbrt_docstring_ = r"""
14451549
cbrt(x, /, \*, out=None, order='K')

0 commit comments

Comments
 (0)