Skip to content

Commit

Permalink
Structured bindings for lazy_context arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
laffernandes committed Feb 10, 2020
1 parent 32df487 commit f4e9361
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/arithmetic_operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression>
constexpr decltype(auto) operator+(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::addition_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/conjugation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ga {

template<typename CoefficientType, typename Expression>
constexpr decltype(auto) conjugate(clifford_expression<CoefficientType, Expression> const &arg) GA_NOEXCEPT {
auto lazy = make_lazy_context(arg);
auto const lazy = make_lazy_context(arg);
return lazy.eval(clifford_expression<default_integral_t, detail::graded_unary_minus_t<typename decltype(lazy)::template argument_expression_t<0>, (bitset_t)0x6666666666666666ull> >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/dot_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) dot(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> const &mtr) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::product_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t<MetricSpaceType, detail::dot_mapping> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/geometric_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) gp(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> const &) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::product_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t<MetricSpaceType, detail::gp_mapping> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/hestenes_inner_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) hip(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> const &mtr) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::product_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t<MetricSpaceType, detail::hip_mapping> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/involution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ga {

template<typename CoefficientType, typename Expression>
constexpr decltype(auto) involute(clifford_expression<CoefficientType, Expression> const &arg) GA_NOEXCEPT {
auto lazy = make_lazy_context(arg);
auto const lazy = make_lazy_context(arg);
return lazy.eval(clifford_expression<default_integral_t, detail::graded_unary_minus_t<typename decltype(lazy)::template argument_expression_t<0>, (bitset_t)0xAAAAAAAAAAAAAAAAull> >());
}

Expand Down
11 changes: 11 additions & 0 deletions cpp/include/gatl/ga/core/lazy_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ namespace ga {
return argument_t<Index>();
}

constexpr static decltype(auto) arguments() GA_NOEXCEPT {
return arguments_tuple(std::make_index_sequence<sizeof...(InputExpressions)>());
}

template<typename CoefficientType, typename Expression, typename = std::enable_if_t<super::stored_inputs_count() != 0> >
constexpr decltype(auto) eval(clifford_expression<CoefficientType, Expression> const &expression) const {
return detail::eval<base_id + 1, base_id + (detail::tag_t)super::stored_inputs_count()>(expression, super::stored_inputs_tuple());
Expand All @@ -657,6 +661,13 @@ namespace ga {
constexpr decltype(auto) eval(clifford_expression<CoefficientType, Expression> &&) const GA_NOEXCEPT {
return clifford_expression<CoefficientType, Expression>();
}

private:

template<std::size_t... Indices>
constexpr static decltype(auto) arguments_tuple(std::index_sequence<Indices...>) GA_NOEXCEPT {
return std::make_tuple(argument<Indices>()...);
}
};

template<typename... InputTypes>
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/left_contraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) lcont(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> const &mtr) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::product_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t<MetricSpaceType, detail::lcont_mapping> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/outer_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) op(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> const &) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::product_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1>, detail::exterior_product_mapping<MetricSpaceType::vector_space_dimensions> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/regressive_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) rp(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> const &) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::product_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1>, detail::regressive_product_mapping<MetricSpaceType::vector_space_dimensions> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/reversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ga {

template<typename CoefficientType, typename Expression>
constexpr decltype(auto) reverse(clifford_expression<CoefficientType, Expression> const &arg) GA_NOEXCEPT {
auto lazy = make_lazy_context(arg);
auto const lazy = make_lazy_context(arg);
return lazy.eval(clifford_expression<default_integral_t, detail::graded_unary_minus_t<typename decltype(lazy)::template argument_expression_t<0>, (bitset_t)0xCCCCCCCCCCCCCCCCull> >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/right_contraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) rcont(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> const &mtr) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::product_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t<MetricSpaceType, detail::rcont_mapping> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/core/scalar_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) sp(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> const &mtr) GA_NOEXCEPT {
auto lazy = make_lazy_context(lhs, rhs);
auto const lazy = make_lazy_context(lhs, rhs);
return lazy.eval(clifford_expression<default_integral_t, detail::product_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1>, detail::metric_space_mapping_t<MetricSpaceType, detail::sp_mapping> > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/extra/commutator_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ga {

template<typename LeftCoefficientType, typename LeftExpression, typename RightCoefficientType, typename RightExpression, typename MetricSpaceType>
constexpr decltype(auto) cp(clifford_expression<LeftCoefficientType, LeftExpression> const &lhs, clifford_expression<RightCoefficientType, RightExpression> const &rhs, metric_space<MetricSpaceType> 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>);
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/extra/grade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename CoefficientType, typename Expression, typename ToleranceType>
constexpr decltype(auto) largest_grade(clifford_expression<CoefficientType, 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<grade_t, detail::deduce_largest_grade_result_t<typename decltype(lazy)::template argument_expression_t<0>, detail::coefficient_t<typename decltype(lazy)::template argument_expression_t<1> > > >());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gatl/ga/extra/take_grade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace ga {
// Returns the k-grade part of the given Clifford expression.
template<typename CoefficientType, typename Expression, typename GradeCoefficientType, typename GradeCoefficient, typename = std::enable_if_t<std::is_constructible_v<grade_t, GradeCoefficientType> > >
constexpr decltype(auto) take_grade(clifford_expression<CoefficientType, Expression> const &arg, scalar_clifford_expression<GradeCoefficientType, GradeCoefficient> const &k) GA_NOEXCEPT {
auto lazy = make_lazy_context(arg, k);
auto const lazy = make_lazy_context(arg, k);
return lazy.eval(clifford_expression<default_integral_t, detail::keep_grade_t<typename decltype(lazy)::template argument_expression_t<0>, typename decltype(lazy)::template argument_expression_t<1> > >());
}

Expand Down
4 changes: 1 addition & 3 deletions cpp/tools/example/concepts/lazy_evaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions cpp/tools/test/size/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>);
Expand All @@ -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);
Expand Down

0 comments on commit f4e9361

Please sign in to comment.