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

sxs-collaboration / spectre / 4235749111

pending completion
4235749111

push

github

GitHub
Merge pull request #3142 from nilsvu/reftags_args

9 of 9 new or added lines in 3 files covered. (100.0%)

63847 of 66538 relevant lines covered (95.96%)

468412.87 hits per line

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

97.06
/src/NumericalAlgorithms/Interpolation/PredictedZeroCrossing.cpp
1
// Distributed under the MIT License.
2
// See LICENSE.txt for details.
3

4
#include "NumericalAlgorithms/Interpolation/PredictedZeroCrossing.hpp"
5

6
#include <algorithm>
7
#include <deque>
8
#include <vector>
9

10
#include "NumericalAlgorithms/Interpolation/LinearRegression.hpp"
11

12
namespace intrp {
13

14
double predicted_zero_crossing_value(const std::vector<double>& x_values,
11✔
15
                                     const std::vector<double>& y_values) {
16
  ASSERT(*std::max_element(x_values.begin(), x_values.end()) <= 0.0,
11✔
17
         "predicted_zero_crossing_value assumes that the x values are "
18
         "non-positive. This assumption is not necessary for the fit, but "
19
         "it is necessary to make sense of the special treatment of the "
20
         "return type for when the error bars are large.");
21

22
  const auto [intercept, slope, delta_intercept, delta_slope] =
23
      linear_regression(x_values, y_values);
11✔
24

25
  // See the doxygen comments for details of the implementation.
26
  // For now, set all the x's to zero if denominators are zero.
27
  const double x_best_fit = slope == 0.0 ? 0.0 : -intercept / slope;
11✔
28
  const double x0 =
11✔
29
      slope + delta_slope == 0.0
11✔
30
          ? 0.0
11✔
31
          : -(intercept - delta_intercept) / (slope + delta_slope);
11✔
32
  const double x1 =
11✔
33
      slope + delta_slope == 0.0
11✔
34
          ? 0.0
11✔
35
          : -(intercept + delta_intercept) / (slope + delta_slope);
11✔
36
  const double x2 =
11✔
37
      slope - delta_slope == 0.0
11✔
38
          ? 0.0
11✔
39
          : -(intercept - delta_intercept) / (slope - delta_slope);
11✔
40
  const double x3 =
11✔
41
      slope - delta_slope == 0.0
11✔
42
          ? 0.0
11✔
43
          : -(intercept + delta_intercept) / (slope - delta_slope);
11✔
44
  if ((x_best_fit > 0.0 and x1 > 0.0 and x2 > 0.0 and x3 > 0.0 and x0 > 0.0) or
11✔
45
      (x_best_fit < 0.0 and x1 < 0.0 and x2 < 0.0 and x3 < 0.0 and x0 < 0.0)) {
×
46
    return x_best_fit;
10✔
47
  }
48
  return 0.0;  // That is, assign no crossing value at all
1✔
49
}
50

51
DataVector predicted_zero_crossing_value(
4✔
52
    const std::deque<double>& x_values,
53
    const std::deque<DataVector>& y_values) {
54
  ASSERT(x_values.size() == y_values.size(),
4✔
55
         "The x_values and y_values must be of the same size");
56
  DataVector result(y_values.front().size());
4✔
57

58
  const std::vector<double> tmp_x_values(x_values.begin(), x_values.end());
8✔
59
  std::vector<double> tmp_y_values(x_values.size());
8✔
60
  for (size_t i = 0; i < result.size(); i++) {
13✔
61
    for (size_t j = 0; j < tmp_y_values.size(); j++) {
99✔
62
      tmp_y_values[j] = y_values[j][i];
180✔
63
    }
64
    result[i] = predicted_zero_crossing_value(tmp_x_values, tmp_y_values);
18✔
65
  }
66

67
  return result;
8✔
68
}
69

70
}  // namespace intrp
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

© 2025 Coveralls, Inc