1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-11 14:40:46 +01:00

Added rank_non_trivial

This commit is contained in:
Michael Marshall 2019-02-12 22:15:55 +00:00
parent e7048231bc
commit 76c6a6772a
2 changed files with 25 additions and 7 deletions

View File

@ -56,22 +56,31 @@ namespace Grid {
template <typename T> struct grid_tensor_att { template <typename T> struct grid_tensor_att {
static constexpr unsigned int depth = 0; // How many levels of Grid Tensor there are static constexpr unsigned int depth = 0; // How many levels of Grid Tensor there are
static constexpr unsigned int rank = 0; // The rank of the grid tensor (i.e. how many indices used) 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) static constexpr unsigned int count = 1; // total number of elements (i.e. product of dimensions)
typedef T scalar_type; // Type of the underlying scalar typedef T scalar_type; // Type of the underlying scalar
static constexpr size_t scalar_size = sizeof(T); // Size of the underlying scalar in bytes static constexpr size_t scalar_size = sizeof(T); // Size of the underlying scalar in bytes
static constexpr size_t size = scalar_size * count; // total size of elements in bytes static constexpr 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> // e.g. iVector<iMatrix<Complex,3>,4>
// depth = 2 // depth = 2
// rank = 3 // rank = 3
// size = 36 // rank_non_trivial = 3
// count = 36
// e.g. iScalar<iVector<iMatrix<Complex,4>,3>> // e.g. iScalar<iVector<iMatrix<Complex,4>,3>>
// depth = 3 // depth = 3
// rank = 3 // rank = 3
// size = 48 // rank_non_trivial = 3
// count = 48
}; };
template <typename T> struct grid_tensor_att<iScalar<T>> { template <typename T> struct grid_tensor_att<iScalar<T>> {
static constexpr unsigned int depth = 1 + grid_tensor_att<T>::depth; 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 = 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; static constexpr unsigned int count = 1 * grid_tensor_att<T>::count;
typedef typename grid_tensor_att<T>::scalar_type scalar_type; typedef typename grid_tensor_att<T>::scalar_type scalar_type;
static constexpr size_t scalar_size = grid_tensor_att<T>::scalar_size; static constexpr size_t scalar_size = grid_tensor_att<T>::scalar_size;
@ -80,6 +89,7 @@ namespace Grid {
template <typename T, int N> struct grid_tensor_att<iVector<T, N>> { 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 depth = 1 + grid_tensor_att<T>::depth;
static constexpr unsigned int rank = 1 + grid_tensor_att<T>::rank; 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; static constexpr unsigned int count = N * grid_tensor_att<T>::count;
typedef typename grid_tensor_att<T>::scalar_type scalar_type; typedef typename grid_tensor_att<T>::scalar_type scalar_type;
static constexpr size_t scalar_size = grid_tensor_att<T>::scalar_size; static constexpr size_t scalar_size = grid_tensor_att<T>::scalar_size;
@ -88,6 +98,7 @@ namespace Grid {
template <typename T, int N> struct grid_tensor_att<iMatrix<T, N>> { 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 depth = 1 + grid_tensor_att<T>::depth;
static constexpr unsigned int rank = 2 + grid_tensor_att<T>::rank; 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; static constexpr unsigned int count = N * N * grid_tensor_att<T>::count;
typedef typename grid_tensor_att<T>::scalar_type scalar_type; typedef typename grid_tensor_att<T>::scalar_type scalar_type;
static constexpr size_t scalar_size = grid_tensor_att<T>::scalar_size; static constexpr size_t scalar_size = grid_tensor_att<T>::scalar_size;

View File

@ -574,7 +574,14 @@ struct rank<T[N]> : public std::integral_constant<std::size_t, rank<T>::value +
template <typename T> template <typename T>
void DebugGridTensorTest_print( int i ) void DebugGridTensorTest_print( int i )
{ {
std::cout << i << " : " << is_grid_tensor<T>::value << ", depth" << grid_tensor_att<T>::depth << ", rank" << grid_tensor_att<T>::rank << ", count" << grid_tensor_att<T>::count << ", scalar_size" << grid_tensor_att<T>::scalar_size << ", size" << grid_tensor_att<T>::size << std::endl; std::cout << i << " : " << is_grid_tensor<T>::value
<< ", depth " << grid_tensor_att<T>::depth
<< ", rank " << grid_tensor_att<T>::rank
<< ", rank_non_trivial " << grid_tensor_att<T>::rank_non_trivial
<< ", count " << grid_tensor_att<T>::count
<< ", scalar_size " << grid_tensor_att<T>::scalar_size
<< ", size " << grid_tensor_att<T>::size
<< std::endl;
} }
bool DebugGridTensorTest( void ) bool DebugGridTensorTest( void )
@ -583,9 +590,9 @@ bool DebugGridTensorTest( void )
typedef iScalar<t1> t2; typedef iScalar<t1> t2;
typedef iVector<t1, Ns> t3; typedef iVector<t1, Ns> t3;
typedef iMatrix<t1, Nc> t4; typedef iMatrix<t1, Nc> t4;
typedef iVector<iMatrix<t1,3>,4> t5; typedef iVector<iMatrix<t1,1>,4> t5;
typedef iScalar<t5> t6; typedef iScalar<t5> t6;
typedef iMatrix<iVector<iScalar<iMatrix<t6, 4>>,2>,7> t7; typedef iMatrix<iVector<iScalar<iMatrix<t6, 1>>,2>,7> t7;
int i = 1; int i = 1;
DebugGridTensorTest_print<t1>( i++ ); DebugGridTensorTest_print<t1>( i++ );
DebugGridTensorTest_print<t2>( i++ ); DebugGridTensorTest_print<t2>( i++ );
@ -605,8 +612,8 @@ int main(int argc, char *argv[])
std::cout << "sizeof(std::streamsize) = " << sizeof(std::streamsize) << std::endl; std::cout << "sizeof(std::streamsize) = " << sizeof(std::streamsize) << std::endl;
std::cout << "sizeof(Eigen::Index) = " << sizeof(Eigen::Index) << std::endl; std::cout << "sizeof(Eigen::Index) = " << sizeof(Eigen::Index) << std::endl;
//if( DebugEigenTest() ) return 0; //if( DebugEigenTest() ) return 0;
//if(DebugGridTensorTest()) return 0; if(DebugGridTensorTest()) return 0;
if(DebugIOTest()) return 0; //if(DebugIOTest()) return 0;
#endif #endif
// Decode command-line parameters. 1st one is which test to run // Decode command-line parameters. 1st one is which test to run