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

Commits on Oct 12, 2020

  1. Add Norm².

    pleroy committed Oct 12, 2020
    Copy the full SHA
    ca91b10 View commit details
  2. Use Norm².

    pleroy committed Oct 12, 2020
    Copy the full SHA
    1a175c9 View commit details
  3. Copy the full SHA
    b670736 View commit details
  4. Copy the full SHA
    f8bdc8d View commit details
  5. A bug fix, but the values are not generated in an order suitable for …

    …reverse bit ordering.
    pleroy committed Oct 12, 2020
    Copy the full SHA
    12d662b View commit details
  6. Copy the full SHA
    00e6483 View commit details
  7. Copy the full SHA
    25b683b View commit details
  8. Comment caching.

    pleroy committed Oct 12, 2020
    Copy the full SHA
    1aa1e2d View commit details

Commits on Oct 13, 2020

  1. Back to 2^p + 1.

    pleroy committed Oct 13, 2020
    Copy the full SHA
    f4bfceb View commit details
  2. Tolerances and lint.

    pleroy committed Oct 13, 2020
    Copy the full SHA
    07448c4 View commit details
  3. After egg's review.

    pleroy committed Oct 13, 2020
    Copy the full SHA
    035a2c5 View commit details
  4. After egg's 2nd review.

    pleroy committed Oct 13, 2020
    Copy the full SHA
    64522ea View commit details
  5. Merge pull request #2761 from pleroy/Optimization

    Optimization of integration
    pleroy authored Oct 13, 2020
    Copy the full SHA
    6a5c01b View commit details
4 changes: 4 additions & 0 deletions base/bits_body.hpp
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@ constexpr int PowerOf2Le(int const n) {
}

constexpr int BitReversedIncrement(int const n, int const bits) {
if (bits == 0) {
CONSTEXPR_DCHECK(n == 0);
return 0;
}
CONSTEXPR_DCHECK(n >= 0 && n < 1 << bits);
CONSTEXPR_DCHECK(bits > 0 && bits < 32);
// [War03], chapter 7.1 page 105.
2 changes: 2 additions & 0 deletions base/bits_test.cpp
Original file line number Diff line number Diff line change
@@ -41,6 +41,8 @@ TEST(BitsTest, BitReversedIncrement) {
EXPECT_EQ(0x2, BitReversedIncrement(0xC, 4));
EXPECT_EQ(0x3, BitReversedIncrement(0xD, 4));
EXPECT_EQ(0x1, BitReversedIncrement(0xE, 4));

EXPECT_EQ(0, BitReversedIncrement(0, 0));
}

} // namespace base
5 changes: 2 additions & 3 deletions geometry/complexification_body.hpp
Original file line number Diff line number Diff line change
@@ -35,9 +35,8 @@ Complexification<Vector> Complexification<Vector>::Conjugate() const {
template<typename Vector>
typename Hilbert<Vector>::InnerProductType Complexification<Vector>::Norm²()
const {
// TODO(egg): Hilbert::Norm².
return Hilbert<Vector>::InnerProduct(real_part_, real_part_) +
Hilbert<Vector>::InnerProduct(imaginary_part_, imaginary_part_);
return Hilbert<Vector>::Norm²(real_part_) +
Hilbert<Vector>::Norm²(imaginary_part_);
}

template<typename Vector>
10 changes: 6 additions & 4 deletions geometry/hilbert.hpp
Original file line number Diff line number Diff line change
@@ -45,11 +45,12 @@ struct Hilbert<T, T, std::enable_if_t<is_quantity_v<T>>>
using InnerProductType = Square<T>;
static InnerProductType InnerProduct(T const& t1, T const& t2);

using Norm²Type = InnerProductType;
static Norm²Type Norm²(T const& t);

using NormType = T;
static NormType Norm(T const& t);

// TODO(egg): Hilbert::Norm².

using NormalizedType = double;
};

@@ -77,11 +78,12 @@ struct Hilbert<T, T,
decltype(InnerProduct(std::declval<T>(), std::declval<T>()));
static InnerProductType InnerProduct(T const& t1, T const& t2);

using Norm²Type = InnerProductType;
static Norm²Type Norm²(T const& t);

using NormType = decltype(std::declval<T>().Norm());
static NormType Norm(T const& t);

// TODO(egg): Hilbert::Norm².

using NormalizedType = Quotient<T, NormType>;
};

17 changes: 16 additions & 1 deletion geometry/hilbert_body.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@


#pragma once

#include "geometry/hilbert.hpp"

#include "geometry/grassmann.hpp"
#include "quantities/elementary_functions.hpp"
#include "hilbert.hpp"

