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

IntelPython / dpnp / 11906771818

19 Nov 2024 05:20AM UTC coverage: 66.566% (-1.2%) from 67.754%
11906771818

Pull #2180

github

web-flow
Merge 9083eeb2f into 261772aca
Pull Request #2180: Implementation of correlate

4397 of 10348 branches covered (42.49%)

Branch coverage included in aggregate %.

281 of 595 new or added lines in 9 files covered. (47.23%)

43 existing lines in 2 files now uncovered.

16486 of 21024 relevant lines covered (78.42%)

20297.42 hits per line

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

68.53
/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
{
562✔
38
    auto it = std::find_if(inputs.cbegin(), inputs.cend(),
562✔
39
                           [](const array_ptr &arr) { return arr != nullptr; });
562✔
40

41
    if (it != inputs.cend()) {
562!
42
        return (*it)->get_queue();
562✔
43
    }
562✔
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
{
562✔
74
    for (const auto &arr : arrays) {
562✔
75
        if (arr != nullptr && !arr->is_writable()) {
562!
NEW
76
            throw py::value_error(name_of(arr, names) +
×
NEW
77
                                  " parameter is not writable");
×
NEW
78
        }
×
79
    }
562✔
80
}
562✔
81

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

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

102
    if (unequal_queue != arrays.cend()) {
1,123✔
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,123✔
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;
227✔
115
    }
227✔
116

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

119
    if (overlap(*input, *output)) {
1,116!
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,116✔
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
{
561✔
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
}
561✔
136

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

148
void check_max_dims(const array_ptr &arr,
149
                    const size_t max_ndim,
150
                    const array_names &names)
151
{
221✔
152
    if (arr != nullptr && arr->get_ndim() > max_ndim) {
221!
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->get_ndim()) + " dimensions.");
×
NEW
157
    }
×
158
}
221✔
159

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

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

178
    check_c_contig(inputs, names);
562✔
179
    check_c_contig(outputs, names);
562✔
180

181
    auto exec_q = get_queue(inputs, outputs);
562✔
182

183
    check_queue(inputs, names, exec_q);
562✔
184
    check_queue(outputs, names, exec_q);
562✔
185

186
    check_no_overlap(inputs, outputs, names);
562✔
187
}
562✔
188

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