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: 68fff005c79f
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ffe3a73ef6e3
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 23, 2018

  1. Copy the full SHA
    f50b710 View commit details

Commits on Jan 24, 2018

  1. Lint.

    pleroy committed Jan 24, 2018
    Copy the full SHA
    5df435c View commit details
  2. Merge pull request #1696 from pleroy/Degree

    A function to retrieve the degree of a polynomial
    pleroy authored Jan 24, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ffe3a73 View commit details
Showing with 25 additions and 10 deletions.
  1. +8 −2 numerics/polynomial.hpp
  2. +15 −8 numerics/polynomial_body.hpp
  3. +2 −0 numerics/polynomial_test.cpp
10 changes: 8 additions & 2 deletions numerics/polynomial.hpp
Original file line number Diff line number Diff line change
@@ -66,11 +66,15 @@ class Polynomial {
virtual Derivative<Value, Argument> EvaluateDerivative(
Argument const& argument) const = 0;

// Only useful for benchmarking or analyzing performance. Do not use in real
// code.
virtual int degree() const = 0;

protected:
virtual ~Polynomial() = default;
};

template<typename Value, typename Argument, int degree,
template<typename Value, typename Argument, int degree_,
template<typename, typename, int> class Evaluator>
class PolynomialInMonomialBasis : public Polynomial<Value, Argument> {
public:
@@ -81,14 +85,16 @@ class PolynomialInMonomialBasis : public Polynomial<Value, Argument> {
using Coefficients =
NthDerivatives<Value,
Argument,
std::make_integer_sequence<int, degree + 1>>;
std::make_integer_sequence<int, degree_ + 1>>;

explicit PolynomialInMonomialBasis(Coefficients const& coefficients);

FORCE_INLINE(inline) Value Evaluate(Argument const& argument) const override;
FORCE_INLINE(inline) Derivative<Value, Argument> EvaluateDerivative(
Argument const& argument) const override;

constexpr int degree() const override;

private:
Coefficients coefficients_;
};
23 changes: 15 additions & 8 deletions numerics/polynomial_body.hpp
Original file line number Diff line number Diff line change
@@ -8,28 +8,35 @@ namespace principia {
namespace numerics {
namespace internal_polynomial {

template<typename Value, typename Argument, int degree,
template<typename Value, typename Argument, int degree_,
template<typename, typename, int> class Evaluator>
PolynomialInMonomialBasis<Value, Argument, degree, Evaluator>::
PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>::
PolynomialInMonomialBasis(Coefficients const& coefficients)
: coefficients_(coefficients) {}

template<typename Value, typename Argument, int degree,
template<typename Value, typename Argument, int degree_,
template<typename, typename, int> class Evaluator>
Value PolynomialInMonomialBasis<Value, Argument, degree, Evaluator>::
Value PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>::
Evaluate(Argument const& argument) const {
return Evaluator<Value, Argument, degree>::Evaluate(coefficients_, argument);
return Evaluator<Value, Argument, degree_>::Evaluate(coefficients_, argument);
}

template<typename Value, typename Argument, int degree,
template<typename Value, typename Argument, int degree_,
template<typename, typename, int> class Evaluator>
Derivative<Value, Argument>
PolynomialInMonomialBasis<Value, Argument, degree, Evaluator>::
PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>::
EvaluateDerivative(Argument const& argument) const {
return Evaluator<Value, Argument, degree>::EvaluateDerivative(
return Evaluator<Value, Argument, degree_>::EvaluateDerivative(
coefficients_, argument);
}

template<typename Value, typename Argument, int degree_,
template<typename, typename, int> class Evaluator>
constexpr int
PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>::degree() const {
return degree_;
}

} // namespace internal_polynomial
} // namespace numerics
} // namespace principia
2 changes: 2 additions & 0 deletions numerics/polynomial_test.cpp
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ TEST_F(PolynomialTest, Coefficients) {
// Check that a polynomial can be constructed and evaluated.
TEST_F(PolynomialTest, Evaluate2) {
P2 p(coefficients_);
EXPECT_EQ(2, p.degree());
Displacement<World> const d = p.Evaluate(0.5 * Second);
Velocity<World> const v = p.EvaluateDerivative(0.5 * Second);
EXPECT_THAT(d, AlmostEquals(Displacement<World>({0.25 * Metre,
@@ -79,6 +80,7 @@ TEST_F(PolynomialTest, Evaluate2) {
TEST_F(PolynomialTest, Evaluate17) {
P17::Coefficients const coefficients;
P17 p(coefficients);
EXPECT_EQ(17, p.degree());
Displacement<World> const d = p.Evaluate(0.5 * Second);
EXPECT_THAT(d, AlmostEquals(Displacement<World>({0 * Metre,
0 * Metre,