Skip to content
Snippets Groups Projects
Commit 71503928 authored by Max Kahnt's avatar Max Kahnt
Browse files

Add isQuadratic compile-time check for static matrices (and scalars).

parent 88b250be
No related branches found
No related tags found
No related merge requests found
#install headers
install(FILES
fieldtraits.hh
isquadratic.hh
matrixtraits.hh
scalartraits.hh
utilities.hh
......
#ifndef DUNE_MATRIX_VECTOR_TRAITS_ISQUADRATIC_HH
#define DUNE_MATRIX_VECTOR_TRAITS_ISQUADRATIC_HH
#include <dune/matrix-vector/traits/utilities.hh>
/**
* \file
* \brief This may yield incorrect results for types whose ScalarTraits or
* MatrixTraits specializations are incomplete. Will report the dimension > 0
* in case the type is detected to be symmetric.
*/
namespace Dune {
namespace MatrixVector {
namespace Traits {
template <class, class Enable = void>
struct IsQuadratic {
constexpr static int dimension = 0;
};
template <class T>
struct IsQuadratic<T, EnableScalar<T>> {
constexpr static int dimension = 1;
};
template <class T>
using EnableNonScalarQuadraticMatrix =
std::enable_if_t<isMatrix<T>() and (MatrixTraits<T>::rows > 1) and
MatrixTraits<T>::rows == MatrixTraits<T>::cols>;
template <class T>
struct IsQuadratic<T, EnableNonScalarQuadraticMatrix<T>> {
constexpr static int dimension = MatrixTraits<T>::rows;
};
} // end namespace Traits
} // end namespace MatrixVector
} // end namespace Dune
#endif // DUNE_MATRIX_VECTOR_TRAITS_ISQUADRATIC_HH
......@@ -11,6 +11,9 @@
#include <dune/matrix-vector/traits/matrixtraits.hh>
#include <dune/matrix-vector/traits/vectortraits.hh>
// coming below to avoid circular dependency:
// #include <dune/matrix-vector/traits/isquadratic.hh>
namespace Dune {
namespace MatrixVector {
......@@ -82,4 +85,18 @@ constexpr auto isSparseRangeIterable() {
} // end namespace MatrixVector
} // end namespace Dune
#include <dune/matrix-vector/traits/isquadratic.hh>
namespace Dune {
namespace MatrixVector {
template <class T>
constexpr auto isQuadratic() {
return Std::bool_constant<Traits::IsQuadratic<std::decay_t<T>>::dimension>();
}
} // end namespace MatrixVector
} // end namespace Dune
#endif // DUNE_MATRIX_VECTOR_TRAITS_UTILITIES_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment