Skip to content

Commit eab5fec

Browse files
Move ti.imag()/isfinite()/isfinite() and reuse them
1 parent 44ac844 commit eab5fec

File tree

18 files changed

+1291
-18
lines changed

18 files changed

+1291
-18
lines changed

dpctl_ext/tensor/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ set(_elementwise_sources
103103
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/greater_equal.cpp
104104
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/greater.cpp
105105
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/hypot.cpp
106-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/imag.cpp
107-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/isfinite.cpp
108-
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/isinf.cpp
106+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/imag.cpp
107+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/isfinite.cpp
108+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/isinf.cpp
109109
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/isnan.cpp
110110
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/less_equal.cpp
111111
#${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/less.cpp

dpctl_ext/tensor/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
exp,
101101
expm1,
102102
floor,
103+
imag,
104+
isfinite,
105+
isinf,
103106
)
104107
from ._reduction import (
105108
argmax,
@@ -171,6 +174,9 @@
171174
"full",
172175
"full_like",
173176
"iinfo",
177+
"imag",
178+
"isfinite",
179+
"isinf",
174180
"isdtype",
175181
"isin",
176182
"linspace",

dpctl_ext/tensor/_elementwise_funcs.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,94 @@
464464
)
465465
del _floor_docstring
466466

467+
# U16: ==== IMAG (x)
468+
_imag_docstring = r"""
469+
imag(x, /, \*, out=None, order='K')
470+
471+
Computes imaginary part of each element `x_i` for input array `x`.
472+
473+
Args:
474+
x (usm_ndarray):
475+
Input array. May have any data type.
476+
out (Union[usm_ndarray, None], optional):
477+
Output array to populate.
478+
Array must have the correct shape and the expected data type.
479+
order ("C","F","A","K", optional):
480+
Memory layout of the new output array, if parameter
481+
`out` is ``None``.
482+
Default: "K".
483+
484+
Returns:
485+
usm_ndarray:
486+
An array containing the element-wise imaginary component of input.
487+
If the input is a real-valued data type, the returned array has
488+
the same data type. If the input is a complex floating-point
489+
data type, the returned array has a floating-point data type
490+
with the same floating-point precision as complex input.
491+
"""
492+
493+
imag = UnaryElementwiseFunc(
494+
"imag", ti._imag_result_type, ti._imag, _imag_docstring
495+
)
496+
del _imag_docstring
497+
498+
# U17: ==== ISFINITE (x)
499+
_isfinite_docstring_ = r"""
500+
isfinite(x, /, \*, out=None, order='K')
501+
502+
Test if each element of input array is a finite number.
503+
504+
Args:
505+
x (usm_ndarray):
506+
Input array. May have any data type.
507+
out (Union[usm_ndarray, None], optional):
508+
Output array to populate.
509+
Array must have the correct shape and the expected data type.
510+
order ("C","F","A","K", optional):
511+
Memory layout of the new output array, if parameter
512+
`out` is ``None``.
513+
Default: "K".
514+
515+
Returns:
516+
usm_ndarray:
517+
An array which is True where `x` is not positive infinity,
518+
negative infinity, or NaN, False otherwise.
519+
The data type of the returned array is `bool`.
520+
"""
521+
522+
isfinite = UnaryElementwiseFunc(
523+
"isfinite", ti._isfinite_result_type, ti._isfinite, _isfinite_docstring_
524+
)
525+
del _isfinite_docstring_
526+
527+
# U18: ==== ISINF (x)
528+
_isinf_docstring_ = r"""
529+
isinf(x, /, \*, out=None, order='K')
530+
531+
Test if each element of input array is an infinity.
532+
533+
Args:
534+
x (usm_ndarray):
535+
Input array. May have any data type.
536+
out (Union[usm_ndarray, None], optional):
537+
Output array to populate.
538+
Array must have the correct shape and the expected data type.
539+
order ("C","F","A","K", optional):
540+
Memory layout of the new output array, if parameter
541+
`out` is ``None``.
542+
Default: "K".
543+
544+
Returns:
545+
usm_ndarray:
546+
An array which is True where `x` is positive or negative infinity,
547+
False otherwise. The data type of the returned array is `bool`.
548+
"""
549+
550+
isinf = UnaryElementwiseFunc(
551+
"isinf", ti._isinf_result_type, ti._isinf, _isinf_docstring_
552+
)
553+
del _isinf_docstring_
554+
467555
# U43: ==== ANGLE (x)
468556
_angle_docstring = r"""
469557
angle(x, /, \*, out=None, order='K')

dpctl_ext/tensor/libtensor/include/kernels/elementwise_functions/exp.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@
2626
// THE POSSIBILITY OF SUCH DAMAGE.
2727
//*****************************************************************************
2828
//
29+
//===---------------------------------------------------------------------===//
30+
///
2931
/// \file
3032
/// This file defines kernels for elementwise evaluation of EXP(x) function.
3133
//===---------------------------------------------------------------------===//
3234

3335
#pragma once
3436
#include <cmath>
37+
#include <complex>
3538
#include <cstddef>
3639
#include <cstdint>
3740
#include <limits>
3841
#include <type_traits>
42+
#include <vector>
3943

4044
#include <sycl/sycl.hpp>
4145

@@ -45,7 +49,6 @@
4549
#include "kernels/dpctl_tensor_types.hpp"
4650
#include "kernels/elementwise_functions/common.hpp"
4751

48-
#include "utils/offset_utils.hpp"
4952
#include "utils/type_dispatch_building.hpp"
5053
#include "utils/type_utils.hpp"
5154

dpctl_ext/tensor/libtensor/include/kernels/elementwise_functions/expm1.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@
2626
// THE POSSIBILITY OF SUCH DAMAGE.
2727
//*****************************************************************************
2828
//
29+
//===---------------------------------------------------------------------===//
30+
///
2931
/// \file
3032
/// This file defines kernels for elementwise evaluation of EXPM1(x) function.
3133
//===---------------------------------------------------------------------===//
3234

3335
#pragma once
3436
#include <cmath>
37+
#include <complex>
3538
#include <cstddef>
3639
#include <cstdint>
3740
#include <limits>
3841
#include <type_traits>
42+
#include <vector>
3943

4044
#include <sycl/sycl.hpp>
4145

@@ -44,7 +48,6 @@
4448
#include "kernels/dpctl_tensor_types.hpp"
4549
#include "kernels/elementwise_functions/common.hpp"
4650

47-
#include "utils/offset_utils.hpp"
4851
#include "utils/type_dispatch_building.hpp"
4952
#include "utils/type_utils.hpp"
5053

dpctl_ext/tensor/libtensor/include/kernels/elementwise_functions/floor.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
// THE POSSIBILITY OF SUCH DAMAGE.
2727
//*****************************************************************************
2828
//
29+
//===---------------------------------------------------------------------===//
30+
///
2931
/// \file
3032
/// This file defines kernels for elementwise evaluation of FLOOR(x) function.
3133
//===---------------------------------------------------------------------===//
@@ -35,6 +37,7 @@
3537
#include <cstddef>
3638
#include <cstdint>
3739
#include <type_traits>
40+
#include <vector>
3841

3942
#include <sycl/sycl.hpp>
4043

@@ -43,7 +46,6 @@
4346
#include "kernels/dpctl_tensor_types.hpp"
4447
#include "kernels/elementwise_functions/common.hpp"
4548

46-
#include "utils/offset_utils.hpp"
4749
#include "utils/type_dispatch_building.hpp"
4850
#include "utils/type_utils.hpp"
4951

0 commit comments

Comments
 (0)