mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-17 23:37:06 +01:00
Finalising traits
This commit is contained in:
@ -174,36 +174,36 @@ class iScalar {
|
||||
};
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
typename std::enable_if<!isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline begin() const { return &_internal; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
typename std::enable_if<isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline begin() const { return _internal.begin(); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return (&_internal) + grid_tensor_att<iScalar<T>>::count; }
|
||||
typename std::enable_if<!isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return (&_internal) + 1; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal.begin() + grid_tensor_att<iScalar<T>>::count; }
|
||||
typename std::enable_if<isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal.begin() + sizeof(_internal)/sizeof(scalar_type); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, scalar_type *>::type
|
||||
typename std::enable_if<!isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline begin() { return &_internal; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, scalar_type *>::type
|
||||
typename std::enable_if<isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline begin() { return _internal.begin(); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return (&_internal) + grid_tensor_att<iScalar<T>>::count; }
|
||||
typename std::enable_if<!isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return (&_internal) + 1; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal.begin() + grid_tensor_att<iScalar<T>>::count; }
|
||||
typename std::enable_if<isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal.begin() + sizeof(_internal)/sizeof(scalar_type); }
|
||||
};
|
||||
///////////////////////////////////////////////////////////
|
||||
// Allows to turn scalar<scalar<scalar<double>>>> back to double.
|
||||
@ -335,36 +335,36 @@ class iVector {
|
||||
// }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
typename std::enable_if<!isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline begin() const { return _internal; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
typename std::enable_if<isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline begin() const { return _internal[0].begin(); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal + grid_tensor_att<iVector<T,N>>::count; }
|
||||
typename std::enable_if<!isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal + N; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal[0].begin() + grid_tensor_att<iVector<T,N>>::count; }
|
||||
typename std::enable_if<isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal[0].begin() + sizeof(_internal)/sizeof(scalar_type); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, scalar_type *>::type
|
||||
typename std::enable_if<!isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline begin() { return _internal; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, scalar_type *>::type
|
||||
typename std::enable_if<isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline begin() { return _internal[0].begin(); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal + grid_tensor_att<iVector<T,N>>::count; }
|
||||
typename std::enable_if<!isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal + N; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal[0].begin() + grid_tensor_att<iVector<T,N>>::count; }
|
||||
typename std::enable_if<isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal[0].begin() + sizeof(_internal)/sizeof(scalar_type); }
|
||||
};
|
||||
|
||||
template <class vtype, int N>
|
||||
@ -522,36 +522,36 @@ class iMatrix {
|
||||
// }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
typename std::enable_if<!isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline begin() const { return _internal[0]; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
typename std::enable_if<isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline begin() const { return _internal[0][0].begin(); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal[0] + grid_tensor_att<iMatrix<T,N>>::count; }
|
||||
typename std::enable_if<!isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal[0] + N * N; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal[0][0].begin() + grid_tensor_att<iMatrix<T,N>>::count; }
|
||||
typename std::enable_if<isGridTensor<T>::value, const scalar_type *>::type
|
||||
strong_inline end() const { return _internal[0][0].begin() + sizeof(_internal)/sizeof(scalar_type); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, scalar_type *>::type
|
||||
typename std::enable_if<!isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline begin() { return _internal[0]; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, scalar_type *>::type
|
||||
typename std::enable_if<isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline begin() { return _internal[0][0].begin(); }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<!is_grid_tensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal[0] + grid_tensor_att<iMatrix<T,N>>::count; }
|
||||
typename std::enable_if<!isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal[0] + N * N; }
|
||||
|
||||
template <typename T = vtype>
|
||||
typename std::enable_if<is_grid_tensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal[0][0].begin() + grid_tensor_att<iMatrix<T,N>>::count; }
|
||||
typename std::enable_if<isGridTensor<T>::value, scalar_type *>::type
|
||||
strong_inline end() { return _internal[0][0].begin() + sizeof(_internal)/sizeof(scalar_type); }
|
||||
};
|
||||
|
||||
template <class v>
|
||||
|
@ -288,79 +288,6 @@ namespace Grid {
|
||||
|
||||
enum { value = sizeof(real_scalar_type)/sizeof(float) };
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Review with Peter - obvious (but partial) overlap with the above
|
||||
// What of this is good and should be kept ... vs what functions should I really be using?
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Need some forward references or the below won't work
|
||||
template <class vtype>
|
||||
class iScalar;
|
||||
template <class vtype, int N>
|
||||
class iVector;
|
||||
template <class vtype, int N>
|
||||
class iMatrix;
|
||||
|
||||
// which types are grid tensors
|
||||
template <typename T> struct is_grid_tensor : public std::false_type {};
|
||||
template <typename T> struct is_grid_tensor<iScalar<T>> : public std::true_type {};
|
||||
template <typename T, int N> struct is_grid_tensor<iVector<T, N>> : public std::true_type {};
|
||||
template <typename T, int N> struct is_grid_tensor<iMatrix<T, N>> : public std::true_type {};
|
||||
|
||||
// Rank and dimension of grid tensors, i.e. compositions of iScalar, iVector and iMatrix
|
||||
// This defines the bottom level - i.e. it's a description of the underlying scalar
|
||||
template <typename T> struct grid_tensor_att {
|
||||
static constexpr unsigned int depth = 0; // How many levels of Grid Tensor there are (TensorLevel)
|
||||
static constexpr unsigned int rank = 0; // The rank of the grid tensor (i.e. how many indices used)
|
||||
static constexpr unsigned int rank_non_trivial = 0; // As per rank, but excludes those of dimension 1
|
||||
static constexpr unsigned int count = 1; // total number of elements (i.e. product of dimensions)
|
||||
using scalar_type = T; // Type of the underlying scalar
|
||||
static constexpr std::size_t scalar_size = sizeof(T); // Size of the underlying scalar in bytes
|
||||
static constexpr std::size_t size = scalar_size * count; // total size of elements in bytes
|
||||
// e.g. iScalar<iVector<Complex,1>>
|
||||
// depth = 2
|
||||
// rank = 1
|
||||
// rank_non_trivial = 0
|
||||
// count = 1
|
||||
// e.g. iVector<iMatrix<Complex,3>,4>
|
||||
// depth = 2
|
||||
// rank = 3
|
||||
// rank_non_trivial = 3
|
||||
// count = 36
|
||||
// e.g. iScalar<iVector<iMatrix<Complex,4>,3>>
|
||||
// depth = 3
|
||||
// rank = 3
|
||||
// rank_non_trivial = 3
|
||||
// count = 48
|
||||
};
|
||||
template <typename T> struct grid_tensor_att<iScalar<T>> {
|
||||
static constexpr unsigned int depth = 1 + grid_tensor_att<T>::depth;
|
||||
static constexpr unsigned int rank = 0 + grid_tensor_att<T>::rank;
|
||||
static constexpr unsigned int rank_non_trivial = 0 + grid_tensor_att<T>::rank_non_trivial;
|
||||
static constexpr unsigned int count = 1 * grid_tensor_att<T>::count;
|
||||
using scalar_type = typename grid_tensor_att<T>::scalar_type;
|
||||
static constexpr std::size_t scalar_size = grid_tensor_att<T>::scalar_size;
|
||||
static constexpr std::size_t size = scalar_size * count;
|
||||
};
|
||||
template <typename T, int N> struct grid_tensor_att<iVector<T, N>> {
|
||||
static constexpr unsigned int depth = 1 + grid_tensor_att<T>::depth;
|
||||
static constexpr unsigned int rank = 1 + grid_tensor_att<T>::rank;
|
||||
static constexpr unsigned int rank_non_trivial = (N>1 ? 1 : 0) + grid_tensor_att<T>::rank_non_trivial;
|
||||
static constexpr unsigned int count = N * grid_tensor_att<T>::count;
|
||||
using scalar_type = typename grid_tensor_att<T>::scalar_type;
|
||||
static constexpr std::size_t scalar_size = grid_tensor_att<T>::scalar_size;
|
||||
static constexpr std::size_t size = scalar_size * count;
|
||||
};
|
||||
template <typename T, int N> struct grid_tensor_att<iMatrix<T, N>> {
|
||||
static constexpr unsigned int depth = 1 + grid_tensor_att<T>::depth;
|
||||
static constexpr unsigned int rank = 2 + grid_tensor_att<T>::rank;
|
||||
static constexpr unsigned int rank_non_trivial = (N>1 ? 2 : 0) + grid_tensor_att<T>::rank_non_trivial;
|
||||
static constexpr unsigned int count = N * N * grid_tensor_att<T>::count;
|
||||
using scalar_type = typename grid_tensor_att<T>::scalar_type;
|
||||
static constexpr std::size_t scalar_size = grid_tensor_att<T>::scalar_size;
|
||||
static constexpr std::size_t size = scalar_size * count;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user