[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_COMPARABLE_HPP
#define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_COMPARABLE_HPP
#include "matrix.hpp"
#include <boost/hana/all.hpp>
#include <boost/hana/bool.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/eval_if.hpp>
#include <boost/hana/zip_with.hpp>
namespace boost { namespace hana {
template <unsigned R1, unsigned C1, unsigned R2, unsigned C2>
struct equal_impl<cppcon::Matrix<R1, C1>, cppcon::Matrix<R2, C2>> {
template <typename M1, typename M2>
static constexpr auto apply(M1 const& m1, M2 const& m2) {
return eval_if(bool_c<R1 == R2 && C1 == C2>,
[&](auto _) {
return all(zip_with(_(equal), cppcon::rows(m1),
cppcon::rows(m2)));
},
[] { return false_c; }
);
}
};
}}
#endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_COMPARABLE_HPP

View File

@@ -0,0 +1,60 @@
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_DET_HPP
#define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_DET_HPP
#include <boost/hana/equal.hpp>
#include <boost/hana/eval_if.hpp>
#include <boost/hana/front.hpp>
#include <boost/hana/functional/always.hpp>
#include <boost/hana/functional/fix.hpp>
#include <boost/hana/functional/flip.hpp>
#include <boost/hana/functional/on.hpp>
#include <boost/hana/functional/partial.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/plus.hpp>
#include <boost/hana/power.hpp>
#include <boost/hana/range.hpp>
#include <boost/hana/remove_at.hpp>
#include <boost/hana/transform.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/unpack.hpp>
#include <utility>
#include "matrix.hpp"
namespace cppcon {
namespace hana = boost::hana;
auto det = hana::fix([](auto det, auto&& m) -> decltype(auto) {
auto matrix_minor = [=](auto&& m, auto i, auto j) -> decltype(auto) {
return det(hana::unpack(
hana::transform(
hana::remove_at(rows(std::forward<decltype(m)>(m)), i),
hana::partial(hana::flip(hana::remove_at), j)
),
matrix
));
};
auto cofactor = [=](auto&& m, auto i, auto j) {
return hana::power(hana::int_c<-1>, hana::plus(i, j)) *
matrix_minor(std::forward<decltype(m)>(m), i, j);
};
return hana::eval_if(m.size() == hana::size_c<1>,
hana::always(m.at(hana::size_c<0>, hana::size_c<0>)),
[=](auto _) {
auto cofactors_1st_row = hana::unpack(_(hana::make_range)(hana::size_c<0>, m.ncolumns()),
hana::on(hana::make_tuple, hana::partial(cofactor, m, hana::size_c<0>))
);
return detail::tuple_scalar_product(hana::front(rows(m)), cofactors_1st_row);
}
);
});
} // end namespace cppcon
#endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_DET_HPP

View File

@@ -0,0 +1,33 @@
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_FUNCTOR_HPP
#define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_FUNCTOR_HPP
#include "matrix.hpp"
#include <boost/hana/functional/flip.hpp>
#include <boost/hana/functional/partial.hpp>
#include <boost/hana/concept/functor.hpp>
#include <utility>
namespace boost { namespace hana {
template <unsigned Rows, unsigned Columns>
struct transform_impl<cppcon::Matrix<Rows, Columns>> {
template <typename M, typename F>
static constexpr decltype(auto) apply(M&& m, F&& f) {
return unpack(
transform(
cppcon::rows(std::forward<M>(m)),
partial(flip(transform), std::forward<F>(f))
),
cppcon::matrix
);
}
};
}}
#endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_FUNCTOR_HPP

View File

@@ -0,0 +1,28 @@
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_GROUP_HPP
#define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_GROUP_HPP
#include "matrix.hpp"
#include <boost/hana/concept/group.hpp>
#include <utility>
namespace boost { namespace hana {
template <unsigned R, unsigned C>
struct minus_impl<cppcon::Matrix<R, C>, cppcon::Matrix<R, C>> {
template <typename M1, typename M2>
static constexpr decltype(auto) apply(M1&& m1, M2&& m2) {
return element_wise(minus)(
std::forward<M1>(m1),
std::forward<M2>(m2)
);
}
};
}}
#endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_GROUP_HPP

View File

@@ -0,0 +1,110 @@
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MATRIX_HPP
#define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MATRIX_HPP
#include <boost/hana/all_of.hpp>
#include <boost/hana/assert.hpp>
#include <boost/hana/at.hpp>
#include <boost/hana/drop_front.hpp>
#include <boost/hana/front.hpp>
#include <boost/hana/functional/on.hpp>
#include <boost/hana/functional/partial.hpp>
#include <boost/hana/fuse.hpp>
#include <boost/hana/length.hpp>
#include <boost/hana/mult.hpp>
#include <boost/hana/sum.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/unpack.hpp>
#include <boost/hana/value.hpp>
#include <boost/hana/zip.hpp>
#include <boost/hana/zip_with.hpp>
#include <utility>
namespace cppcon {
template <unsigned Rows, unsigned Columns>
struct Matrix { };
template <unsigned Rows, unsigned Columns, typename Storage>
struct matrix_type {
using hana_tag = Matrix<Rows, Columns>;
Storage rows_;
constexpr auto ncolumns() const
{ return boost::hana::length(boost::hana::front(rows_)); }
constexpr auto nrows() const
{ return boost::hana::length(rows_); }
constexpr auto size() const
{ return nrows() * ncolumns(); }
template <typename I, typename J>
constexpr decltype(auto) at(I i, J j) const
{ return boost::hana::at(boost::hana::at(rows_, i), j); }
};
auto row = boost::hana::make_tuple;
auto matrix = [](auto&& ...rows) -> decltype(auto) {
namespace hana = boost::hana;
auto storage = hana::make_tuple(std::forward<decltype(rows)>(rows)...);
auto ncolumns = hana::length(hana::front(storage));
BOOST_HANA_CONSTANT_CHECK(
hana::all_of(hana::drop_front(storage), [&](auto const& row) {
return hana::length(row) == ncolumns;
})
);
return matrix_type<
sizeof...(rows), hana::value(ncolumns), decltype(storage)
>{std::move(storage)};
};
auto vector = boost::hana::on(matrix, row);
// More operations
auto rows = [](auto&& m) -> decltype(auto) {
return std::forward<decltype(m)>(m).rows_;
};
auto transpose = [](auto&& m) -> decltype(auto) {
return boost::hana::unpack(
boost::hana::fuse(boost::hana::zip)(rows(std::forward<decltype(m)>(m))),
matrix
);
};
auto columns = [](auto&& m) -> decltype(auto) {
return rows(transpose(std::forward<decltype(m)>(m)));
};
auto element_wise = [](auto&& f) -> decltype(auto) {
namespace hana = boost::hana;
return [f(std::forward<decltype(f)>(f))](auto&& ...m) -> decltype(auto) {
return hana::unpack(
hana::zip_with(hana::partial(hana::zip_with, f),
rows(std::forward<decltype(m)>(m))...
),
matrix
);
};
};
namespace detail {
auto tuple_scalar_product = [](auto&& u, auto&& v) -> decltype(auto) {
namespace hana = boost::hana;
return hana::sum<>(hana::zip_with(hana::mult,
std::forward<decltype(u)>(u),
std::forward<decltype(v)>(v)
));
};
}
} // end namespace cppcon
#endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MATRIX_HPP

View File

@@ -0,0 +1,37 @@
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP
#define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP
#include "matrix.hpp"
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/concept/sequence.hpp>
#include <boost/hana/concept/monoid.hpp>
#include <boost/hana/range.hpp>
namespace boost { namespace hana {
template <unsigned R, unsigned C>
struct plus_impl<cppcon::Matrix<R, C>, cppcon::Matrix<R, C>> {
template <typename M1, typename M2>
static constexpr decltype(auto) apply(M1&& m1, M2&& m2) {
return element_wise(plus)(
std::forward<M1>(m1),
std::forward<M2>(m2)
);
}
};
template <unsigned R, unsigned C>
struct zero_impl<cppcon::Matrix<R, C>> {
static constexpr decltype(auto) apply() {
auto zeros = replicate(int_<0>, int_<C>);
return unpack(replicate(zeros, int_<R>), cppcon::matrix);
}
};
}}
#endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP

View File

@@ -0,0 +1,62 @@
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_RING_HPP
#define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_RING_HPP
#include "matrix.hpp"
#include <boost/hana/equal.hpp>
#include <boost/hana/fwd/mult.hpp>
#include <boost/hana/fwd/one.hpp>
#include <boost/hana/if.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/range.hpp>
#include <boost/hana/replicate.hpp>
#include <boost/hana/transform.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/unpack.hpp>
#include <boost/hana/zip_with.hpp>
#include <utility>
namespace boost { namespace hana {
template <unsigned R1, unsigned C1, unsigned R2, unsigned C2>
struct mult_impl<cppcon::Matrix<R1, C1>, cppcon::Matrix<R2, C2>> {
template <typename M1, typename M2>
static constexpr decltype(auto) apply(M1&& m1, M2&& m2) {
static_assert(C1 == R2,
"wrong dimensions for matrix multiplication");
auto cols = cppcon::columns(std::forward<M2>(m2));
return unpack(
transform(cppcon::rows(std::forward<M1>(m1)),
[&](auto&& row) -> decltype(auto) {
return zip_with(cppcon::detail::tuple_scalar_product,
replicate<tuple_tag>(std::forward<decltype(row)>(row), uint_c<R1>),
cols
);
}
),
cppcon::matrix
);
}
};
template <unsigned R, unsigned C>
struct one_impl<cppcon::Matrix<R, C>> {
static constexpr decltype(auto) apply() {
return unpack(range_c<unsigned, 0, R>, [](auto ...n) {
return unpack(range_c<unsigned, 0, C>, [=](auto ...m) {
auto row = [=](auto n) {
return cppcon::row(if_(n == m, int_c<1>, int_c<0>)...);
};
return cppcon::matrix(row(n)...);
});
});
}
};
}}
#endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_RING_HPP