• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IntelPython / dpnp / 24687578389

20 Apr 2026 08:03PM UTC coverage: 78.429% (-3.6%) from 82.034%
24687578389

push

github

web-flow
Migrate `dpctl.tensor` into `dpnp.tensor` (#2856)

This PR migrates the tensor implementation from `dpctl.tensor` into
`dpnp.tensor` making dpnp the primary owner of the Array API-compliant
tensor layer

Major changes:

- Move compiled C++/SYCL extensions (`_tensor_impl,
_tensor_elementwise_impl, _tensor_reductions_impl, _tensor_sorting_impl,
_tensor_accumulation_impl, tensor linalg`) into `dpnp.tensor`
- Move `usm_ndarray`, `compute-follows-data utilities` and tensor
`tests` from dpctl
- Replace all `dpctl.tensor` references with `dpnp.tensor` in
docstrings, error messages and comments
- Remove redundant dpctl.tensor C-API  interface
- Add `tensor.rst` documentation page describing the module, its
relationship to `dpnp.ndarray` and `dpctl` and linking to the `dpctl
0.21.1 API` reference

This simplifies maintenance, reduces cross-project dependencies and
enables independent development and release cycles

1573 of 2908 branches covered (54.09%)

Branch coverage included in aggregate %.

6973 of 9803 new or added lines in 203 files covered. (71.13%)

1 existing line in 1 file now uncovered.

26259 of 32579 relevant lines covered (80.6%)

7622.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/dpnp/tensor/libtensor/include/utils/math_utils.hpp
1
//*****************************************************************************
2
// Copyright (c) 2026, Intel Corporation
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are met:
7
// - Redistributions of source code must retain the above copyright notice,
8
//   this list of conditions and the following disclaimer.
9
// - Redistributions in binary form must reproduce the above copyright notice,
10
//   this list of conditions and the following disclaimer in the documentation
11
//   and/or other materials provided with the distribution.
12
// - Neither the name of the copyright holder nor the names of its contributors
13
//   may be used to endorse or promote products derived from this software
14
//   without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26
// THE POSSIBILITY OF SUCH DAMAGE.
27
//*****************************************************************************
28
///
29
/// \file
30
/// This file defines math utility functions.
31
//===----------------------------------------------------------------------===//
32

33
#pragma once
34

35
#include <cmath>
36
#include <complex>
37
#include <limits>
38

39
#include <sycl/sycl.hpp>
40

41
namespace dpnp::tensor::math_utils
42
{
43
template <typename T>
44
bool less_complex(const T &x1, const T &x2)
NEW
45
{
×
NEW
46
    using realT = typename T::value_type;
×
NEW
47
    realT real1 = std::real(x1);
×
NEW
48
    realT real2 = std::real(x2);
×
NEW
49
    realT imag1 = std::imag(x1);
×
NEW
50
    realT imag2 = std::imag(x2);
×
51

NEW
52
    return (real1 == real2)
×
NEW
53
               ? (imag1 < imag2)
×
NEW
54
               : (real1 < real2 && !std::isnan(imag1) && !std::isnan(imag2));
×
NEW
55
}
×
56

57
template <typename T>
58
bool greater_complex(const T &x1, const T &x2)
59
{
60
    using realT = typename T::value_type;
61
    realT real1 = std::real(x1);
62
    realT real2 = std::real(x2);
63
    realT imag1 = std::imag(x1);
64
    realT imag2 = std::imag(x2);
65

66
    return (real1 == real2)
67
               ? (imag1 > imag2)
68
               : (real1 > real2 && !std::isnan(imag1) && !std::isnan(imag2));
69
}
70

71
template <typename T>
72
bool less_equal_complex(const T &x1, const T &x2)
NEW
73
{
×
NEW
74
    using realT = typename T::value_type;
×
NEW
75
    realT real1 = std::real(x1);
×
NEW
76
    realT real2 = std::real(x2);
×
NEW
77
    realT imag1 = std::imag(x1);
×
NEW
78
    realT imag2 = std::imag(x2);
×
79

NEW
80
    return (real1 == real2)
×
NEW
81
               ? (imag1 <= imag2)
×
NEW
82
               : (real1 < real2 && !std::isnan(imag1) && !std::isnan(imag2));
×
NEW
83
}
×
84

85
template <typename T>
86
bool greater_equal_complex(const T &x1, const T &x2)
NEW
87
{
×
NEW
88
    using realT = typename T::value_type;
×
NEW
89
    realT real1 = std::real(x1);
×
NEW
90
    realT real2 = std::real(x2);
×
NEW
91
    realT imag1 = std::imag(x1);
×
NEW
92
    realT imag2 = std::imag(x2);
×
93

NEW
94
    return (real1 == real2)
×
NEW
95
               ? (imag1 >= imag2)
×
NEW
96
               : (real1 > real2 && !std::isnan(imag1) && !std::isnan(imag2));
×
NEW
97
}
×
98

99
template <typename T>
100
T max_complex(const T &x1, const T &x2)
101
{
102
    using realT = typename T::value_type;
103
    realT real1 = std::real(x1);
104
    realT real2 = std::real(x2);
105
    realT imag1 = std::imag(x1);
106
    realT imag2 = std::imag(x2);
107

108
    bool isnan_imag1 = std::isnan(imag1);
109
    bool gt = (real1 == real2)
110
                  ? (imag1 > imag2)
111
                  : (real1 > real2 && !isnan_imag1 && !std::isnan(imag2));
112
    return (std::isnan(real1) || isnan_imag1 || gt) ? x1 : x2;
113
}
114

115
template <typename T>
116
T min_complex(const T &x1, const T &x2)
117
{
118
    using realT = typename T::value_type;
119
    realT real1 = std::real(x1);
120
    realT real2 = std::real(x2);
121
    realT imag1 = std::imag(x1);
122
    realT imag2 = std::imag(x2);
123

124
    bool isnan_imag1 = std::isnan(imag1);
125
    bool lt = (real1 == real2)
126
                  ? (imag1 < imag2)
127
                  : (real1 < real2 && !isnan_imag1 && !std::isnan(imag2));
128
    return (std::isnan(real1) || isnan_imag1 || lt) ? x1 : x2;
129
}
130

131
template <typename T>
132
T logaddexp(T x, T y)
133
{
134
    if (x == y) { // handle signed infinities
135
        const T log2 = sycl::log(T(2));
136
        return x + log2;
137
    }
138
    else {
139
        const T tmp = x - y;
140
        static constexpr T zero(0);
141

142
        return (tmp > zero)
143
                   ? (x + sycl::log1p(sycl::exp(-tmp)))
144
                   : ((tmp <= zero) ? y + sycl::log1p(sycl::exp(tmp))
145
                                    : std::numeric_limits<T>::quiet_NaN());
146
    }
147
}
148
} // namespace dpnp::tensor::math_utils
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc