• 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

54.48
/dpnp/tensor/libtensor/include/utils/type_dispatch.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 class to implement dispatch tables for pair of types
31
//===----------------------------------------------------------------------===//
32

33
#pragma once
34

35
#include <cassert>
36
#include <cstdint>
37
#include <stdexcept>
38
#include <string>
39

40
#include "dpnp4pybind11.hpp"
41

42
#include "type_dispatch_building.hpp"
43

44
namespace dpnp::tensor::type_dispatch
45
{
46
struct usm_ndarray_types
47
{
48
    int typenum_to_lookup_id(int typenum) const
49
    {
487,993✔
50
        using typenum_t = ::dpnp::tensor::type_dispatch::typenum_t;
487,993✔
51
        auto const &api = ::dpnp::detail::dpnp_capi::get();
487,993✔
52

53
        if (typenum == api.UAR_DOUBLE_) {
487,993✔
54
            return static_cast<int>(typenum_t::DOUBLE);
233,305✔
55
        }
233,305✔
56
        else if (typenum == api.UAR_INT64_) {
254,688✔
57
            return static_cast<int>(typenum_t::INT64);
44,456✔
58
        }
44,456✔
59
        else if (typenum == api.UAR_INT32_) {
210,232✔
60
            return static_cast<int>(typenum_t::INT32);
23,696✔
61
        }
23,696✔
62
        else if (typenum == api.UAR_BOOL_) {
186,536✔
63
            return static_cast<int>(typenum_t::BOOL);
7,124✔
64
        }
7,124✔
65
        else if (typenum == api.UAR_CDOUBLE_) {
179,412✔
66
            return static_cast<int>(typenum_t::CDOUBLE);
48,790✔
67
        }
48,790✔
68
        else if (typenum == api.UAR_FLOAT_) {
130,622✔
69
            return static_cast<int>(typenum_t::FLOAT);
67,572✔
70
        }
67,572✔
71
        else if (typenum == api.UAR_INT16_) {
63,050✔
72
            return static_cast<int>(typenum_t::INT16);
3,706✔
73
        }
3,706✔
74
        else if (typenum == api.UAR_INT8_) {
59,344✔
75
            return static_cast<int>(typenum_t::INT8);
3,553✔
76
        }
3,553✔
77
        else if (typenum == api.UAR_UINT64_) {
55,791✔
78
            return static_cast<int>(typenum_t::UINT64);
3,437✔
79
        }
3,437✔
80
        else if (typenum == api.UAR_UINT32_) {
52,354✔
81
            return static_cast<int>(typenum_t::UINT32);
3,790✔
82
        }
3,790✔
83
        else if (typenum == api.UAR_UINT16_) {
48,564✔
84
            return static_cast<int>(typenum_t::UINT16);
3,031✔
85
        }
3,031✔
86
        else if (typenum == api.UAR_UINT8_) {
45,533✔
87
            return static_cast<int>(typenum_t::UINT8);
2,737✔
88
        }
2,737✔
89
        else if (typenum == api.UAR_CFLOAT_) {
42,796✔
90
            return static_cast<int>(typenum_t::CFLOAT);
31,169✔
91
        }
31,169✔
92
        else if (typenum == api.UAR_HALF_) {
11,627!
93
            return static_cast<int>(typenum_t::HALF);
11,627✔
94
        }
11,627✔
NEW
95
        else if (typenum == api.UAR_INT_ || typenum == api.UAR_UINT_) {
×
NEW
96
            switch (sizeof(int)) {
×
NEW
97
            case sizeof(std::int32_t):
×
NEW
98
                return ((typenum == api.UAR_INT_)
×
NEW
99
                            ? static_cast<int>(typenum_t::INT32)
×
NEW
100
                            : static_cast<int>(typenum_t::UINT32));
×
NEW
101
            case sizeof(std::int64_t):
×
NEW
102
                return ((typenum == api.UAR_INT_)
×
NEW
103
                            ? static_cast<int>(typenum_t::INT64)
×
NEW
104
                            : static_cast<int>(typenum_t::UINT64));
×
NEW
105
            default:
×
NEW
106
                throw_unrecognized_typenum_error(typenum);
×
NEW
107
            }
×
NEW
108
        }
×
NEW
109
        else if (typenum == api.UAR_LONGLONG_ ||
×
NEW
110
                 typenum == api.UAR_ULONGLONG_) {
×
NEW
111
            switch (sizeof(long long)) {
×
NEW
112
            case sizeof(std::int64_t):
×
NEW
113
                return ((typenum == api.UAR_LONGLONG_)
×
NEW
114
                            ? static_cast<int>(typenum_t::INT64)
×
NEW
115
                            : static_cast<int>(typenum_t::UINT64));
×
NEW
116
            default:
×
NEW
117
                throw_unrecognized_typenum_error(typenum);
×
NEW
118
            }
×
NEW
119
        }
×
NEW
120
        else {
×
NEW
121
            throw_unrecognized_typenum_error(typenum);
×
NEW
122
        }
×
123
        // return code signalling error, should never be reached
124
        assert(false);
487,993!
NEW
125
        return -1;
×
NEW
126
    }
×
127

128
private:
129
    void throw_unrecognized_typenum_error(int typenum) const
NEW
130
    {
×
NEW
131
        throw std::runtime_error("Unrecognized typenum " +
×
NEW
132
                                 std::to_string(typenum) + " encountered.");
×
NEW
133
    }
×
134
};
135
} // namespace dpnp::tensor::type_dispatch
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