Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e95eb6cb642b
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b3863b38a0b3
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 27, 2019

  1. Fix problems found on Linux.

    pleroy committed Apr 27, 2019
    Copy the full SHA
    9ae5b70 View commit details
  2. Typo.

    pleroy committed Apr 27, 2019
    Copy the full SHA
    58a0a03 View commit details
  3. Merge pull request #2145 from pleroy/Linux

    Fix problems found on Linux
    pleroy authored Apr 27, 2019
    Copy the full SHA
    b3863b3 View commit details
Showing with 10 additions and 7 deletions.
  1. +1 −1 astronomy/standard_product_3.cpp
  2. +1 −1 numerics/finite_difference.hpp
  3. +6 −5 numerics/finite_difference_body.hpp
  4. +2 −0 numerics/finite_difference_test.cpp
2 changes: 1 addition & 1 deletion astronomy/standard_product_3.cpp
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ StandardProduct3::StandardProduct3(

// The specification uses 1-based column indices, and column ranges with
// bounds included.
auto const column = [&line, &location, line_number](int const index) {
auto const column = [&line, &location](int const index) {
CHECK(line.has_value()) << location;
CHECK_LT(index - 1, line->size()) << location;
return (*line)[index - 1];
2 changes: 1 addition & 1 deletion numerics/finite_difference.hpp
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ using quantities::Difference;
// The error on the derivative is 𝒪(hⁿ⁻¹) as h → 0.
// If f is a polynomial of degree less than or equal to n - 1, the result is
// exact up to rounding errors.
template<typename Value, typename Argument, int n>
template<typename Value, typename Argument, std::size_t n>
Derivative<Value, Argument> FiniteDifference(
std::array<Value, n> const& values,
Argument const& step,
11 changes: 6 additions & 5 deletions numerics/finite_difference_body.hpp
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ namespace principia {
namespace numerics {
namespace internal_finite_difference {

template<typename Value, typename Argument, int n>
template<typename Value, typename Argument, std::size_t n>
Derivative<Value, Argument> FiniteDifference(
std::array<Value, n> const& values,
Argument const& step,
@@ -20,9 +20,10 @@ Derivative<Value, Argument> FiniteDifference(
// For the central difference formula, aᵢ = - aₙ₋ᵢ₋₁; in particular, for
// i = (n - 1) / 2 (the central coefficient), aᵢ = -aᵢ: the central value is
// unused.
// We thus evaluate the sum Σᵢ aᵢ f(xᵢ), with i runnning from 0 to n - 1, as
// Σⱼ aⱼ (f(xⱼ) - f(xₙ₋ⱼ₋₁)), with j running from 0 to (n - 3) / 2.
for (int j = 0; j <= (n - 3) / 2; ++j) {
// We thus evaluate the sum Σᵢ aᵢ f(xᵢ), with i running from 0 to n - 1, as
// Σⱼ aⱼ (f(xⱼ) - f(xₙ₋ⱼ₋₁)), with j running from 0 to (n - 3) / 2. Which
// we cannot write naively because n is unsigned.
for (int j = 0; 2 * j + 3 <= n; ++j) {
sum += numerators[j] * (values[j] - values[n - j - 1]);
}
return sum / (denominator * step);
@@ -33,7 +34,7 @@ Derivative<Value, Argument> FiniteDifference(
// where the sum over j runs from 0 to n - 2, and the sum over
// k runs from 0 to j.
double numerator = 0;
for (int j = 0; j <= n - 2; ++j) {
for (int j = 0; j + 2 <= n; ++j) {
numerator += numerators[j];
sum += numerator * (values[j] - values[j + 1]);
}
2 changes: 2 additions & 0 deletions numerics/finite_difference_test.cpp
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ TYPED_TEST_CASE(FiniteDifferenceTest, UpTo9);

// Polynomials of degree up to n - 1, differentiated exactly.
TYPED_TEST(FiniteDifferenceTest, LowDegreePolynomials) {
constexpr int n = TestFixture::n;
std::array<double, n> values;
constexpr double h = 3;
static constexpr std::int64_t max_bits =
@@ -63,6 +64,7 @@ TYPED_TEST(FiniteDifferenceTest, LowDegreePolynomials) {
// Polynomial of degree n, differentiated approximately, with convergence order
// n - 1.
TYPED_TEST(FiniteDifferenceTest, HighDegreePolynomial) {
constexpr int n = TestFixture::n;
std::array<double, n> values;
for (int j = 0; j < n; ++j) {
std::vector<double> log_steps;