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

Move traits classes and utilities to separate directory.

parent a5120bc2
No related branches found
No related tags found
1 merge request!5Feature/organize traits
add_subdirectory(test)
add_subdirectory(traits)
#install headers
install(FILES
......@@ -12,9 +13,7 @@ install(FILES
crossproduct.hh
genericvectortools.hh
ldlt.hh
matrixtraits.hh
promote.hh
scalartraits.hh
singlenonzerocolumnmatrix.hh
singlenonzerorowmatrix.hh
tranpose.hh
......
#ifndef DUNE_MATRIX_VECTOR_MATRIXTRAITS_HH
#define DUNE_MATRIX_VECTOR_MATRIXTRAITS_HH
#include <dune/common/diagonalmatrix.hh>
#include <dune/common/fmatrix.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/multitypeblockmatrix.hh>
#include <dune/istl/scaledidmatrix.hh>
namespace Dune {
namespace MatrixVector {
/** \brief Class to identify matrix types and extract information
*
* Specialize this class for all types that can be used like a matrix.
*/
template<class T>
struct MatrixTraits
{
constexpr static bool isMatrix = false;
constexpr static int rows = -1;
constexpr static int cols = -1;
};
template<class T, int n, int m>
struct MatrixTraits<Dune::FieldMatrix<T,n,m> >
{
constexpr static bool isMatrix = true;
constexpr static int rows = n;
constexpr static int cols = m;
};
template<class T, int n>
struct MatrixTraits<Dune::DiagonalMatrix<T,n> >
{
constexpr static bool isMatrix = true;
constexpr static int rows = n;
constexpr static int cols = n;
};
template<class T, int n>
struct MatrixTraits<Dune::ScaledIdentityMatrix<T,n> >
{
constexpr static bool isMatrix = true;
constexpr static int rows = n;
constexpr static int cols = n;
};
template<class T>
struct MatrixTraits<Dune::BCRSMatrix<T> >
{
constexpr static bool isMatrix = true;
};
template<class... T>
struct MatrixTraits<MultiTypeBlockMatrix<T...> >
{
constexpr static bool isMatrix = true;
};
}
}
#endif
#ifndef DUNE_MATRIX_VECTOR_SCALARTRAITS_HH
#define DUNE_MATRIX_VECTOR_SCALARTRAITS_HH
#include <dune/common/diagonalmatrix.hh>
#include <dune/common/fmatrix.hh>
#include <dune/common/typetraits.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/scaledidmatrix.hh>
namespace Dune {
namespace MatrixVector {
/** \brief Class to identify scalar types
*
* Specialize this class for all types that can be used
* like scalar quantities.
*/
template <class T>
struct ScalarTraits {
constexpr static bool isScalar = Dune::IsNumber<T>::value;
};
template <class T>
struct ScalarTraits<Dune::FieldVector<T, 1>> {
constexpr static bool isScalar = true;
};
template <class T>
struct ScalarTraits<Dune::FieldMatrix<T, 1, 1>> {
constexpr static bool isScalar = true;
};
template <class T>
struct ScalarTraits<Dune::DiagonalMatrix<T, 1>> {
constexpr static bool isScalar = true;
};
template <class T>
struct ScalarTraits<Dune::ScaledIdentityMatrix<T, 1>> {
constexpr static bool isScalar = true;
};
}
}
#endif
#install headers
install(FILES
scalartraits.hh
matrixtraits.hh
vectortraits.hh
utilities.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/matrix-vector/traits)
#ifndef DUNE_MATRIX_VECTOR_TRAITS_MATRIXTRAITS_HH
#define DUNE_MATRIX_VECTOR_TRAITS_MATRIXTRAITS_HH
#include <dune/common/diagonalmatrix.hh>
#include <dune/common/fmatrix.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/multitypeblockmatrix.hh>
#include <dune/istl/scaledidmatrix.hh>
namespace Dune {
namespace MatrixVector {
namespace Traits {
/** \brief Class to identify matrix types and extract information
*
* Specialize this class for all types that can be used like a matrix.
*/
template<class T>
struct MatrixTraits {
constexpr static bool isMatrix = false;
constexpr static int rows = -1;
constexpr static int cols = -1;
};
template<class T, int n, int m>
struct MatrixTraits<FieldMatrix<T, n, m>> {
constexpr static bool isMatrix = true;
constexpr static int rows = n;
constexpr static int cols = m;
};
template<class T, int n>
struct MatrixTraits<DiagonalMatrix<T, n>> {
constexpr static bool isMatrix = true;
constexpr static int rows = n;
constexpr static int cols = n;
};
template<class T, int n>
struct MatrixTraits<ScaledIdentityMatrix<T, n>> {
constexpr static bool isMatrix = true;
constexpr static int rows = n;
constexpr static int cols = n;
};
template<class T>
struct MatrixTraits<BCRSMatrix<T>> {
constexpr static bool isMatrix = true;
};
template<class... T>
struct MatrixTraits<MultiTypeBlockMatrix<T...> > {
constexpr static bool isMatrix = true;
};
} // end namespace Traits
} // end namespace MatrixVector
} // end namespace Dune
#endif // DUNE_MATRIX_VECTOR_TRAITS_MATRIXTRAITS_HH
#ifndef DUNE_MATRIX_VECTOR_TRAITS_SCALARTRAITS_HH
#define DUNE_MATRIX_VECTOR_TRAITS_SCALARTRAITS_HH
#include <dune/common/diagonalmatrix.hh>
#include <dune/common/fmatrix.hh>
#include <dune/common/typetraits.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/scaledidmatrix.hh>
namespace Dune {
namespace MatrixVector {
namespace Traits {
/** \brief Class to identify scalar types
*
* Specialize this class for all types that can be used
* like scalar quantities.
*/
template <class T>
struct ScalarTraits {
constexpr static bool isScalar = Dune::IsNumber<T>::value;
};
template <class T>
struct ScalarTraits<Dune::FieldVector<T, 1>> {
constexpr static bool isScalar = true;
};
template <class T>
struct ScalarTraits<Dune::FieldMatrix<T, 1, 1>> {
constexpr static bool isScalar = true;
};
template <class T>
struct ScalarTraits<Dune::DiagonalMatrix<T, 1>> {
constexpr static bool isScalar = true;
};
template <class T>
struct ScalarTraits<Dune::ScaledIdentityMatrix<T, 1>> {
constexpr static bool isScalar = true;
};
} // end namespace Traits
} // end namespace MatrixVector
} // end namespace Dune
#endif // DUNE_MATRIX_VECTOR_TRAITS_SCALARTRAITS_HH
#ifndef DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH
#define DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH
#ifndef DUNE_MATRIX_VECTOR_UTILITIES_HH
#define DUNE_MATRIX_VECTOR_UTILITIES_HH
#include <type_traits>
......@@ -7,9 +7,9 @@
#include <dune/common/typetraits.hh>
#include <dune/matrix-vector/concepts.hh>
#include <dune/matrix-vector/scalartraits.hh>
#include <dune/matrix-vector/matrixtraits.hh>
#include <dune/matrix-vector/vectortraits.hh>
#include <dune/matrix-vector/traits/scalartraits.hh>
#include <dune/matrix-vector/traits/matrixtraits.hh>
#include <dune/matrix-vector/traits/vectortraits.hh>
namespace Dune {
namespace MatrixVector {
......@@ -17,22 +17,22 @@ namespace MatrixVector {
// convenience compile-time functions to classify types
template <class T>
constexpr auto isNumber() {
return Std::bool_constant<IsNumber<T>::value>();
return Std::bool_constant<IsNumber<std::decay_t<T>>::value>();
}
template <class T>
constexpr auto isScalar() {
return Std::bool_constant<ScalarTraits<T>::isScalar>();
return Std::bool_constant<Traits::ScalarTraits<std::decay_t<T>>::isScalar>();
}
template <class T>
constexpr auto isVector() {
return Std::bool_constant<VectorTraits<T>::isVector>();
return Std::bool_constant<Traits::VectorTraits<std::decay_t<T>>::isVector>();
}
template <class T>
constexpr auto isMatrix() {
return Std::bool_constant<MatrixTraits<T>::isMatrix>();
return Std::bool_constant<Traits::MatrixTraits<std::decay_t<T>>::isMatrix>();
}
template <class T>
......@@ -41,30 +41,36 @@ constexpr auto isTupleOrDerived() {
}
// enable_if typedefs for traits ...
template <class T>
using EnableNumber = std::enable_if_t<isNumber<T>()>;
template <class T, class R = void>
using EnableNumber = std::enable_if_t<isNumber<T>(), R>;
template <class T>
using EnableScalar = std::enable_if_t<isScalar<T>()>;
template <class T, class R = void>
using EnableScalar = std::enable_if_t<isScalar<T>(), R>;
template <class T>
using EnableVector = std::enable_if_t<isVector<T>()>;
template <class T, class R = void>
using EnableVector = std::enable_if_t<isVector<T>(), R>;
template <class T>
using EnableMatrix = std::enable_if_t<isMatrix<T>()>;
template <class T, class R = void>
using EnableMatrix = std::enable_if_t<isMatrix<T>(), R>;
template <class T, class R = void>
using EnableTupleOrDerived = std::enable_if_t<isTupleOrDerived<T>(), R>;
// ... and their negations
template <class T>
using DisableNumber = std::enable_if_t<not isNumber<T>()>;
template <class T, class R = void>
using DisableNumber = std::enable_if_t<not isNumber<T>(), R>;
template <class T>
using DisableScalar = std::enable_if_t<not isScalar<T>()>;
template <class T, class R = void>
using DisableScalar = std::enable_if_t<not isScalar<T>(), R>;
template <class T>
using DisableVector = std::enable_if_t<not isVector<T>()>;
template <class T, class R = void>
using DisableVector = std::enable_if_t<not isVector<T>(), R>;
template <class T>
using DisableMatrix = std::enable_if_t<not isMatrix<T>()>;
template <class T, class R = void>
using DisableMatrix = std::enable_if_t<not isMatrix<T>(), R>;
template <class T, class R = void>
using DisableTupleOrDerived = std::enable_if_t<not isTupleOrDerived<T>(), R>;
// compile-time property checks
template <class T>
......@@ -76,4 +82,4 @@ constexpr auto isSparseRangeIterable() {
} // end namespace MatrixVector
} // end namespace Dune
#endif // DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH
#endif // DUNE_MATRIX_VECTOR_TRAITS_UTILITIES_HH
#ifndef DUNE_MATRIX_VECTOR_VECTORTRAITS_HH
#define DUNE_MATRIX_VECTOR_VECTORTRAITS_HH
#ifndef DUNE_MATRIX_VECTOR_TRAITS_VECTORTRAITS_HH
#define DUNE_MATRIX_VECTOR_TRAITS_VECTORTRAITS_HH
#include <dune/common/fvector.hh>
#include <dune/istl/bvector.hh>
......@@ -7,6 +7,7 @@
namespace Dune {
namespace MatrixVector {
namespace Traits {
/** \brief Class to identify vector types and extract information
*
......@@ -27,7 +28,8 @@ struct VectorTraits<BlockVector<Block>> {
constexpr static bool isVector = true;
};
} // end namespace Traits
} // end namespace MatrixVector
} // end namespace Dune
#endif // DUNE_MATRIX_VECTOR_VECTORTRAITS_HH
#endif // DUNE_MATRIX_VECTOR_TRAITS_VECTORTRAITS_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment