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

IntelPython / dpnp / 12076405164

28 Nov 2024 11:09PM UTC coverage: 66.699% (-1.2%) from 67.852%
12076405164

Pull #2180

github

web-flow
Merge fa3af10fd into 4e021720c
Pull Request #2180: Implementation of correlate

4427 of 10378 branches covered (42.66%)

Branch coverage included in aggregate %.

282 of 590 new or added lines in 9 files covered. (47.8%)

58 existing lines in 3 files now uncovered.

16622 of 21180 relevant lines covered (78.48%)

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

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

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

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

102
    if (unequal_queue != arrays.cend()) {
1,127✔
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,127✔
108

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

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

119
    if (overlap(*input, *output)) {
1,120!
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,120✔
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
{
563✔
130
    for (const auto &input : inputs) {
1,349✔
131
        for (const auto &output : outputs) {
1,349✔
132
            check_no_overlap(input, output, names);
1,349✔
133
        }
1,349✔
134
    }
1,349✔
135
}
563✔
136

137
void check_num_dims(const array_ptr &arr,
138
                    const size_t ndim,
139
                    const array_names &names)
140
{
1,545✔
141
    size_t arr_n_dim = arr != nullptr ? arr->get_ndim() : 0;
1,545✔
142
    if (arr != nullptr && arr_n_dim != ndim) {
1,545!
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,545✔
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
{
564✔
179
    check_writable(outputs, names);
564✔
180

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

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

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

189
    check_no_overlap(inputs, outputs, names);
564✔
190
}
564✔
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