1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Tweak to initialisation example

This commit is contained in:
Michael Marshall 2019-02-16 17:08:22 +00:00
parent b6803a070a
commit 00e9416e0a
2 changed files with 14 additions and 8 deletions

View File

@ -187,10 +187,10 @@ namespace Grid {
for( std::size_t j = 0; j < NumScalars; j++ ) { for( std::size_t j = 0; j < NumScalars; j++ ) {
// if constexpr is C++ 17 ... but otherwise need two specialisations (Container vs Scalar) // if constexpr is C++ 17 ... but otherwise need two specialisations (Container vs Scalar)
if constexpr ( InnerRank == 0 ) { if constexpr ( InnerRank == 0 ) {
lambda( * pScalar, Seq++, &MyIndex[0] ); lambda( * pScalar, Seq++, MyIndex );
} else { } else {
for( typename Scalar::scalar_type &Source : * pScalar ) { for( typename Scalar::scalar_type &Source : * pScalar ) {
lambda(Source, Seq++, &MyIndex[0] ); lambda(Source, Seq++, MyIndex );
// Now increment SubIndex // Now increment SubIndex
for( auto i = rank + InnerRank - 1; i != rank - 1 && ++MyIndex[i] == Dims[i]; i-- ) for( auto i = rank + InnerRank - 1; i != rank - 1 && ++MyIndex[i] == Dims[i]; i-- )
MyIndex[i] = 0; MyIndex[i] = 0;

View File

@ -522,22 +522,28 @@ void EigenSliceExample2()
using T2 = Eigen::Tensor<TestScalar, 2, Options>; using T2 = Eigen::Tensor<TestScalar, 2, Options>;
T3 a(2,3,4); T3 a(2,3,4);
std::cout << "Initialising:a"; std::cout << "Initialising a:";
for_all( a, [&](TestScalar &c, float f, const std::array<size_t,T3::NumIndices> &Dims ){
c = TestScalar{f,-f};
std::cout << " a(" << Dims[0] << "," << Dims[1] << "," << Dims[2] << ")=" << c;
} );
std::cout << std::endl;
//std::cout << "Validating a:";
float z = 0; float z = 0;
for( int i = 0 ; i < a.dimension(0) ; i++ ) for( int i = 0 ; i < a.dimension(0) ; i++ )
for( int j = 0 ; j < a.dimension(1) ; j++ ) for( int j = 0 ; j < a.dimension(1) ; j++ )
for( int k = 0 ; k < a.dimension(2) ; k++ ) { for( int k = 0 ; k < a.dimension(2) ; k++ ) {
TestScalar w{z, -z}; TestScalar w{z, -z};
a(i,j,k) = w; //std::cout << " a(" << i << "," << j << "," << k << ")=" << w;
std::cout << " a(" << i << "," << j << "," << k << ")=" << w; assert( a(i,j,k) == w );
z++; z++;
} }
std::cout << std::endl; //std::cout << std::endl;
//std::cout << "a initialised to:\n" << a << std::endl; //std::cout << "a initialised to:\n" << a << std::endl;
DumpMemoryOrder( a, "a" ); DumpMemoryOrder( a, "a" );
std::cout << "for_all(a):"; std::cout << "for_all(a):";
for_all( a, [&](TestScalar c, typename T3::Index n, const std::size_t * pDims ){ for_all( a, [&](TestScalar c, typename T3::Index n, const std::array<size_t,T3::NumIndices> &Dims ){
std::cout << " (" << pDims[0] << "," << pDims[1] << "," << pDims[2] << ")<" << n << ">=" << c; std::cout << " (" << Dims[0] << "," << Dims[1] << "," << Dims[2] << ")<" << n << ">=" << c;
} ); } );
std::cout << std::endl; std::cout << std::endl;
Eigen::array<typename T3::Index, 3> offsets = {0,1,1}; Eigen::array<typename T3::Index, 3> offsets = {0,1,1};