| 164 | } |
| 165 | |
| 166 | std::vector<size_t> sample_point_indices(size_t count, size_t target) { |
| 167 | if (count == 0) { |
| 168 | return {}; |
| 169 | } |
| 170 | if (count <= target) { |
| 171 | std::vector<size_t> all(count); |
| 172 | for (size_t i = 0; i < count; ++i) { |
| 173 | all[i] = i; |
| 174 | } |
| 175 | return all; |
| 176 | } |
| 177 | |
| 178 | const size_t first_count = 14; |
| 179 | const size_t middle_count = 12; |
| 180 | const size_t last_count = 14; |
| 181 | const size_t first_end = count / 3; |
| 182 | const size_t middle_end = (count * 2) / 3; |
| 183 | |
| 184 | auto append_range = [](std::vector<size_t> & dst, size_t begin, size_t end, size_t samples) { |
| 185 | if (begin >= end || samples == 0) { |
| 186 | return; |
| 187 | } |
| 188 | const size_t span = end - begin; |
| 189 | if (span <= samples) { |
| 190 | for (size_t i = begin; i < end; ++i) { |
| 191 | if (dst.empty() || dst.back() != i) { |
| 192 | dst.push_back(i); |
| 193 | } |
| 194 | } |
| 195 | return; |
| 196 | } |
| 197 | for (size_t i = 0; i < samples; ++i) { |
| 198 | const double pos = samples == 1 ? 0.0 : static_cast<double>(i) / static_cast<double>(samples - 1); |
| 199 | const size_t offset = static_cast<size_t>(pos * static_cast<double>(span - 1)); |
| 200 | const size_t index = begin + offset; |
| 201 | if (dst.empty() || dst.back() != index) { |
| 202 | dst.push_back(index); |
| 203 | } |
| 204 | } |
| 205 | }; |
| 206 | |
| 207 | std::vector<size_t> points; |
| 208 | points.reserve(target); |
| 209 | append_range(points, 0, first_end, first_count); |
| 210 | append_range(points, first_end, middle_end, middle_count); |
| 211 | append_range(points, middle_end, count, last_count); |
| 212 | |
| 213 | if (points.empty() || points.front() != 0) { |
| 214 | points.insert(points.begin(), 0); |
| 215 | } |
| 216 | if (points.back() != count - 1) { |
| 217 | points.push_back(count - 1); |
| 218 | } |
| 219 | points.erase(std::unique(points.begin(), points.end()), points.end()); |
| 220 | return points; |
| 221 | } |
| 222 | |
| 223 | std::string sample_points_f32(const std::vector<float> & values) { |
no test coverage detected