namespace principia {
namespace geometry {
@@ -27,6 +28,12 @@ auto Hilbert<T, T, std::enable_if_t<is_quantity_v<T>>>::
return t1 * t2;
}

template<typename T>
auto Hilbert<T, T, std::enable_if_t<is_quantity_v<T>>>::Norm²(T const& t)
-> Norm²Type {
return t * t;
}

template<typename T>
auto Hilbert<T, T, std::enable_if_t<is_quantity_v<T>>>::Norm(
T const& t) -> NormType {
@@ -53,6 +60,14 @@ auto Hilbert<T, T,
return internal_grassmann::InnerProduct(t1, t2);
}

template<typename T>
auto Hilbert<T, T,
std::void_t<decltype(InnerProduct(std::declval<T>(),
std::declval<T>()))>>::
Norm²(T const& t) -> Norm²Type {
return t.Norm²();
}

template<typename T>
auto Hilbert<T, T,
std::void_t<decltype(InnerProduct(std::declval<T>(),
16 changes: 11 additions & 5 deletions geometry/hilbert_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "geometry/hilbert.hpp"
#include "geometry/hilbert.hpp"

#include <type_traits>

@@ -37,7 +37,8 @@ TEST(HilbertTest, ScalarTypes) {
static_assert(H2::dimension == 1);
static_assert(std::is_same_v<Length, H2::InnerProductType>);
#if 0
H2::NormType h2;
H2::NormType h2a;
H2::Norm²Type h2b;
#endif

using H3 = Hilbert<Length, Length>;
@@ -56,7 +57,8 @@ TEST(HilbertTest, VectorTypes) {
static_assert(H2::dimension == 3);
static_assert(std::is_same_v<Length, H2::InnerProductType>);
#if 0
H2::NormType h2;
H2::NormType h2a;
H2::Norm²Type h2b;
#endif

using H3 = Hilbert<Trivector<Length, World>, Trivector<Length, World>>;
@@ -73,7 +75,8 @@ TEST(HilbertTest, ScalarValues) {
using H2 = Hilbert<double, Length>;
EXPECT_EQ(6 * Metre, H2::InnerProduct(3, 2 * Metre));
#if 0
auto h2 = H2::Norm(6 * Metre);
auto h2a = H2::Norm(6 * Metre);
auto h2b = H2::Norm²(6 * Metre);
#endif

using H3 = Hilbert<Length, Length>;
@@ -92,7 +95,8 @@ TEST(HilbertTest, VectorValues) {
using H2 = Hilbert<Vector<double, World>, Vector<Length, World>>;
EXPECT_EQ(-32 * Metre, H2::InnerProduct(v1, v2));
#if 0
auto h2 = H2::Norm(v2);
auto h2a = H2::Norm(v2);
auto h2b = H2::Norm²(v2);
#endif

using H3 = Hilbert<Vector<Length, World>, Vector<Length, World>>;
@@ -105,9 +109,11 @@ TEST(HilbertTest, OneParameter) {

using H1 = Hilbert<double>;
EXPECT_EQ(2, H1::Norm(2));
EXPECT_EQ(4, H1::Norm²(2));

using H3 = Hilbert<Vector<Length, World>>;
EXPECT_EQ(Sqrt(77) * Metre, H3::Norm(v2));
EXPECT_EQ(77 * Metre * Metre, H3::Norm²(v2));
}

TEST(HilbertTest, BadParameters) {
1 change: 0 additions & 1 deletion numerics/frequency_analysis_body.hpp
Original file line number Diff line number Diff line change
@@ -86,7 +86,6 @@ IncrementalProjection(Function const& function,
Instant const& t_max) {
using Value = std::invoke_result_t<Function, Instant>;
using Norm = typename Hilbert<Value>::NormType;
using Norm² = typename Hilbert<Value>::InnerProductType;
using Normalized = typename Hilbert<Value>::NormalizedType;
using Series = PoissonSeries<Value, degree_, Evaluator>;

2 changes: 0 additions & 2 deletions numerics/frequency_analysis_test.cpp
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@

#include "geometry/frame.hpp"
#include "geometry/grassmann.hpp"
#include "geometry/hilbert.hpp"
#include "geometry/named_quantities.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -31,7 +30,6 @@ namespace frequency_analysis {
using geometry::Displacement;
using geometry::Frame;
using geometry::Handedness;
using geometry::Hilbert;
using geometry::Inertial;
using geometry::Instant;
using geometry::Vector;
2 changes: 1 addition & 1 deletion numerics/poisson_series_body.hpp
Original file line number Diff line number Diff line change
@@ -365,7 +365,7 @@ PoissonSeries<Value, degree_, Evaluator>::Norm(
(t_max - t_min) * max_ω / (2 * π * Radian)));

auto integrand = [this, &weight](Instant const& t) {
return Hilbert<Value>::InnerProduct((*this)(t), (*this)(t)) * weight(t);
return Hilbert<Value>::Norm²((*this)(t)) * weight(t);
};
return Sqrt(quadrature::AutomaticClenshawCurtis(
integrand,
Loading