diff --git a/Grid/serialisation/BaseIO.h b/Grid/serialisation/BaseIO.h index 3dd01a63..d5692490 100644 --- a/Grid/serialisation/BaseIO.h +++ b/Grid/serialisation/BaseIO.h @@ -62,9 +62,6 @@ namespace Grid { void write(const std::string &s, const iVector &output); template void write(const std::string &s, const iMatrix &output); - /*template - typename std::enable_if::value || Grid::is_complex::value, void>::type - write(const std::string &s, const Eigen::Tensor &output);*/ template typename std::enable_if, ETensor>::value && (std::is_arithmetic::value || Grid::is_complex::value), void>::type write(const std::string &s, const ETensor &output); @@ -181,15 +178,10 @@ namespace Grid { // Eigen::Tensors of arithmetic/complex base type template - /*template - typename std::enable_if::value || Grid::is_complex::value, void>::type - Writer::write(const std::string &s, const Eigen::Tensor &output)*/ template typename std::enable_if, ETensor>::value && (std::is_arithmetic::value || Grid::is_complex::value), void>::type Writer::write(const std::string &s, const ETensor &output) { - //typedef Eigen::Tensor Tensor; - //typedef Eigen::TensorBase Tensor; const typename ETensor::Index NumElements{output.size()}; assert( NumElements > 0 ); if( NumElements == 1 ) @@ -394,6 +386,18 @@ namespace Grid { Eigen::Tensor bResult = (lhs == rhs).all(); return bResult(0); } + + template + static inline typename std::enable_if, T>::value, bool>::type + CompareMember(const std::vector &lhs, const std::vector &rhs) { + const auto NumElements{lhs.size()}; + bool bResult = ( NumElements == rhs.size() ); + for( auto i = 0 ; i < NumElements && bResult ; i++ ) { + Eigen::Tensor b = (lhs[i] == rhs[i]).all(); + bResult = b(0); + } + return bResult; + } }; // Generic writer interface ////////////////////////////////////////////////// diff --git a/tests/hadrons/Test_hadrons_distil.cc b/tests/hadrons/Test_hadrons_distil.cc index 1e2378fa..7c1b7427 100644 --- a/tests/hadrons/Test_hadrons_distil.cc +++ b/tests/hadrons/Test_hadrons_distil.cc @@ -446,26 +446,6 @@ bool DebugEigenTest() return true; } -typedef iMatrix OddBall; -typedef Eigen::Tensor TensorOddBall; - -//typedef int TestScalar; -typedef std::complex TestScalar; -typedef Eigen::Tensor TestTensor; -typedef Eigen::TensorFixedSize> TestTensorFixed; - -// From Test_serialisation.cc -class myclass: Serializable { -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(myclass - , TestTensor, Critter - , TestTensorFixed, FixedCritter - , SpinColourVector, scv - , SpinColourMatrix, scm - ); - myclass() : Critter(7,3,2) {} -}; - template bool ioTest(const std::string &filename, const O &object, const std::string &name) { @@ -476,80 +456,62 @@ bool ioTest(const std::string &filename, const O &object, const std::string &nam } /*R reader(filename); - O buf; - bool good; - - read(reader, "testobject", buf); - good = (object == buf); - std::cout << name << " IO test: " << (good ? "success" : "failure"); - std::cout << std::endl; - return good;*/ + O buf; + bool good; + + read(reader, "testobject", buf); + good = (object == buf); + std::cout << name << " IO test: " << (good ? "success" : "failure"); + std::cout << std::endl; + return good;*/ return true; } -/* - template -eval Eigen::TensorForcedEvalOp, const Eigen::Tensor, const Eigen::Tensor >, Eigen::MakePointer> - - template - std::ostream& operator << (std::ostream& os, const TensorBase& expr) { - typedef TensorEvaluator, DefaultDevice> Evaluator; - typedef typename Evaluator::Dimensions Dimensions; - - // Evaluate the expression if needed - TensorForcedEvalOp eval = expr.eval(); - Evaluator tensor(eval, DefaultDevice()); - tensor.evalSubExprsIfNeeded(NULL); - - // Print the result - static const int rank = internal::array_size::value; - internal::TensorPrinter::run(os, tensor); - - // Cleanup. - tensor.cleanup(); - return os; - } -*/ - -template constexpr T Inc{1,-1}; -//template <> constexpr std::complex Inc< < std::complex > >{1,1}; +//typedef int TestScalar; +typedef std::complex TestScalar; +typedef Eigen::Tensor TestTensor; +typedef Eigen::TensorFixedSize> TestTensorFixed; +typedef std::vector aTestTensorFixed; +// From Test_serialisation.cc +class myclass: Serializable { +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(myclass + , SpinColourVector, scv + , SpinColourMatrix, scm + , TestTensor, Critter + , TestTensorFixed, FixedCritter + , aTestTensorFixed, aFixedCritter + ); + myclass() : Critter(7,3,2), aFixedCritter(3) {} +}; bool DebugIOTest(void) { - OddBall critter; - ioTest("iotest_oddball.h5", critter, "OddBall"); - SpinColourMatrix scm; - ioTest("iotest_matrix.h5", scm, "SpinColourMatrix"); SpinColourVector scv; ioTest("iotest_vector.h5", scv, "SpinColourVector"); + SpinColourMatrix scm; + ioTest("iotest_matrix.h5", scm, "SpinColourMatrix"); + + constexpr TestScalar Inc{1,-1}; TestTensor t(3,6,2); - TestScalar Val{Inc}; - for( int i = 0 ; i < 3 ; i++) - for( int j = 0 ; j < 6 ; j++) - for( int k = 0 ; k < 2 ; k++) { + TestScalar Val{Inc}; + for( int i = 0 ; i < t.dimension(0) ; i++) + for( int j = 0 ; j < t.dimension(1) ; j++) + for( int k = 0 ; k < t.dimension(2) ; k++) { t(i,j,k) = Val; - Val += Inc; + Val += Inc; } ioTest("iotest_tensor.h5", t, "eigen_tensor_instance_name"); - TestTensor t2(t); - t2(1,1,1) += Inc; - Eigen::Tensor rResult = (t == t2).all(); - if( rResult(0) ) - std::cout << "t2 == t" << std::endl; - else - std::cout << "t2 != t" << std::endl; - //std::cout << "(t == t2) : " << (t == t2).all()(0) << std::endl; - // Now serialise a fixed size tensor using FixedTensor = Eigen::TensorFixedSize>; FixedTensor tf; - Val = Inc; - for( int i = 0 ; i < 8 ; i++) - for( int j = 0 ; j < 4 ; j++) - for( int k = 0 ; k < 3 ; k++) { + Val = Inc; + for( int i = 0 ; i < tf.dimension(0) ; i++) + for( int j = 0 ; j < tf.dimension(1) ; j++) + for( int k = 0 ; k < tf.dimension(2) ; k++) { tf(i,j,k) = Val; - Val += Inc; + Val += Inc; } ioTest("iotest_tensor_fixed.h5", tf, "eigen_tensor_fixed_name");