From f4e9361cfea6b346c03fe595c2fe6e0d078a3fc0 Mon Sep 17 00:00:00 2001 From: "Leandro A. F. Fernandes" Date: Mon, 10 Feb 2020 12:38:09 -0300 Subject: [PATCH] Structured bindings for lazy_context arguments. --- cpp/CMakeLists.txt | 4 ++-- cpp/include/gatl/ga/core/arithmetic_operators.hpp | 2 +- cpp/include/gatl/ga/core/conjugation.hpp | 2 +- cpp/include/gatl/ga/core/dot_product.hpp | 2 +- cpp/include/gatl/ga/core/geometric_product.hpp | 2 +- cpp/include/gatl/ga/core/hestenes_inner_product.hpp | 2 +- cpp/include/gatl/ga/core/involution.hpp | 2 +- cpp/include/gatl/ga/core/lazy_context.hpp | 11 +++++++++++ cpp/include/gatl/ga/core/left_contraction.hpp | 2 +- cpp/include/gatl/ga/core/outer_product.hpp | 2 +- cpp/include/gatl/ga/core/regressive_product.hpp | 2 +- cpp/include/gatl/ga/core/reversion.hpp | 2 +- cpp/include/gatl/ga/core/right_contraction.hpp | 2 +- cpp/include/gatl/ga/core/scalar_product.hpp | 2 +- cpp/include/gatl/ga/extra/commutator_product.hpp | 2 +- cpp/include/gatl/ga/extra/grade.hpp | 2 +- cpp/include/gatl/ga/extra/take_grade.hpp | 2 +- cpp/tools/example/concepts/lazy_evaluation.cpp | 4 +--- cpp/tools/test/size/main.cpp | 4 ++-- 19 files changed, 31 insertions(+), 22 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 6a16ae1..f08baa6 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -23,8 +23,8 @@ cmake_minimum_required(VERSION 3.10) set(VERSION_MAJOR 2) -set(VERSION_MINOR 0) -set(VERSION_PATCH 20200120) +set(VERSION_MINOR 1) +set(VERSION_PATCH 0) project(GATL VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} diff --git a/cpp/include/gatl/ga/core/arithmetic_operators.hpp b/cpp/include/gatl/ga/core/arithmetic_operators.hpp index 423b7ea..1477800 100644 --- a/cpp/include/gatl/ga/core/arithmetic_operators.hpp +++ b/cpp/include/gatl/ga/core/arithmetic_operators.hpp @@ -33,7 +33,7 @@ namespace ga { template constexpr decltype(auto) operator+(clifford_expression const &lhs, clifford_expression const &rhs) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1> > >()); } diff --git a/cpp/include/gatl/ga/core/conjugation.hpp b/cpp/include/gatl/ga/core/conjugation.hpp index ade7e80..f2426a5 100644 --- a/cpp/include/gatl/ga/core/conjugation.hpp +++ b/cpp/include/gatl/ga/core/conjugation.hpp @@ -28,7 +28,7 @@ namespace ga { template constexpr decltype(auto) conjugate(clifford_expression const &arg) GA_NOEXCEPT { - auto lazy = make_lazy_context(arg); + auto const lazy = make_lazy_context(arg); return lazy.eval(clifford_expression, (bitset_t)0x6666666666666666ull> >()); } diff --git a/cpp/include/gatl/ga/core/dot_product.hpp b/cpp/include/gatl/ga/core/dot_product.hpp index 23a0356..21adced 100644 --- a/cpp/include/gatl/ga/core/dot_product.hpp +++ b/cpp/include/gatl/ga/core/dot_product.hpp @@ -69,7 +69,7 @@ namespace ga { template constexpr decltype(auto) dot(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &mtr) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t > >()); } diff --git a/cpp/include/gatl/ga/core/geometric_product.hpp b/cpp/include/gatl/ga/core/geometric_product.hpp index 5f12fe8..0432ee5 100644 --- a/cpp/include/gatl/ga/core/geometric_product.hpp +++ b/cpp/include/gatl/ga/core/geometric_product.hpp @@ -96,7 +96,7 @@ namespace ga { template constexpr decltype(auto) gp(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t > >()); } diff --git a/cpp/include/gatl/ga/core/hestenes_inner_product.hpp b/cpp/include/gatl/ga/core/hestenes_inner_product.hpp index c092bed..32d79a3 100644 --- a/cpp/include/gatl/ga/core/hestenes_inner_product.hpp +++ b/cpp/include/gatl/ga/core/hestenes_inner_product.hpp @@ -80,7 +80,7 @@ namespace ga { template constexpr decltype(auto) hip(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &mtr) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t > >()); } diff --git a/cpp/include/gatl/ga/core/involution.hpp b/cpp/include/gatl/ga/core/involution.hpp index b7dd9f2..f822368 100644 --- a/cpp/include/gatl/ga/core/involution.hpp +++ b/cpp/include/gatl/ga/core/involution.hpp @@ -28,7 +28,7 @@ namespace ga { template constexpr decltype(auto) involute(clifford_expression const &arg) GA_NOEXCEPT { - auto lazy = make_lazy_context(arg); + auto const lazy = make_lazy_context(arg); return lazy.eval(clifford_expression, (bitset_t)0xAAAAAAAAAAAAAAAAull> >()); } diff --git a/cpp/include/gatl/ga/core/lazy_context.hpp b/cpp/include/gatl/ga/core/lazy_context.hpp index c840210..01ba2f5 100644 --- a/cpp/include/gatl/ga/core/lazy_context.hpp +++ b/cpp/include/gatl/ga/core/lazy_context.hpp @@ -648,6 +648,10 @@ namespace ga { return argument_t(); } + constexpr static decltype(auto) arguments() GA_NOEXCEPT { + return arguments_tuple(std::make_index_sequence()); + } + template > constexpr decltype(auto) eval(clifford_expression const &expression) const { return detail::eval(expression, super::stored_inputs_tuple()); @@ -657,6 +661,13 @@ namespace ga { constexpr decltype(auto) eval(clifford_expression &&) const GA_NOEXCEPT { return clifford_expression(); } + + private: + + template + constexpr static decltype(auto) arguments_tuple(std::index_sequence) GA_NOEXCEPT { + return std::make_tuple(argument()...); + } }; template diff --git a/cpp/include/gatl/ga/core/left_contraction.hpp b/cpp/include/gatl/ga/core/left_contraction.hpp index b275c20..4189efd 100644 --- a/cpp/include/gatl/ga/core/left_contraction.hpp +++ b/cpp/include/gatl/ga/core/left_contraction.hpp @@ -64,7 +64,7 @@ namespace ga { template constexpr decltype(auto) lcont(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &mtr) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t > >()); } diff --git a/cpp/include/gatl/ga/core/outer_product.hpp b/cpp/include/gatl/ga/core/outer_product.hpp index 71c698c..5e3fe2a 100644 --- a/cpp/include/gatl/ga/core/outer_product.hpp +++ b/cpp/include/gatl/ga/core/outer_product.hpp @@ -28,7 +28,7 @@ namespace ga { template constexpr decltype(auto) op(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1>, detail::exterior_product_mapping > >()); } diff --git a/cpp/include/gatl/ga/core/regressive_product.hpp b/cpp/include/gatl/ga/core/regressive_product.hpp index e58838b..a613786 100644 --- a/cpp/include/gatl/ga/core/regressive_product.hpp +++ b/cpp/include/gatl/ga/core/regressive_product.hpp @@ -28,7 +28,7 @@ namespace ga { template constexpr decltype(auto) rp(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1>, detail::regressive_product_mapping > >()); } diff --git a/cpp/include/gatl/ga/core/reversion.hpp b/cpp/include/gatl/ga/core/reversion.hpp index 671897a..faf13de 100644 --- a/cpp/include/gatl/ga/core/reversion.hpp +++ b/cpp/include/gatl/ga/core/reversion.hpp @@ -28,7 +28,7 @@ namespace ga { template constexpr decltype(auto) reverse(clifford_expression const &arg) GA_NOEXCEPT { - auto lazy = make_lazy_context(arg); + auto const lazy = make_lazy_context(arg); return lazy.eval(clifford_expression, (bitset_t)0xCCCCCCCCCCCCCCCCull> >()); } diff --git a/cpp/include/gatl/ga/core/right_contraction.hpp b/cpp/include/gatl/ga/core/right_contraction.hpp index d8d6512..4e89f78 100644 --- a/cpp/include/gatl/ga/core/right_contraction.hpp +++ b/cpp/include/gatl/ga/core/right_contraction.hpp @@ -64,7 +64,7 @@ namespace ga { template constexpr decltype(auto) rcont(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &mtr) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t > >()); } diff --git a/cpp/include/gatl/ga/core/scalar_product.hpp b/cpp/include/gatl/ga/core/scalar_product.hpp index c68b3b2..10b7b7a 100644 --- a/cpp/include/gatl/ga/core/scalar_product.hpp +++ b/cpp/include/gatl/ga/core/scalar_product.hpp @@ -46,7 +46,7 @@ namespace ga { template constexpr decltype(auto) sp(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &mtr) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t > >()); } diff --git a/cpp/include/gatl/ga/extra/commutator_product.hpp b/cpp/include/gatl/ga/extra/commutator_product.hpp index f59699f..b6d5418 100644 --- a/cpp/include/gatl/ga/extra/commutator_product.hpp +++ b/cpp/include/gatl/ga/extra/commutator_product.hpp @@ -28,7 +28,7 @@ namespace ga { template constexpr decltype(auto) cp(clifford_expression const &lhs, clifford_expression const &rhs, metric_space const &mtr) GA_NOEXCEPT { - auto lazy = make_lazy_context(lhs, rhs); + auto const lazy = make_lazy_context(lhs, rhs); return lazy.eval((gp(lazy.template argument<0>(), lazy.template argument<1>(), mtr) - gp(lazy.template argument<1>(), lazy.template argument<0>(), mtr)) / c<2>); } diff --git a/cpp/include/gatl/ga/extra/grade.hpp b/cpp/include/gatl/ga/extra/grade.hpp index 1aa7332..773ca42 100644 --- a/cpp/include/gatl/ga/extra/grade.hpp +++ b/cpp/include/gatl/ga/extra/grade.hpp @@ -263,7 +263,7 @@ namespace ga { // Returns a scalar expression with the largest grade part of a given Clifford expression such that it is not zero. template constexpr decltype(auto) largest_grade(clifford_expression const &arg, ToleranceType const &tol) GA_NOEXCEPT { - auto lazy = make_lazy_context(arg, scalar(tol)); + auto const lazy = make_lazy_context(arg, scalar(tol)); return lazy.eval(scalar_clifford_expression, detail::coefficient_t > > >()); } diff --git a/cpp/include/gatl/ga/extra/take_grade.hpp b/cpp/include/gatl/ga/extra/take_grade.hpp index 2f65790..6ad3d69 100644 --- a/cpp/include/gatl/ga/extra/take_grade.hpp +++ b/cpp/include/gatl/ga/extra/take_grade.hpp @@ -85,7 +85,7 @@ namespace ga { // Returns the k-grade part of the given Clifford expression. template > > constexpr decltype(auto) take_grade(clifford_expression const &arg, scalar_clifford_expression const &k) GA_NOEXCEPT { - auto lazy = make_lazy_context(arg, k); + auto const lazy = make_lazy_context(arg, k); return lazy.eval(clifford_expression, typename decltype(lazy)::template argument_expression_t<1> > >()); } diff --git a/cpp/tools/example/concepts/lazy_evaluation.cpp b/cpp/tools/example/concepts/lazy_evaluation.cpp index d8f7bfd..a1f4f2f 100644 --- a/cpp/tools/example/concepts/lazy_evaluation.cpp +++ b/cpp/tools/example/concepts/lazy_evaluation.cpp @@ -68,9 +68,7 @@ int main() { std::cout << std::endl; { auto lazy = make_lazy_context(scalar(x_in), scalar(y_in), scalar(z_in)); - auto x = lazy.argument<0>(); - auto y = lazy.argument<1>(); - auto z = lazy.argument<2>(); + auto [x, y, z] = lazy.arguments(); auto p = x * e1 + y * e2 + z * e3 + ep; auto d = x * e1 + y * e2 + z * e3; diff --git a/cpp/tools/test/size/main.cpp b/cpp/tools/test/size/main.cpp index 9958fe4..2367cc9 100644 --- a/cpp/tools/test/size/main.cpp +++ b/cpp/tools/test/size/main.cpp @@ -45,7 +45,7 @@ TEST(Size, ScaledScalar) { } TEST(Size, LazyArgument) { - auto lazy = make_lazy_context(scalar(5.0), scalar(7), scalar(7.0)); + auto const lazy = make_lazy_context(scalar(5.0), scalar(7), scalar(7.0)); auto x = lazy.argument<0>() + lazy.argument<1>(); auto y = c<5> + sqrt(lazy.argument<2>()); auto z = c<5> + sqrt(c<7>) + cbrt(c<11>); @@ -56,7 +56,7 @@ TEST(Size, LazyArgument) { } TEST(Size, MixedExpressions1) { - auto lazy = make_lazy_context(scalar(5.0), scalar(7), scalar(7.0)); + auto const lazy = make_lazy_context(scalar(5.0), scalar(7), scalar(7.0)); auto x1 = c<5> + pow(c<2>, c<10>); auto x2 = scalar(5.0);