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

IntelPython / dpctl / 16270219306

14 Jul 2025 02:53PM UTC coverage: 85.89%. Remained the same
16270219306

Pull #2123

github

web-flow
Merge 4947f5cfd into e2789db9a
Pull Request #2123: Allow type casting of zero-sized array to any dtype

3227 of 3878 branches covered (83.21%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

2 existing lines in 2 files now uncovered.

12235 of 14124 relevant lines covered (86.63%)

6889.19 hits per line

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

71.43
/libsyclinterface/source/dpctl_vector_templ.cpp
1
//===-- dpctl_vector_templ.cpp - Wrapper functions for opaque vector types ===//
2
//
3
//                      Data Parallel Control (dpctl)
4
//
5
// Copyright 2020-2025 Intel Corporation
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
//    http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// distributed under the License is distributed on an "AS IS" BASIS,
15
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
// See the License for the specific language governing permissions and
17
// limitations under the License.
18
//
19
//===----------------------------------------------------------------------===//
20
///
21
/// \file
22
/// This file is meant to be directly included inside other source files to add
23
/// the wrapper functions for vector operations.
24
///
25
//===----------------------------------------------------------------------===//
26
#include "Support/MemOwnershipAttrs.h"
27
#include "dpctl_error_handlers.h"
28
#include "dpctl_sycl_type_casters.hpp"
29
#include "dpctl_vector_macros.h"
30
#include <stddef.h>
31
#include <type_traits>
32
#include <vector>
33

34
/*!
35
 * @brief Creates a new std::vector of the opaque SYCL pointer types.
36
 *
37
 * @return   A new dynamically allocated std::vector of opaque pointer types.
38
 */
39
__dpctl_give VECTOR(EL) FN(EL, Create)()
40
{
1✔
41
    using vecTy = std::vector<SYCLREF(EL)>;
1✔
42
    vecTy *Vec = nullptr;
1✔
43
    try {
1✔
44
        Vec = new std::vector<SYCLREF(EL)>();
1✔
45
        return ::dpctl::syclinterface::wrap<vecTy>(Vec);
1✔
46
    } catch (std::exception const &e) {
1✔
47
        delete Vec;
×
48
        error_handler(e, __FILE__, __func__, __LINE__);
×
49
        return nullptr;
×
50
    }
×
51
}
1✔
52

53
/*!
54
 * @brief Creates a new std::vector of the opaque SYCL pointer types from given
55
 * C array with deep copy.
56
 *
57
 * @return   A new dynamically allocated std::vector of opaque pointer types.
58
 */
59
__dpctl_give VECTOR(EL)
60
    FN(EL, CreateFromArray)(size_t n, __dpctl_keep SYCLREF(EL) * elems)
61
{
2✔
62
    using vecTy = std::vector<SYCLREF(EL)>;
2✔
63
    vecTy *Vec = nullptr;
2✔
64
    try {
2✔
65
        Vec = new vecTy();
2✔
66
        for (size_t i = 0; i < n; ++i) {
7!
67
            auto Ref = ::dpctl::syclinterface::unwrap<EL_SYCL_TYPE>(elems[i]);
5✔
68
            Vec->emplace_back(::dpctl::syclinterface::wrap<EL_SYCL_TYPE>(
5✔
69
                new EL_SYCL_TYPE(*Ref)));
5✔
70
        }
5✔
71
        return ::dpctl::syclinterface::wrap<vecTy>(Vec);
2✔
72
    } catch (std::exception const &e) {
2✔
73
        delete Vec;
×
74
        error_handler(e, __FILE__, __func__, __LINE__);
×
75
        return nullptr;
×
76
    }
×
77
}
2✔
78

79
/*!
80
 * @brief Frees all the elements of the passed in std::vector and then frees the
81
 * std::vector pointer.
82
 *
83
 */
84
void FN(EL, Delete)(__dpctl_take VECTOR(EL) VRef)
85
{
513✔
86
    using vecTy = std::vector<SYCLREF(EL)>;
513✔
87
    auto Vec = ::dpctl::syclinterface::unwrap<vecTy>(VRef);
513✔
88
    if (Vec) {
513!
89
        for (auto i = 0ul; i < Vec->size(); ++i) {
1,031✔
90
            auto D = ::dpctl::syclinterface::unwrap<EL_SYCL_TYPE>((*Vec)[i]);
530✔
91
            delete D;
530✔
92
        }
530✔
93
    }
501✔
94
    delete Vec;
513✔
95
}
513✔
96

97
/*!
98
 * @brief Frees all the elements of the vector and then calls clear().
99
 *
100
 */
101
void FN(EL, Clear)(__dpctl_keep VECTOR(EL) VRef)
102
{
17✔
103
    using vecTy = std::vector<SYCLREF(EL)>;
17✔
104
    auto Vec = ::dpctl::syclinterface::unwrap<vecTy>(VRef);
17✔
105
    if (Vec) {
17!
106
        for (auto i = 0ul; i < Vec->size(); ++i) {
23!
107
            auto D = ::dpctl::syclinterface::unwrap<EL_SYCL_TYPE>((*Vec)[i]);
6✔
108
            delete D;
6✔
109
        }
6✔
110
        Vec->clear();
17✔
111
    }
17✔
112
}
17✔
113

114
/*!
115
 * @brief Returns the number of elements in the vector.
116
 *
117
 */
118
size_t FN(EL, Size)(__dpctl_keep VECTOR(EL) VRef)
119
{
494✔
120
    using vecTy = std::vector<SYCLREF(EL)>;
494✔
121
    auto V = ::dpctl::syclinterface::unwrap<vecTy>(VRef);
494✔
122
    if (V)
494!
123
        return V->size();
494✔
124
    else
×
125
        return 0;
×
126
}
494✔
127

128
/*!
129
 * @brief Returns a copy of the opaque pointer at specified index, and throws
130
 * an out_of_range exception if the index is incorrect.
131
 *
132
 */
133
SYCLREF(EL) FN(EL, GetAt)(__dpctl_keep VECTOR(EL) VRef, size_t index)
134
{
478✔
135
    using vecTy = std::vector<SYCLREF(EL)>;
478✔
136
    auto Vec = ::dpctl::syclinterface::unwrap<vecTy>(VRef);
478✔
137
    SYCLREF(EL) copy = nullptr;
478✔
138
    if (Vec) {
478!
139
        SYCLREF(EL) ret;
478✔
140
        try {
478✔
141
            ret = Vec->at(index);
478✔
142
        } catch (std::exception const &e) {
478✔
143
            error_handler(e, __FILE__, __func__, __LINE__);
×
144
            return nullptr;
×
145
        }
×
146
        auto Ref = ::dpctl::syclinterface::unwrap<EL_SYCL_TYPE>(ret);
478✔
147
        EL_SYCL_TYPE *elPtr = nullptr;
478✔
148
        try {
478✔
149
            elPtr = new EL_SYCL_TYPE(*Ref);
478✔
150
            copy = ::dpctl::syclinterface::wrap<EL_SYCL_TYPE>(elPtr);
478✔
151
        } catch (std::exception const &e) {
478✔
152
            delete elPtr;
×
153
            error_handler(e, __FILE__, __func__, __LINE__);
×
154
            return nullptr;
×
155
        }
×
156
    }
478✔
157
    return copy;
478✔
158
}
478✔
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

© 2025 Coveralls, Inc