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

IntelPython / dpnp / 12223684049

08 Dec 2024 05:07PM UTC coverage: 66.716% (-1.4%) from 68.085%
12223684049

Pull #2180

github

web-flow
Merge 943726f4c into 6dc39f9e9
Pull Request #2180: Implementation of correlate

4487 of 10508 branches covered (42.7%)

Branch coverage included in aggregate %.

276 of 589 new or added lines in 9 files covered. (46.86%)

60 existing lines in 3 files now uncovered.

16704 of 21255 relevant lines covered (78.59%)

20101.65 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::validation
57
{
58
std::string name_of(const array_ptr &arr, const array_names &names)
59
{
1✔
60
    auto name_it = names.find(arr);
1✔
61
    assert(name_it != names.end());
1✔
62

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

NEW
66
    return "'unknown'";
×
67
}
1✔
68

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

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

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

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

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

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

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

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

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

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

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

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

179
    check_c_contig(inputs, names);
561✔
180
    check_c_contig(outputs, names);
561✔
181

182
    auto exec_q = get_queue(inputs, outputs);
561✔
183

184
    check_queue(inputs, names, exec_q);
561✔
185
    check_queue(outputs, names, exec_q);
561✔
186

187
    check_no_overlap(inputs, outputs, names);
561✔
188
}
561✔
189

190
} // namespace statistics::validation
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