Skip to content
Snippets Groups Projects
Commit 052fdfb8 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'feature/static_size_eigen' into 'master'

add static size information for Eigen matrix type

See merge request !50
parents f194064a 5cd6e870
No related branches found
No related tags found
1 merge request!50add static size information for Eigen matrix type
......@@ -25,6 +25,12 @@ namespace Dune
class MultiTypeBlockVector;
}
namespace Eigen
{
template <typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix;
}
namespace AMDiS
{
namespace Impl
......@@ -60,6 +66,14 @@ namespace AMDiS
struct SizeImpl<Dune::MultiTypeBlockVector<Ts...>>
: std::integral_constant<std::size_t, sizeof...(Ts)> {};
template <class T, int N, int... opts>
struct SizeImpl<Eigen::Matrix<T,N,1,opts...>>
: std::integral_constant<std::size_t, (N >= 0 ? std::size_t(N) : 0u)> {};
template <class T, int N, int... opts>
struct SizeImpl<Eigen::Matrix<T,1,N,opts...>>
: std::integral_constant<std::size_t, (N >= 0 ? std::size_t(N) : 0u)> {};
// Specialization for arithmetic types
template <class T>
struct SizeImpl<T, std::enable_if_t<std::is_arithmetic<T>::value> >
......@@ -93,6 +107,10 @@ namespace AMDiS
struct RowsImpl<T, std::enable_if_t<std::is_arithmetic<T>::value> >
: std::integral_constant<std::size_t, 1> {};
template <class T, int N, int M, int... opts>
struct RowsImpl<Eigen::Matrix<T,N,M,opts...>>
: std::integral_constant<std::size_t, (N >= 0 ? std::size_t(N) : 0u)> {};
} // end namespace Impl
/// Get the number of rows in a fixed-size matrix
......@@ -121,6 +139,10 @@ namespace AMDiS
struct ColsImpl<T, std::enable_if_t<std::is_arithmetic<T>::value> >
: std::integral_constant<std::size_t, 1> {};
template <class T, int N, int M, int... opts>
struct ColsImpl<Eigen::Matrix<T,N,M,opts...>>
: std::integral_constant<std::size_t, (M >= 0 ? std::size_t(M) : 0u)> {};
} // end namespace Impl
/// Get the number of columns in a fixed-size matrix
......
......@@ -67,12 +67,15 @@ dune_add_test(SOURCES RangeTypeTest.cpp
dune_add_test(SOURCES ResizeTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES SwitchCasesTest.cpp
dune_add_test(SOURCES StaticSizeTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES StringTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES SwitchCasesTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES TreeDataTest.cpp
LINK_LIBRARIES amdis)
......
#include <amdis/AMDiS.hpp>
#include <amdis/common/StaticSize.hpp>
#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
#include <dune/istl/multitypeblockvector.hh>
#include <dune/istl/multitypeblockmatrix.hh>
#if HAVE_EIGEN
#include <Eigen/Dense>
#endif
#include "Tests.hpp"
using namespace AMDiS;
struct Null {};
int main(int argc, char** argv)
{
Environment env(argc, argv);
static_assert(Size_v<double> == 1, "");
static_assert(Rows_v<double> == 1, "");
static_assert(Cols_v<double> == 1, "");
static_assert(Size_v<Null> == 0, "");
static_assert(Rows_v<Null> == 0, "");
static_assert(Cols_v<Null> == 0, "");
using Vec1 = Dune::FieldVector<double,2>;
using Vec2 = Dune::MultiTypeBlockVector<double,double>;
using Vec3 = std::array<double,2>;
using Vec4 = std::tuple<double,double>;
using Vec5 = Dune::TupleVector<double,double>;
static_assert(Size_v<Vec1> == 2, "");
static_assert(Size_v<Vec2> == 2, "");
static_assert(Size_v<Vec3> == 2, "");
static_assert(Size_v<Vec4> == 2, "");
static_assert(Size_v<Vec5> == 2, "");
using Mat1 = Dune::FieldMatrix<double,2,2>;
using Mat2 = Dune::MultiTypeBlockMatrix<Vec2,Vec2>;
static_assert(Rows_v<Mat1> == 2, "");
static_assert(Cols_v<Mat1> == 2, "");
static_assert(Rows_v<Mat2> == 2, "");
static_assert(Cols_v<Mat2> == 2, "");
#if HAVE_EIGEN
using Vec6 = Eigen::Vector2d;
using Vec7 = Eigen::Matrix<double,2,1>;
using Vec8 = Eigen::Matrix<double,1,2>;
static_assert(Size_v<Vec6> == 2, "");
static_assert(Size_v<Vec7> == 2, "");
static_assert(Size_v<Vec8> == 2, "");
using Mat3 = Eigen::Matrix2d;
using Mat4 = Eigen::Matrix<double,2,2>;
static_assert(Rows_v<Mat3> == 2, "");
static_assert(Cols_v<Mat3> == 2, "");
static_assert(Rows_v<Mat4> == 2, "");
static_assert(Cols_v<Mat4> == 2, "");
#endif
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment