|
20 | 20 | #define APPROXIMATION_H_INCLUDED |
21 | 21 |
|
22 | 22 | #include <algorithm> |
| 23 | +#include <cassert> |
23 | 24 | #include <cmath> |
24 | 25 | #include <cstddef> |
25 | 26 | #include <cstdint> |
@@ -403,33 +404,36 @@ class Summand { |
403 | 404 | Summand<int64_t> grid_squeeze(const std::vector<std::vector<value_type>> &grid) const; |
404 | 405 |
|
405 | 406 | void evaluate_in_grid(const std::vector<std::vector<value_type>> &grid) { |
| 407 | + using T = typename filtration_type::value_type; |
406 | 408 | if (birth_corners_.num_generators() == 0) return; |
407 | | - auto num_parameters = birth_corners_.num_parameters(); |
408 | | - auto snap = [](value_type x) { |
409 | | - value_type a = std::floor(x); |
410 | | - value_type b = std::ceil(x); |
411 | | - size_t out; |
| 409 | + auto snap = [](T x) { |
| 410 | + T a = std::floor(x); |
| 411 | + T b = std::ceil(x); |
| 412 | + std::size_t out; |
412 | 413 | if (x - a < b - x) |
413 | | - out = static_cast<size_t>(a); |
| 414 | + out = static_cast<std::size_t>(a); |
414 | 415 | else |
415 | | - out = static_cast<size_t>(b); |
| 416 | + out = static_cast<std::size_t>(b); |
416 | 417 | return out; |
417 | 418 | }; |
418 | 419 | auto todo = [&](auto &corners) { |
419 | | - return [&](size_t g) { |
| 420 | + return [&](std::size_t g) { |
420 | 421 | // auto &x = corners[i]; |
421 | 422 | // for (auto g = 0u; g < x.num_generators(); ++g) { |
422 | 423 | for (auto p = 0u; p < corners.num_parameters(); ++p) { |
423 | | - value_type snapped = snap(corners(g, p)); |
424 | | - corners(g, p) = (snapped >= grid[p].size() ? filtration_type::inf(num_parameters)(0,p) : grid[p][snapped]); |
| 424 | + assert(corners(g, p) >= 0); |
| 425 | + if (corners(g, p) != filtration_type::T_inf) { |
| 426 | + std::size_t snapped = snap(corners(g, p)); |
| 427 | + corners(g, p) = (snapped >= grid[p].size() ? filtration_type::T_inf : grid[p][snapped]); |
| 428 | + } |
425 | 429 | } |
426 | 430 | // } |
427 | 431 | }; |
428 | 432 | }; |
429 | 433 |
|
430 | | - tbb::parallel_for(size_t(0), birth_corners_.size(), todo(birth_corners_)); |
| 434 | + tbb::parallel_for(std::size_t(0), birth_corners_.size(), todo(birth_corners_)); |
431 | 435 | if (death_corners_.num_generators() == 0) return; |
432 | | - tbb::parallel_for(size_t(0), death_corners_.size(), todo(death_corners_)); |
| 436 | + tbb::parallel_for(std::size_t(0), death_corners_.size(), todo(death_corners_)); |
433 | 437 | }; |
434 | 438 |
|
435 | 439 | void snap_to_integers() { |
|
0 commit comments