From a97e2e307e43a3d59451130462f58bb045447ddf Mon Sep 17 00:00:00 2001 From: pleroy Date: Mon, 22 Apr 2024 18:32:09 +0200 Subject: [PATCH 01/14] Lattices. --- numerics/lattice.hpp | 7 +++++++ numerics/numerics.vcxproj | 1 + numerics/numerics.vcxproj.filters | 9 ++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 numerics/lattice.hpp diff --git a/numerics/lattice.hpp b/numerics/lattice.hpp new file mode 100644 index 0000000000..119be99060 --- /dev/null +++ b/numerics/lattice.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace principia { +namespace numerics { +namespace _lattice { +} +}} diff --git a/numerics/numerics.vcxproj b/numerics/numerics.vcxproj index 2e49ff5485..9d06488190 100644 --- a/numerics/numerics.vcxproj +++ b/numerics/numerics.vcxproj @@ -24,6 +24,7 @@ + diff --git a/numerics/numerics.vcxproj.filters b/numerics/numerics.vcxproj.filters index 0dffd31c0d..e543455bba 100644 --- a/numerics/numerics.vcxproj.filters +++ b/numerics/numerics.vcxproj.filters @@ -113,9 +113,6 @@ Header Files - - Source Files - Header Files @@ -266,6 +263,9 @@ Source Files + + Header Files + @@ -388,6 +388,9 @@ Test Files + + Source Files + From f05786bd6f27786230a63026b045a0ee3f30c1a5 Mon Sep 17 00:00:00 2001 From: pleroy Date: Mon, 22 Apr 2024 19:37:21 +0200 Subject: [PATCH 02/14] A first skeleton of LLL. --- numerics/lattice.hpp | 7 ---- numerics/lattices.hpp | 25 ++++++++++++ numerics/lattices_body.hpp | 81 ++++++++++++++++++++++++++++++++++++++ numerics/numerics.vcxproj | 3 +- 4 files changed, 108 insertions(+), 8 deletions(-) delete mode 100644 numerics/lattice.hpp create mode 100644 numerics/lattices.hpp create mode 100644 numerics/lattices_body.hpp diff --git a/numerics/lattice.hpp b/numerics/lattice.hpp deleted file mode 100644 index 119be99060..0000000000 --- a/numerics/lattice.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace principia { -namespace numerics { -namespace _lattice { -} -}} diff --git a/numerics/lattices.hpp b/numerics/lattices.hpp new file mode 100644 index 0000000000..23f78949b8 --- /dev/null +++ b/numerics/lattices.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "numerics/concepts.hpp" + +namespace principia { +namespace numerics { +namespace _lattices { +namespace internal { + +using namespace principia::numerics::_concepts; + +//TODO(phl):Should this be integral? +template + requires two_dimensional +Matrix LenstraLenstraLovįsz(Matrix const& L); + +} // namespace internal + +using internal::LenstraLenstraLovįsz; + +} // namespace _lattices +} // namespace numerics +} // namespace principia + +#include "numerics/lattices_body.hpp" diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp new file mode 100644 index 0000000000..fe21d85e8a --- /dev/null +++ b/numerics/lattices_body.hpp @@ -0,0 +1,81 @@ +#pragma once + +#include "numerics/lattices.hpp" + +#include "numerics/fixed_arrays.hpp" +#include "numerics/matrix_computations.hpp" +#include "numerics/matrix_views.hpp" +#include "numerics/unbounded_arrays.hpp" +#include "quantities/elementary_functions.hpp" + +namespace principia { +namespace numerics { +namespace _lattices { +namespace internal { + +using namespace principia::numerics::_fixed_arrays; +using namespace principia::numerics::_matrix_computations; +using namespace principia::numerics::_matrix_views; +using namespace principia::numerics::_unbounded_arrays; +using namespace principia::quantities::_elementary_functions; + +template +struct LenstraLenstraLovĆ”szGenerator; + +template +struct LenstraLenstraLovĆ”szGenerator> {}; + +template +struct LenstraLenstraLovĆ”szGenerator< + FixedMatrix> {}; + +template + requires two_dimensional && + std::is_integral_v +Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { + //TODO(phl):Rows/columns confusion. + using G = LenstraLenstraLovĆ”szGenerator; + auto const n = L.columns(); + auto const m = L.rows(); + auto v = L; + for (int k = 1; k < n;) { + auto const qr = UnitriangularGramSchmidt(L); + auto vā‚– = ColumnView{.matrix = v, + .first_row = 0, + .last_row = m, + .column = k}; + for (int j = k - 1; j >= 0; --j) { + auto const Ī¼ā‚–ā±¼ = qr.R(j, k); + auto vā±¼ = ColumnView{.matrix = v, + .first_row = 0, + .last_row = m, + .column = j}; + vā‚– -= std::round(Ī¼ā‚–ā±¼) * typename G::Lvector(vā±¼); + } + auto const Ī¼ā‚–ā‚–ā‚‹ā‚ = qr.R(k - 1, k); + auto všŒŸā‚– = ColumnView{matrix = qr.Q, + .first_row = 0, + .last_row = m, + .column = k}; + auto všŒŸā‚–ā‚‹ā‚ = ColumnView{matrix = qr.Q, + .first_row = 0, + .last_row = m, + .column = k - 1}; + if (všŒŸā‚–.NormĀ²() >= (0.75 - Pow<2>(Ī¼ā‚–ā‚–ā‚‹ā‚)) * všŒŸā‚–ā‚‹ā‚.NormĀ²()) { + ++k; + } else { + auto vā‚–ā‚‹ā‚ = ColumnView{.matrix = v, + .first_row = 0, + .last_row = m, + .column = k - 1}; + std::swap(vā‚–ā‚‹ā‚, vā‚–); + k = std::max(k - 1, 1); + } + } + return v; +} + +} // namespace internal +} // namespace _lattices +} // namespace numerics +} // namespace principia diff --git a/numerics/numerics.vcxproj b/numerics/numerics.vcxproj index 9d06488190..47fe024bfa 100644 --- a/numerics/numerics.vcxproj +++ b/numerics/numerics.vcxproj @@ -24,7 +24,8 @@ - + + From 1f800eccd70f210beeb6536b876b2a1ced518a7b Mon Sep 17 00:00:00 2001 From: pleroy Date: Mon, 22 Apr 2024 22:03:35 +0200 Subject: [PATCH 03/14] Move files. --- numerics/numerics.vcxproj.filters | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/numerics/numerics.vcxproj.filters b/numerics/numerics.vcxproj.filters index e543455bba..4a82e11bae 100644 --- a/numerics/numerics.vcxproj.filters +++ b/numerics/numerics.vcxproj.filters @@ -263,9 +263,12 @@ Source Files - + Header Files + + Source Files + From 024d0f1d40acc65c38985d3fef221f90ed076032 Mon Sep 17 00:00:00 2001 From: pleroy Date: Mon, 22 Apr 2024 23:00:44 +0200 Subject: [PATCH 04/14] A test that fails. --- numerics/lattices.hpp | 4 +-- numerics/lattices_body.hpp | 45 ++++++++++++++++++------------- numerics/lattices_test.cpp | 28 +++++++++++++++++++ numerics/matrix_views.hpp | 4 +++ numerics/matrix_views_body.hpp | 9 +++++++ numerics/numerics.vcxproj | 1 + numerics/numerics.vcxproj.filters | 3 +++ 7 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 numerics/lattices_test.cpp diff --git a/numerics/lattices.hpp b/numerics/lattices.hpp index 23f78949b8..1be2d4a81b 100644 --- a/numerics/lattices.hpp +++ b/numerics/lattices.hpp @@ -12,11 +12,11 @@ using namespace principia::numerics::_concepts; //TODO(phl):Should this be integral? template requires two_dimensional -Matrix LenstraLenstraLovįsz(Matrix const& L); +Matrix LenstraLenstraLovĆ”sz(Matrix const& L); } // namespace internal -using internal::LenstraLenstraLovįsz; +using internal::LenstraLenstraLovĆ”sz; } // namespace _lattices } // namespace numerics diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index fe21d85e8a..736489c154 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -5,6 +5,7 @@ #include "numerics/fixed_arrays.hpp" #include "numerics/matrix_computations.hpp" #include "numerics/matrix_views.hpp" +#include "numerics/transposed_view.hpp" #include "numerics/unbounded_arrays.hpp" #include "quantities/elementary_functions.hpp" @@ -16,6 +17,7 @@ namespace internal { using namespace principia::numerics::_fixed_arrays; using namespace principia::numerics::_matrix_computations; using namespace principia::numerics::_matrix_views; +using namespace principia::numerics::_transposed_view; using namespace principia::numerics::_unbounded_arrays; using namespace principia::quantities::_elementary_functions; @@ -23,15 +25,18 @@ template struct LenstraLenstraLovĆ”szGenerator; template -struct LenstraLenstraLovĆ”szGenerator> {}; +struct LenstraLenstraLovĆ”szGenerator> { + using Vector = UnboundedVector; +}; -template +template struct LenstraLenstraLovĆ”szGenerator< - FixedMatrix> {}; + FixedMatrix> { + using Vector = FixedVector; +}; template - requires two_dimensional && - std::is_integral_v + requires two_dimensional Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { //TODO(phl):Rows/columns confusion. using G = LenstraLenstraLovĆ”szGenerator; @@ -39,36 +44,38 @@ Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { auto const m = L.rows(); auto v = L; for (int k = 1; k < n;) { - auto const qr = UnitriangularGramSchmidt(L); +LOG(ERROR)<<"k = "<= 0; --j) { auto const Ī¼ā‚–ā±¼ = qr.R(j, k); auto vā±¼ = ColumnView{.matrix = v, - .first_row = 0, - .last_row = m, - .column = j}; - vā‚– -= std::round(Ī¼ā‚–ā±¼) * typename G::Lvector(vā±¼); + .first_row = 0, + .last_row = m - 1, + .column = j}; + vā‚– -= std::round(Ī¼ā‚–ā±¼) * typename G::Vector(vā±¼); } auto const Ī¼ā‚–ā‚–ā‚‹ā‚ = qr.R(k - 1, k); - auto všŒŸā‚– = ColumnView{matrix = qr.Q, + auto všŒŸā‚– = ColumnView{.matrix = qr.Q, .first_row = 0, - .last_row = m, + .last_row = m - 1, .column = k}; - auto všŒŸā‚–ā‚‹ā‚ = ColumnView{matrix = qr.Q, - .first_row = 0, - .last_row = m, - .column = k - 1}; + auto všŒŸā‚–ā‚‹ā‚ = ColumnView{.matrix = qr.Q, + .first_row = 0, + .last_row = m - 1, + .column = k - 1}; if (všŒŸā‚–.NormĀ²() >= (0.75 - Pow<2>(Ī¼ā‚–ā‚–ā‚‹ā‚)) * všŒŸā‚–ā‚‹ā‚.NormĀ²()) { ++k; } else { +LOG(ERROR)<<"Swap"; auto vā‚–ā‚‹ā‚ = ColumnView{.matrix = v, .first_row = 0, - .last_row = m, + .last_row = m - 1, .column = k - 1}; - std::swap(vā‚–ā‚‹ā‚, vā‚–); + SwapColumns(vā‚–ā‚‹ā‚, vā‚–); k = std::max(k - 1, 1); } } diff --git a/numerics/lattices_test.cpp b/numerics/lattices_test.cpp new file mode 100644 index 0000000000..8f02624a18 --- /dev/null +++ b/numerics/lattices_test.cpp @@ -0,0 +1,28 @@ +#include "numerics/lattices.hpp" + +#include "gtest/gtest.h" +#include "numerics/fixed_arrays.hpp" + +namespace principia { +namespace numerics { +namespace _lattices { + +using namespace principia::numerics::_fixed_arrays; +using namespace principia::numerics::_lattices; + +class LatticesTest : public ::testing::Test {}; + +TEST_F(LatticesTest, Example_7_75) { + FixedMatrix l({19, 15, 43, 20, 0, 48, + 2, 42, 15, 44, 48, 33, + 32, 11, 0, 44, 35, 32, + 46, 0, 24, 0, 16, 9, + 3, 3, 4, 18, 31, 1, + 33, 24, 16, 15, 31, 29}); + auto const reduced = LenstraLenstraLovĆ”sz(l); + LOG(ERROR)< +void SwapColumns(ColumnView& m1, ColumnView& m2); + template Product operator*( TransposedView> const& left, @@ -117,6 +120,7 @@ std::ostream& operator<<(std::ostream& out, using internal::BlockView; using internal::ColumnView; +using internal::SwapColumns; } // namespace _matrix_views } // namespace numerics diff --git a/numerics/matrix_views_body.hpp b/numerics/matrix_views_body.hpp index 613d9936dc..7d410c7ed9 100644 --- a/numerics/matrix_views_body.hpp +++ b/numerics/matrix_views_body.hpp @@ -232,6 +232,15 @@ constexpr auto ColumnView::size() const -> int { return last_row - first_row + 1; } +template +void SwapColumns(ColumnView& m1, ColumnView& m2) { + DCHECK_EQ(m1.first_row, m2.first_row); + DCHECK_EQ(m1.last_row, m2.last_row); + for (int i = 0; i < m1.size(); ++i) { + std::swap(m1[i], m2[i]); + } +} + template Product operator*( TransposedView> const& left, diff --git a/numerics/numerics.vcxproj b/numerics/numerics.vcxproj index 47fe024bfa..39b447ca2e 100644 --- a/numerics/numerics.vcxproj +++ b/numerics/numerics.vcxproj @@ -121,6 +121,7 @@ + diff --git a/numerics/numerics.vcxproj.filters b/numerics/numerics.vcxproj.filters index 4a82e11bae..51e2a46941 100644 --- a/numerics/numerics.vcxproj.filters +++ b/numerics/numerics.vcxproj.filters @@ -394,6 +394,9 @@ Source Files + + Test Files + From bd4e7f7fa534c19245eaeac646f095b9cf9c76d7 Mon Sep 17 00:00:00 2001 From: pleroy Date: Mon, 22 Apr 2024 23:22:32 +0200 Subject: [PATCH 05/14] A correct but inefficient version. --- numerics/lattices_body.hpp | 6 ++---- numerics/lattices_test.cpp | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index 736489c154..4086937fd2 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -38,14 +38,12 @@ struct LenstraLenstraLovĆ”szGenerator< template requires two_dimensional Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { - //TODO(phl):Rows/columns confusion. using G = LenstraLenstraLovĆ”szGenerator; auto const n = L.columns(); auto const m = L.rows(); auto v = L; for (int k = 1; k < n;) { -LOG(ERROR)<<"k = "< l({19, 15, 43, 20, 0, 48, 2, 42, 15, 44, 48, 33, - 32, 11, 0, 44, 35, 32, - 46, 0, 24, 0, 16, 9, + 32, 11, 0, 44, 35, 32, + 46, 0, 24, 0, 16, 9, 3, 3, 4, 18, 31, 1, - 33, 24, 16, 15, 31, 29}); + 33, 24, 16, 15, 31, 29}); + auto const reduced = LenstraLenstraLovĆ”sz(l); - LOG(ERROR)<({ 7, -20, 5, -6, -10, 7, + -12, 4, 2, -7, -24, 4, + -8, -9, 33, -20, 21, -9, + 4, 16, 0, -21, -15, -11, + 19, 13, 15, 8, -6, 1, + 9, 16, -9, -12, -11, 31})), + 0)); } } // namespace _lattices From cc03a5a418be4d993bc56ccc8cf410861d89ec18 Mon Sep 17 00:00:00 2001 From: pleroy Date: Tue, 23 Apr 2024 21:49:21 +0200 Subject: [PATCH 06/14] A faster implementation, probably completely broken. --- numerics/lattices.hpp | 5 ++ numerics/lattices_body.hpp | 124 +++++++++++++++++++++++++++++++++++++ numerics/lattices_test.cpp | 20 ++++++ 3 files changed, 149 insertions(+) diff --git a/numerics/lattices.hpp b/numerics/lattices.hpp index 1be2d4a81b..e91a388f4b 100644 --- a/numerics/lattices.hpp +++ b/numerics/lattices.hpp @@ -14,9 +14,14 @@ template requires two_dimensional Matrix LenstraLenstraLovĆ”sz(Matrix const& L); +template + requires two_dimensional +Matrix LenstraLenstraLovĆ”sz2(Matrix const& L); + } // namespace internal using internal::LenstraLenstraLovĆ”sz; +using internal::LenstraLenstraLovĆ”sz2; } // namespace _lattices } // namespace numerics diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index 4086937fd2..645be03322 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -2,24 +2,28 @@ #include "numerics/lattices.hpp" +#include "base/tags.hpp" #include "numerics/fixed_arrays.hpp" #include "numerics/matrix_computations.hpp" #include "numerics/matrix_views.hpp" #include "numerics/transposed_view.hpp" #include "numerics/unbounded_arrays.hpp" #include "quantities/elementary_functions.hpp" +#include "quantities/named_quantities.hpp" namespace principia { namespace numerics { namespace _lattices { namespace internal { +using namespace principia::base::_tags; using namespace principia::numerics::_fixed_arrays; using namespace principia::numerics::_matrix_computations; using namespace principia::numerics::_matrix_views; using namespace principia::numerics::_transposed_view; using namespace principia::numerics::_unbounded_arrays; using namespace principia::quantities::_elementary_functions; +using namespace principia::quantities::_named_quantities; template struct LenstraLenstraLovĆ”szGenerator; @@ -27,12 +31,16 @@ struct LenstraLenstraLovĆ”szGenerator; template struct LenstraLenstraLovĆ”szGenerator> { using Vector = UnboundedVector; + using DoubleMatrix = UnboundedMatrix; + using NormĀ²Vector = UnboundedVector>; }; template struct LenstraLenstraLovĆ”szGenerator< FixedMatrix> { using Vector = FixedVector; + using DoubleMatrix = FixedMatrix; + using NormĀ²Vector = FixedVector, rows>; }; template @@ -80,6 +88,122 @@ Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { return v; } +template +void Red(int const k, + int const l, + Matrix& v, + typename LenstraLenstraLovĆ”szGenerator::DoubleMatrix& Ī¼) { + if (Abs(Ī¼(k, l)) <= 0.5) { + return; + } + auto const m = std::round(Ī¼(k, l)); + auto vā‚– = {.matrix = v, + .first_row = 0, + .last_row = m - 1, + .column = k}; + auto vā‚— = {.matrix = v, + .first_row = 0, + .last_row = m - 1, + .column = l}; + vā‚– -= m * vā‚—; + Ī¼(k, l) -= m; + for (int i = 0; i < l - 1; ++i) { + Ī¼(k, i) -= m * Ī¼(l, i); + } +} + +template +void Swap(int const k, + int const k_max, + Matrix& v, + typename LenstraLenstraLovĆ”szGenerator::DoubleMatrix& Ī¼, + typename LenstraLenstraLovĆ”szGenerator::NormĀ²Vector& B) { + auto const n = v.columns(); + auto const m = v.rows();//TODO(phl)naming + auto vā‚– = ColumnView{.matrix = v, + .first_row = 0, + .last_row = m - 1, + .column = k}; + auto vā‚–ā‚‹ā‚ = ColumnView{.matrix = v, + .first_row = 0, + .last_row = m - 1, + .column = k - 1}; + SwapColumns(vā‚–, vā‚–ā‚‹ā‚); + for (int j = 0; j < k - 2; ++j) { + std::swap(Ī¼(k - 1, j), Ī¼(k, j)); + } + auto Ī¼ = Ī¼(k, k - 1); + auto B = B[k] + Pow<2>(Ī¼) * B[k - 1]; + Ī¼(k, k - 1) = Ī¼ * B[k - 1] / B; + B[k] = B[k - 1] * B[k] / B; + B[k - 1] = B; + for (int i = k + 1; i < k_max; ++i) { + auto const m = Ī¼(i, k); + Ī¼(i, k) = Ī¼(i, k - 1) - Ī¼ * m; + Ī¼(i, k - 1) = m + Ī¼(k, k - 1) * Ī¼(i, k); + } +} + +template + requires two_dimensional +Matrix LenstraLenstraLovĆ”sz2(Matrix const& L) { + using G = LenstraLenstraLovĆ”szGenerator; + auto const n = L.columns(); + auto const m = L.rows(); + Matrix v = L; + int k_max = 0; + Matrix všŒŸ; + typename G::DoubleMatrix Ī¼(uninitialized); + typename G::NormĀ²Vector B(uninitialized); + auto všŒŸā‚€ = ColumnView{.matrix = všŒŸ, + .first_row = 0, + .last_row = m - 1, + .column = 0}; + auto vā‚€ = ColumnView{.matrix = v, + .first_row = 0, + .last_row = m - 1, + .column = 0}; + všŒŸā‚€ = vā‚€; + B[0] = vā‚€.NormĀ²(); + for (int k = 1; k < n;) { + if (k > k_max) { + k_max = k; + auto všŒŸā‚– = ColumnView{.matrix = všŒŸ, + .first_row = 0, + .last_row = m - 1, + .column = k}; + auto vā‚– = ColumnView{.matrix = v, + .first_row = 0, + .last_row = m - 1, + .column = k}; + všŒŸā‚– = vā‚–; + for (int j = 0; j < k - 1; ++j) { + auto všŒŸā±¼ = ColumnView{.matrix = všŒŸ, + .first_row = 0, + .last_row = m - 1, + .column = j}; + Ī¼(k, j) = TransposedView{vā‚–} * všŒŸā±¼ / B[j]; + všŒŸā‚– -= typename G::Vector(Ī¼(k, j) * všŒŸā±¼); + } + B[k] = všŒŸā‚–.NormĀ²(); + } + for (;;) { + Red(k, k - 1, v, Ī¼); + if (B[k] < (0.75 - Pow<2>(Ī¼(k, k - 1))) * B[k - 1]) { + Swap(k, k_max, v, Ī¼, B); + k = std::max(k - 1, 1); + } else { + for (int l = k - 3; l >= 0; --l) { + Red(k, l, v, Ī¼); + } + ++k; + break; + } + } + } + return v; +} + } // namespace internal } // namespace _lattices } // namespace numerics diff --git a/numerics/lattices_test.cpp b/numerics/lattices_test.cpp index fc70eb5932..cedbef1b8a 100644 --- a/numerics/lattices_test.cpp +++ b/numerics/lattices_test.cpp @@ -35,6 +35,26 @@ TEST_F(LatticesTest, Example_7_75) { 0)); } +TEST_F(LatticesTest, Example_7_75b) { + FixedMatrix l({19, 15, 43, 20, 0, 48, + 2, 42, 15, 44, 48, 33, + 32, 11, 0, 44, 35, 32, + 46, 0, 24, 0, 16, 9, + 3, 3, 4, 18, 31, 1, + 33, 24, 16, 15, 31, 29}); + + auto const reduced = LenstraLenstraLovĆ”sz2(l); + EXPECT_THAT(reduced, + AlmostEquals( + (FixedMatrix({ 7, -20, 5, -6, -10, 7, + -12, 4, 2, -7, -24, 4, + -8, -9, 33, -20, 21, -9, + 4, 16, 0, -21, -15, -11, + 19, 13, 15, 8, -6, 1, + 9, 16, -9, -12, -11, 31})), + 0)); +} + } // namespace _lattices } // namespace numerics } // namespace principia From 151f513d0a486b0b3e7d09113c04b3290a521ed9 Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 24 Apr 2024 20:09:21 +0200 Subject: [PATCH 07/14] An implementation that compiles. --- numerics/lattices_body.hpp | 128 +++++++++++++++------------------ numerics/matrix_views.hpp | 2 + numerics/matrix_views_test.cpp | 16 +++++ 3 files changed, 77 insertions(+), 69 deletions(-) diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index 645be03322..fd00b0dfba 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -88,80 +88,70 @@ Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { return v; } -template -void Red(int const k, - int const l, - Matrix& v, - typename LenstraLenstraLovĆ”szGenerator::DoubleMatrix& Ī¼) { - if (Abs(Ī¼(k, l)) <= 0.5) { - return; - } - auto const m = std::round(Ī¼(k, l)); - auto vā‚– = {.matrix = v, - .first_row = 0, - .last_row = m - 1, - .column = k}; - auto vā‚— = {.matrix = v, - .first_row = 0, - .last_row = m - 1, - .column = l}; - vā‚– -= m * vā‚—; - Ī¼(k, l) -= m; - for (int i = 0; i < l - 1; ++i) { - Ī¼(k, i) -= m * Ī¼(l, i); - } -} - -template -void Swap(int const k, - int const k_max, - Matrix& v, - typename LenstraLenstraLovĆ”szGenerator::DoubleMatrix& Ī¼, - typename LenstraLenstraLovĆ”szGenerator::NormĀ²Vector& B) { - auto const n = v.columns(); - auto const m = v.rows();//TODO(phl)naming - auto vā‚– = ColumnView{.matrix = v, - .first_row = 0, - .last_row = m - 1, - .column = k}; - auto vā‚–ā‚‹ā‚ = ColumnView{.matrix = v, - .first_row = 0, - .last_row = m - 1, - .column = k - 1}; - SwapColumns(vā‚–, vā‚–ā‚‹ā‚); - for (int j = 0; j < k - 2; ++j) { - std::swap(Ī¼(k - 1, j), Ī¼(k, j)); - } - auto Ī¼ = Ī¼(k, k - 1); - auto B = B[k] + Pow<2>(Ī¼) * B[k - 1]; - Ī¼(k, k - 1) = Ī¼ * B[k - 1] / B; - B[k] = B[k - 1] * B[k] / B; - B[k - 1] = B; - for (int i = k + 1; i < k_max; ++i) { - auto const m = Ī¼(i, k); - Ī¼(i, k) = Ī¼(i, k - 1) - Ī¼ * m; - Ī¼(i, k - 1) = m + Ī¼(k, k - 1) * Ī¼(i, k); - } -} - template requires two_dimensional Matrix LenstraLenstraLovĆ”sz2(Matrix const& L) { using G = LenstraLenstraLovĆ”szGenerator; auto const n = L.columns(); - auto const m = L.rows(); + auto const rows = L.rows(); Matrix v = L; - int k_max = 0; Matrix všŒŸ; typename G::DoubleMatrix Ī¼(uninitialized); typename G::NormĀ²Vector B(uninitialized); - auto všŒŸā‚€ = ColumnView{.matrix = všŒŸ, + int k_max = 0; + + auto Red = [&](int const k, int const l) { + if (Abs(Ī¼(k, l)) <= 0.5) { + return; + } + auto const m = std::round(Ī¼(k, l)); + auto vā‚– = ColumnView{.matrix = v, .first_row = 0, - .last_row = m - 1, + .last_row = rows - 1, + .column = k}; + auto vā‚— = ColumnView{.matrix = v, + .first_row = 0, + .last_row = rows - 1, + .column = l}; + vā‚– -= m * typename G::Vector(vā‚—); + Ī¼(k, l) -= m; + for (int i = 0; i < l - 1; ++i) { + Ī¼(k, i) -= m * Ī¼(l, i); + } + }; + + auto Swap = [&](int const k) { + auto vā‚– = ColumnView{.matrix = v, + .first_row = 0, + .last_row = rows - 1, + .column = k}; + auto vā‚–ā‚‹ā‚ = ColumnView{.matrix = v, + .first_row = 0, + .last_row = rows - 1, + .column = k - 1}; + SwapColumns(vā‚–, vā‚–ā‚‹ā‚); + for (int j = 0; j < k - 2; ++j) { + std::swap(Ī¼(k - 1, j), Ī¼(k, j)); + } + auto const Ī¼_value = Ī¼(k, k - 1); + auto const B_value = B[k] + Pow<2>(Ī¼_value) * B[k - 1]; + Ī¼(k, k - 1) = Ī¼_value * B[k - 1] / B_value; + B[k] = B[k - 1] * B[k] / B_value; + B[k - 1] = B_value; + for (int i = k + 1; i < k_max; ++i) { + auto const m = Ī¼(i, k); + Ī¼(i, k) = Ī¼(i, k - 1) - Ī¼_value * m; + Ī¼(i, k - 1) = m + Ī¼(k, k - 1) * Ī¼(i, k); + } + }; + + ColumnView všŒŸā‚€ = ColumnView{.matrix = všŒŸ, + .first_row = 0, + .last_row = rows - 1, .column = 0}; - auto vā‚€ = ColumnView{.matrix = v, + ColumnView vā‚€ = ColumnView{.matrix = v, .first_row = 0, - .last_row = m - 1, + .last_row = rows - 1, .column = 0}; všŒŸā‚€ = vā‚€; B[0] = vā‚€.NormĀ²(); @@ -170,31 +160,31 @@ Matrix LenstraLenstraLovĆ”sz2(Matrix const& L) { k_max = k; auto všŒŸā‚– = ColumnView{.matrix = všŒŸ, .first_row = 0, - .last_row = m - 1, + .last_row = rows - 1, .column = k}; auto vā‚– = ColumnView{.matrix = v, .first_row = 0, - .last_row = m - 1, + .last_row = rows - 1, .column = k}; všŒŸā‚– = vā‚–; for (int j = 0; j < k - 1; ++j) { auto všŒŸā±¼ = ColumnView{.matrix = všŒŸ, .first_row = 0, - .last_row = m - 1, + .last_row = rows - 1, .column = j}; Ī¼(k, j) = TransposedView{vā‚–} * všŒŸā±¼ / B[j]; - všŒŸā‚– -= typename G::Vector(Ī¼(k, j) * všŒŸā±¼); + všŒŸā‚– -= Ī¼(k, j) * typename G::Vector(všŒŸā±¼); } B[k] = všŒŸā‚–.NormĀ²(); } for (;;) { - Red(k, k - 1, v, Ī¼); + Red(k, k - 1); if (B[k] < (0.75 - Pow<2>(Ī¼(k, k - 1))) * B[k - 1]) { - Swap(k, k_max, v, Ī¼, B); + Swap(k); k = std::max(k - 1, 1); } else { for (int l = k - 3; l >= 0; --l) { - Red(k, l, v, Ī¼); + Red(k, l); } ++k; break; diff --git a/numerics/matrix_views.hpp b/numerics/matrix_views.hpp index e077d6135f..2f9e2dd54d 100644 --- a/numerics/matrix_views.hpp +++ b/numerics/matrix_views.hpp @@ -72,6 +72,8 @@ struct ColumnView { template requires one_dimensional && same_elements_as ColumnView& operator=(T&& right); + ColumnView& operator=(ColumnView const& right); + ColumnView& operator=(ColumnView&& right); template requires one_dimensional && same_elements_as diff --git a/numerics/matrix_views_test.cpp b/numerics/matrix_views_test.cpp index d2d3fafdae..c2485256b1 100644 --- a/numerics/matrix_views_test.cpp +++ b/numerics/matrix_views_test.cpp @@ -142,6 +142,22 @@ TEST_F(MatrixViewsTest, ColumnView_Indexing) { EXPECT_EQ(-9, cum34[1]); } +TEST_F(MatrixViewsTest, ColumnView_Assignment) { + ColumnView> cfm34{.matrix = fm34_, + .first_row = 1, + .last_row = 2, + .column = 2}; + ColumnView> cum34{.matrix = um34_, + .first_row = 1, + .last_row = 2, + .column = 3}; + cum34 = cfm34; + EXPECT_EQ(-10, cum34[1]); + EXPECT_EQ(-3, cum34[2]); + + cfm34 = cfm34; +} + TEST_F(MatrixViewsTest, ColumnView_Addition) { ColumnView> cfm34{.matrix = fm34_, .first_row = 1, From dce3c48d5889e625960f66414ffbd602466dfdbf Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 24 Apr 2024 20:38:50 +0200 Subject: [PATCH 08/14] The test links. --- numerics/lattices_body.hpp | 4 ++-- numerics/matrix_views.hpp | 7 ------- numerics/matrix_views_body.hpp | 21 ++------------------- numerics/matrix_views_test.cpp | 4 ++-- 4 files changed, 6 insertions(+), 30 deletions(-) diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index fd00b0dfba..bfcb8bbce6 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -145,11 +145,11 @@ Matrix LenstraLenstraLovĆ”sz2(Matrix const& L) { } }; - ColumnView všŒŸā‚€ = ColumnView{.matrix = všŒŸ, + auto všŒŸā‚€ = ColumnView{.matrix = všŒŸ, .first_row = 0, .last_row = rows - 1, .column = 0}; - ColumnView vā‚€ = ColumnView{.matrix = v, + auto vā‚€ = ColumnView{.matrix = v, .first_row = 0, .last_row = rows - 1, .column = 0}; diff --git a/numerics/matrix_views.hpp b/numerics/matrix_views.hpp index 2f9e2dd54d..d839129c9c 100644 --- a/numerics/matrix_views.hpp +++ b/numerics/matrix_views.hpp @@ -34,9 +34,6 @@ struct BlockView { template requires two_dimensional && same_elements_as BlockView& operator=(T const& right); - template - requires two_dimensional && same_elements_as - BlockView& operator=(T&& right); template requires two_dimensional && same_elements_as @@ -69,11 +66,7 @@ struct ColumnView { template requires one_dimensional && same_elements_as ColumnView& operator=(T const& right); - template - requires one_dimensional && same_elements_as - ColumnView& operator=(T&& right); ColumnView& operator=(ColumnView const& right); - ColumnView& operator=(ColumnView&& right); template requires one_dimensional && same_elements_as diff --git a/numerics/matrix_views_body.hpp b/numerics/matrix_views_body.hpp index 7d410c7ed9..5c4ecb8291 100644 --- a/numerics/matrix_views_body.hpp +++ b/numerics/matrix_views_body.hpp @@ -49,21 +49,6 @@ BlockView& BlockView::operator=(T const& right) { return *this; } -template - requires two_dimensional -template - requires two_dimensional && same_elements_as -BlockView& BlockView::operator=(T&& right) { - DCHECK_EQ(rows(), right.rows()); - DCHECK_EQ(columns(), right.columns()); - for (int i = 0; i < rows(); ++i) { - for (int j = 0; j < columns(); ++j) { - matrix(first_row + i, first_column + j) = std::move(right(i, j)); - } - } - return *this; -} - template requires two_dimensional template @@ -158,12 +143,10 @@ ColumnView& ColumnView::operator=(T const& right) { template requires two_dimensional -template - requires one_dimensional && same_elements_as -ColumnView& ColumnView::operator=(T&& right) { +ColumnView& ColumnView::operator=(ColumnView const& right) { DCHECK_EQ(size(), right.size()); for (int i = 0; i < size(); ++i) { - matrix(first_row + i, column) = std::move(right[i]); + matrix(first_row + i, column) = right[i]; } return *this; } diff --git a/numerics/matrix_views_test.cpp b/numerics/matrix_views_test.cpp index c2485256b1..759ba33c5f 100644 --- a/numerics/matrix_views_test.cpp +++ b/numerics/matrix_views_test.cpp @@ -152,8 +152,8 @@ TEST_F(MatrixViewsTest, ColumnView_Assignment) { .last_row = 2, .column = 3}; cum34 = cfm34; - EXPECT_EQ(-10, cum34[1]); - EXPECT_EQ(-3, cum34[2]); + EXPECT_EQ(9, cum34[0]); + EXPECT_EQ(-2, cum34[1]); cfm34 = cfm34; } From 3ae8f4c58f2325101d4cf99a3fa80371170e7fcd Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 24 Apr 2024 21:27:00 +0200 Subject: [PATCH 09/14] Fix a bug. --- numerics/lattices_body.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index bfcb8bbce6..4a9c3b08eb 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -167,7 +167,7 @@ Matrix LenstraLenstraLovĆ”sz2(Matrix const& L) { .last_row = rows - 1, .column = k}; všŒŸā‚– = vā‚–; - for (int j = 0; j < k - 1; ++j) { + for (int j = 0; j < k; ++j) { auto všŒŸā±¼ = ColumnView{.matrix = všŒŸ, .first_row = 0, .last_row = rows - 1, From 4414cb3a8366f39cf563e4ba0db5b723490dd549 Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 24 Apr 2024 21:29:39 +0200 Subject: [PATCH 10/14] Explicit captures. --- numerics/lattices_body.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index 4a9c3b08eb..95d1d841fd 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -100,7 +100,7 @@ Matrix LenstraLenstraLovĆ”sz2(Matrix const& L) { typename G::NormĀ²Vector B(uninitialized); int k_max = 0; - auto Red = [&](int const k, int const l) { + auto Red = [rows, &v, &Ī¼](int const k, int const l) { if (Abs(Ī¼(k, l)) <= 0.5) { return; } @@ -120,7 +120,7 @@ Matrix LenstraLenstraLovĆ”sz2(Matrix const& L) { } }; - auto Swap = [&](int const k) { + auto Swap = [&B, k_max, &v, &Ī¼](int const k) { auto vā‚– = ColumnView{.matrix = v, .first_row = 0, .last_row = rows - 1, From ae7222eb7c92e7d286919ed67a61900babaf7c59 Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 24 Apr 2024 22:00:04 +0200 Subject: [PATCH 11/14] Commit the 2nd algorithm before giving up. --- numerics/lattices_test.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/numerics/lattices_test.cpp b/numerics/lattices_test.cpp index cedbef1b8a..c56b9cdaa8 100644 --- a/numerics/lattices_test.cpp +++ b/numerics/lattices_test.cpp @@ -55,6 +55,20 @@ TEST_F(LatticesTest, Example_7_75b) { 0)); } +TEST_F(LatticesTest, Compalg) { + FixedMatrix l({1, -1, 3, + 1, 0, 5, + 1, 2, 6}); + + auto const reduced = LenstraLenstraLovĆ”sz(l); + EXPECT_THAT(reduced, + AlmostEquals( + (FixedMatrix({0, 1, -1, + 1, 0, 0, + 0, 1, 2})), + 0)); +} + } // namespace _lattices } // namespace numerics } // namespace principia From 131d8f10efb7079f7ea8da6eeddb8c2f57236012 Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 24 Apr 2024 22:06:48 +0200 Subject: [PATCH 12/14] Simplification. --- numerics/lattices.hpp | 6 -- numerics/lattices_body.hpp | 127 +++---------------------------------- numerics/lattices_test.cpp | 34 ---------- 3 files changed, 9 insertions(+), 158 deletions(-) diff --git a/numerics/lattices.hpp b/numerics/lattices.hpp index e91a388f4b..abae155874 100644 --- a/numerics/lattices.hpp +++ b/numerics/lattices.hpp @@ -9,19 +9,13 @@ namespace internal { using namespace principia::numerics::_concepts; -//TODO(phl):Should this be integral? template requires two_dimensional Matrix LenstraLenstraLovĆ”sz(Matrix const& L); -template - requires two_dimensional -Matrix LenstraLenstraLovĆ”sz2(Matrix const& L); - } // namespace internal using internal::LenstraLenstraLovĆ”sz; -using internal::LenstraLenstraLovĆ”sz2; } // namespace _lattices } // namespace numerics diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index 95d1d841fd..c4ec67eb1c 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -2,28 +2,22 @@ #include "numerics/lattices.hpp" -#include "base/tags.hpp" #include "numerics/fixed_arrays.hpp" #include "numerics/matrix_computations.hpp" #include "numerics/matrix_views.hpp" -#include "numerics/transposed_view.hpp" #include "numerics/unbounded_arrays.hpp" #include "quantities/elementary_functions.hpp" -#include "quantities/named_quantities.hpp" namespace principia { namespace numerics { namespace _lattices { namespace internal { -using namespace principia::base::_tags; using namespace principia::numerics::_fixed_arrays; using namespace principia::numerics::_matrix_computations; using namespace principia::numerics::_matrix_views; -using namespace principia::numerics::_transposed_view; using namespace principia::numerics::_unbounded_arrays; using namespace principia::quantities::_elementary_functions; -using namespace principia::quantities::_named_quantities; template struct LenstraLenstraLovĆ”szGenerator; @@ -31,18 +25,18 @@ struct LenstraLenstraLovĆ”szGenerator; template struct LenstraLenstraLovĆ”szGenerator> { using Vector = UnboundedVector; - using DoubleMatrix = UnboundedMatrix; - using NormĀ²Vector = UnboundedVector>; }; template struct LenstraLenstraLovĆ”szGenerator< FixedMatrix> { using Vector = FixedVector; - using DoubleMatrix = FixedMatrix; - using NormĀ²Vector = FixedVector, rows>; }; +// This implements [HPS], theorem 7.71, figure 7.8. Note that figures 7.9 and +// 7.10 are supposedly more efficient, but they are significantly more +// complicated. If performance is an issue, we should look into recent +// improvements of LLL. template requires two_dimensional Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { @@ -62,8 +56,11 @@ Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { .first_row = 0, .last_row = m - 1, .column = j}; - vā‚– -= std::round(Ī¼ā‚–ā±¼) * typename G::Vector(vā±¼); - qr = UnitriangularGramSchmidt(v); + auto const round_Ī¼ā‚–ā±¼ = std::round(Ī¼ā‚–ā±¼); + if (round_Ī¼ā‚–ā±¼ != 0) { + vā‚– -= round_Ī¼ā‚–ā±¼ * typename G::Vector(vā±¼); + qr = UnitriangularGramSchmidt(v); + } } auto const Ī¼ā‚–ā‚–ā‚‹ā‚ = qr.R(k - 1, k); auto všŒŸā‚– = ColumnView{.matrix = qr.Q, @@ -88,112 +85,6 @@ Matrix LenstraLenstraLovĆ”sz(Matrix const& L) { return v; } -template - requires two_dimensional -Matrix LenstraLenstraLovĆ”sz2(Matrix const& L) { - using G = LenstraLenstraLovĆ”szGenerator; - auto const n = L.columns(); - auto const rows = L.rows(); - Matrix v = L; - Matrix všŒŸ; - typename G::DoubleMatrix Ī¼(uninitialized); - typename G::NormĀ²Vector B(uninitialized); - int k_max = 0; - - auto Red = [rows, &v, &Ī¼](int const k, int const l) { - if (Abs(Ī¼(k, l)) <= 0.5) { - return; - } - auto const m = std::round(Ī¼(k, l)); - auto vā‚– = ColumnView{.matrix = v, - .first_row = 0, - .last_row = rows - 1, - .column = k}; - auto vā‚— = ColumnView{.matrix = v, - .first_row = 0, - .last_row = rows - 1, - .column = l}; - vā‚– -= m * typename G::Vector(vā‚—); - Ī¼(k, l) -= m; - for (int i = 0; i < l - 1; ++i) { - Ī¼(k, i) -= m * Ī¼(l, i); - } - }; - - auto Swap = [&B, k_max, &v, &Ī¼](int const k) { - auto vā‚– = ColumnView{.matrix = v, - .first_row = 0, - .last_row = rows - 1, - .column = k}; - auto vā‚–ā‚‹ā‚ = ColumnView{.matrix = v, - .first_row = 0, - .last_row = rows - 1, - .column = k - 1}; - SwapColumns(vā‚–, vā‚–ā‚‹ā‚); - for (int j = 0; j < k - 2; ++j) { - std::swap(Ī¼(k - 1, j), Ī¼(k, j)); - } - auto const Ī¼_value = Ī¼(k, k - 1); - auto const B_value = B[k] + Pow<2>(Ī¼_value) * B[k - 1]; - Ī¼(k, k - 1) = Ī¼_value * B[k - 1] / B_value; - B[k] = B[k - 1] * B[k] / B_value; - B[k - 1] = B_value; - for (int i = k + 1; i < k_max; ++i) { - auto const m = Ī¼(i, k); - Ī¼(i, k) = Ī¼(i, k - 1) - Ī¼_value * m; - Ī¼(i, k - 1) = m + Ī¼(k, k - 1) * Ī¼(i, k); - } - }; - - auto všŒŸā‚€ = ColumnView{.matrix = všŒŸ, - .first_row = 0, - .last_row = rows - 1, - .column = 0}; - auto vā‚€ = ColumnView{.matrix = v, - .first_row = 0, - .last_row = rows - 1, - .column = 0}; - všŒŸā‚€ = vā‚€; - B[0] = vā‚€.NormĀ²(); - for (int k = 1; k < n;) { - if (k > k_max) { - k_max = k; - auto všŒŸā‚– = ColumnView{.matrix = všŒŸ, - .first_row = 0, - .last_row = rows - 1, - .column = k}; - auto vā‚– = ColumnView{.matrix = v, - .first_row = 0, - .last_row = rows - 1, - .column = k}; - všŒŸā‚– = vā‚–; - for (int j = 0; j < k; ++j) { - auto všŒŸā±¼ = ColumnView{.matrix = všŒŸ, - .first_row = 0, - .last_row = rows - 1, - .column = j}; - Ī¼(k, j) = TransposedView{vā‚–} * všŒŸā±¼ / B[j]; - všŒŸā‚– -= Ī¼(k, j) * typename G::Vector(všŒŸā±¼); - } - B[k] = všŒŸā‚–.NormĀ²(); - } - for (;;) { - Red(k, k - 1); - if (B[k] < (0.75 - Pow<2>(Ī¼(k, k - 1))) * B[k - 1]) { - Swap(k); - k = std::max(k - 1, 1); - } else { - for (int l = k - 3; l >= 0; --l) { - Red(k, l); - } - ++k; - break; - } - } - } - return v; -} - } // namespace internal } // namespace _lattices } // namespace numerics diff --git a/numerics/lattices_test.cpp b/numerics/lattices_test.cpp index c56b9cdaa8..fc70eb5932 100644 --- a/numerics/lattices_test.cpp +++ b/numerics/lattices_test.cpp @@ -35,40 +35,6 @@ TEST_F(LatticesTest, Example_7_75) { 0)); } -TEST_F(LatticesTest, Example_7_75b) { - FixedMatrix l({19, 15, 43, 20, 0, 48, - 2, 42, 15, 44, 48, 33, - 32, 11, 0, 44, 35, 32, - 46, 0, 24, 0, 16, 9, - 3, 3, 4, 18, 31, 1, - 33, 24, 16, 15, 31, 29}); - - auto const reduced = LenstraLenstraLovĆ”sz2(l); - EXPECT_THAT(reduced, - AlmostEquals( - (FixedMatrix({ 7, -20, 5, -6, -10, 7, - -12, 4, 2, -7, -24, 4, - -8, -9, 33, -20, 21, -9, - 4, 16, 0, -21, -15, -11, - 19, 13, 15, 8, -6, 1, - 9, 16, -9, -12, -11, 31})), - 0)); -} - -TEST_F(LatticesTest, Compalg) { - FixedMatrix l({1, -1, 3, - 1, 0, 5, - 1, 2, 6}); - - auto const reduced = LenstraLenstraLovĆ”sz(l); - EXPECT_THAT(reduced, - AlmostEquals( - (FixedMatrix({0, 1, -1, - 1, 0, 0, - 0, 1, 2})), - 0)); -} - } // namespace _lattices } // namespace numerics } // namespace principia From 6f8e0f1dc076debafc30637e564eceb4f0c88a04 Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 24 Apr 2024 22:11:06 +0200 Subject: [PATCH 13/14] Readying. --- numerics/lattices_test.cpp | 12 ++++++------ numerics/matrix_views.hpp | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/numerics/lattices_test.cpp b/numerics/lattices_test.cpp index fc70eb5932..e513c662ed 100644 --- a/numerics/lattices_test.cpp +++ b/numerics/lattices_test.cpp @@ -26,12 +26,12 @@ TEST_F(LatticesTest, Example_7_75) { auto const reduced = LenstraLenstraLovĆ”sz(l); EXPECT_THAT(reduced, AlmostEquals( - (FixedMatrix({ 7, -20, 5, -6, -10, 7, - -12, 4, 2, -7, -24, 4, - -8, -9, 33, -20, 21, -9, - 4, 16, 0, -21, -15, -11, - 19, 13, 15, 8, -6, 1, - 9, 16, -9, -12, -11, 31})), + (FixedMatrix({ 7, -20, 5, -6, -10, 7, + -12, 4, 2, -7, -24, 4, + -8, -9, 33, -20, 21, -9, + 4, 16, 0, -21, -15, -11, + 19, 13, 15, 8, -6, 1, + 9, 16, -9, -12, -11, 31})), 0)); } diff --git a/numerics/matrix_views.hpp b/numerics/matrix_views.hpp index d839129c9c..b5cd0c9fa9 100644 --- a/numerics/matrix_views.hpp +++ b/numerics/matrix_views.hpp @@ -83,6 +83,9 @@ struct ColumnView { constexpr int size() const; }; +// TODO(phl): This should probably be just |swap|. The semantics of BlockView +// and ColumnView do imply an implicit dereferencing, so swapping should work +// the same. template void SwapColumns(ColumnView& m1, ColumnView& m2); From 3f93452e37799d56993b586c3ad06c48eda10fc2 Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 24 Apr 2024 22:22:13 +0200 Subject: [PATCH 14/14] Lint. --- numerics/lattices_body.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numerics/lattices_body.hpp b/numerics/lattices_body.hpp index c4ec67eb1c..a8daeaf27e 100644 --- a/numerics/lattices_body.hpp +++ b/numerics/lattices_body.hpp @@ -2,6 +2,8 @@ #include "numerics/lattices.hpp" +#include + #include "numerics/fixed_arrays.hpp" #include "numerics/matrix_computations.hpp" #include "numerics/matrix_views.hpp"