From 00e9416e0a84d633bf64995207d07782e68fdd8b Mon Sep 17 00:00:00 2001 From: Michael Marshall Date: Sat, 16 Feb 2019 17:08:22 +0000 Subject: [PATCH] Tweak to initialisation example --- Grid/serialisation/BaseIO.h | 4 ++-- tests/hadrons/Test_hadrons_distil.cc | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Grid/serialisation/BaseIO.h b/Grid/serialisation/BaseIO.h index 0b907e32..64e5a12c 100644 --- a/Grid/serialisation/BaseIO.h +++ b/Grid/serialisation/BaseIO.h @@ -187,10 +187,10 @@ namespace Grid { for( std::size_t j = 0; j < NumScalars; j++ ) { // if constexpr is C++ 17 ... but otherwise need two specialisations (Container vs Scalar) if constexpr ( InnerRank == 0 ) { - lambda( * pScalar, Seq++, &MyIndex[0] ); + lambda( * pScalar, Seq++, MyIndex ); } else { for( typename Scalar::scalar_type &Source : * pScalar ) { - lambda(Source, Seq++, &MyIndex[0] ); + lambda(Source, Seq++, MyIndex ); // Now increment SubIndex for( auto i = rank + InnerRank - 1; i != rank - 1 && ++MyIndex[i] == Dims[i]; i-- ) MyIndex[i] = 0; diff --git a/tests/hadrons/Test_hadrons_distil.cc b/tests/hadrons/Test_hadrons_distil.cc index 1dba073e..3c38e915 100644 --- a/tests/hadrons/Test_hadrons_distil.cc +++ b/tests/hadrons/Test_hadrons_distil.cc @@ -522,22 +522,28 @@ void EigenSliceExample2() using T2 = Eigen::Tensor; T3 a(2,3,4); - std::cout << "Initialising:a"; + std::cout << "Initialising a:"; + for_all( a, [&](TestScalar &c, float f, const std::array &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; for( int i = 0 ; i < a.dimension(0) ; i++ ) for( int j = 0 ; j < a.dimension(1) ; j++ ) for( int k = 0 ; k < a.dimension(2) ; k++ ) { 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++; } - std::cout << std::endl; + //std::cout << std::endl; //std::cout << "a initialised to:\n" << a << std::endl; DumpMemoryOrder( a, "a" ); std::cout << "for_all(a):"; - for_all( a, [&](TestScalar c, typename T3::Index n, const std::size_t * pDims ){ - std::cout << " (" << pDims[0] << "," << pDims[1] << "," << pDims[2] << ")<" << n << ">=" << c; + for_all( a, [&](TestScalar c, typename T3::Index n, const std::array &Dims ){ + std::cout << " (" << Dims[0] << "," << Dims[1] << "," << Dims[2] << ")<" << n << ">=" << c; } ); std::cout << std::endl; Eigen::array offsets = {0,1,1};