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

IntelPython / dpnp / 12062592735

28 Nov 2024 04:36AM UTC coverage: 66.669% (-1.2%) from 67.824%
12062592735

Pull #2180

github

web-flow
Merge fbc94d0f5 into 88911fbab
Pull Request #2180: Implementation of correlate

4418 of 10370 branches covered (42.6%)

Branch coverage included in aggregate %.

283 of 592 new or added lines in 9 files covered. (47.8%)

58 existing lines in 3 files now uncovered.

16606 of 21165 relevant lines covered (78.46%)

20162.26 hits per line

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

69.74
/dpnp/backend/extensions/statistics/validation_utils.cpp
1
//*****************************************************************************
2
// Copyright (c) 2024, 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
//
13
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
// THE POSSIBILITY OF SUCH DAMAGE.
24
//*****************************************************************************
25

26
#include "validation_utils.hpp"
27
#include "utils/memory_overlap.hpp"
28

29
using statistics::validation::array_names;
30
using statistics::validation::array_ptr;
31

32
namespace
33
{
34

35
sycl::queue get_queue(const std::vector<array_ptr> &inputs,
36
                      const std::vector<array_ptr> &outputs)
37
{
561✔
38
    auto it = std::find_if(inputs.cbegin(), inputs.cend(),
561✔
39
                           [](const array_ptr &arr) { return arr != nullptr; });
561✔
40

41
    if (it != inputs.cend()) {
561!
42
        return (*it)->get_queue();
561✔
43
    }
561✔
44

NEW
45
    it = std::find_if(outputs.cbegin(), outputs.cend(),
×
NEW
46
                      [](const array_ptr &arr) { return arr != nullptr; });
×
47

NEW
48
    if (it != outputs.cend()) {
×
NEW
49
        return (*it)->get_queue();
×
NEW
50
    }
×
51

NEW
52
    throw py::value_error("No input or output arrays found");
×
NEW
53
}
×
54
} // namespace
55

56
namespace statistics
57
{
58
namespace validation
59
{
60
std::string name_of(const array_ptr &arr, const array_names &names)
61
{
1✔
62
    auto name_it = names.find(arr);
1✔
63
    assert(name_it != names.end());
1✔
64

65
    if (name_it != names.end())
1!
66
        return "'" + name_it->second + "'";
1✔
67

NEW
68
    return "'unknown'";
×
69
}
1✔
70

71
void check_writable(const std::vector<array_ptr> &arrays,
72
                    const array_names &names)
73
{
561✔
74
    for (const auto &arr : arrays) {
561✔
75
        if (arr != nullptr && !arr->is_writable()) {
561!
NEW
76
            throw py::value_error(name_of(arr, names) +
×
NEW
77
                                  " parameter is not writable");
×
NEW
78
        }
×
79
    }
561✔
80
}
561✔
81

82
void check_c_contig(const std::vector<array_ptr> &arrays,
83
                    const array_names &names)
84
{
1,122✔
85
    for (const auto &arr : arrays) {
1,906✔
86
        if (arr != nullptr && !arr->is_c_contiguous()) {
1,906!
NEW
87
            throw py::value_error(name_of(arr, names) +
×
NEW
88
                                  " parameter is not c-contiguos");
×
NEW
89
        }
×
90
    }
1,906✔
91
}
1,122✔
92

93
void check_queue(const std::vector<array_ptr> &arrays,
94
                 const array_names &names,
95
                 const sycl::queue &exec_q)
96
{
1,121✔
97
    auto unequal_queue =
1,121✔
98
        std::find_if(arrays.cbegin(), arrays.cend(), [&](const array_ptr &arr) {
1,905✔
99
            return arr != nullptr && arr->get_queue() != exec_q;
1,905✔
100
        });
1,905✔
101

102
    if (unequal_queue != arrays.cend()) {
1,121✔
103
        throw py::value_error(
1✔
104
            name_of(*unequal_queue, names) +
1✔
105
            " parameter has incompatible queue with other parameters");
1✔
106
    }
1✔
107
}
1,121✔
108

109
void check_no_overlap(const array_ptr &input,
110
                      const array_ptr &output,
111
                      const array_names &names)
112
{
1,343✔
113
    if (input == nullptr || output == nullptr) {
1,343!
114
        return;
229✔
115
    }
229✔
116

117
    const auto &overlap = dpctl::tensor::overlap::MemoryOverlap();
1,114✔
118

119
    if (overlap(*input, *output)) {
1,114!
NEW
120
        throw py::value_error(name_of(input, names) +
×
NEW
121
                              " has overlapping memory segments with " +
×
NEW
122
                              name_of(output, names));
×
NEW
123
    }
×
124
}
1,114✔
125

126
void check_no_overlap(const std::vector<array_ptr> &inputs,
127
                      const std::vector<array_ptr> &outputs,
128
                      const array_names &names)
129
{
560✔
130
    for (const auto &input : inputs) {
1,343✔
131
        for (const auto &output : outputs) {
1,343✔
132
            check_no_overlap(input, output, names);
1,343✔
133
        }
1,343✔
134
    }
1,343✔
135
}
560✔
136

137
void check_num_dims(const array_ptr &arr,
138
                    const size_t ndim,
139
                    const array_names &names)
140
{
1,536✔
141
    size_t arr_n_dim = arr != nullptr ? arr->get_ndim() : 0;
1,536✔
142
    if (arr != nullptr && arr_n_dim != ndim) {
1,536!
NEW
143
        throw py::value_error("Array " + name_of(arr, names) + " must be " +
×
NEW
144
                              std::to_string(ndim) + "D, but got " +
×
NEW
145
                              std::to_string(arr_n_dim) + "D.");
×
NEW
146
    }
×
147
}
1,536✔
148

149
void check_max_dims(const array_ptr &arr,
150
                    const size_t max_ndim,
151
                    const array_names &names)
152
{
223✔
153
    size_t arr_n_dim = arr != nullptr ? arr->get_ndim() : 0;
223!
154
    if (arr != nullptr && arr_n_dim > max_ndim) {
223!
NEW
155
        throw py::value_error(
×
NEW
156
            "Array " + name_of(arr, names) + " must have no more than " +
×
NEW
157
            std::to_string(max_ndim) + " dimensions, but got " +
×
NEW
158
            std::to_string(arr_n_dim) + " dimensions.");
×
NEW
159
    }
×
160
}
223✔
161

162
void check_size_at_least(const array_ptr &arr,
163
                         const size_t size,
164
                         const array_names &names)
165
{
446✔
166
    size_t arr_size = arr != nullptr ? arr->get_size() : 0;
446✔
167
    if (arr != nullptr && arr_size < size) {
446!
NEW
168
        throw py::value_error("Array " + name_of(arr, names) +
×
NEW
169
                              " must have at least " + std::to_string(size) +
×
NEW
170
                              " elements, but got " + std::to_string(arr_size) +
×
NEW
171
                              " elements.");
×
NEW
172
    }
×
173
}
446✔
174

175
void common_checks(const std::vector<array_ptr> &inputs,
176
                   const std::vector<array_ptr> &outputs,
177
                   const array_names &names)
178
{
561✔
179
    check_writable(outputs, names);
561✔
180

181
    check_c_contig(inputs, names);
561✔
182
    check_c_contig(outputs, names);
561✔
183

184
    auto exec_q = get_queue(inputs, outputs);
561✔
185

186
    check_queue(inputs, names, exec_q);
561✔
187
    check_queue(outputs, names, exec_q);
561✔
188

189
    check_no_overlap(inputs, outputs, names);
561✔
190
}
561✔
191

192
} // namespace validation
193
} // namespace statistics
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