2016-01-02 14:51:32 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
2017-07-11 14:31:57 +01:00
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
2016-01-02 14:51:32 +00:00
|
|
|
|
|
|
|
Source file: ./tests/Test_serialisation.cc
|
|
|
|
|
2017-01-23 14:57:38 +00:00
|
|
|
Copyright (C) 2015-2016
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2017-01-23 14:57:38 +00:00
|
|
|
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
2016-01-02 14:51:32 +00:00
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2016-07-07 22:31:07 +01:00
|
|
|
#include <Grid/Grid.h>
|
2015-08-20 16:21:26 +01:00
|
|
|
|
2015-12-08 13:54:00 +00:00
|
|
|
using namespace Grid;
|
2017-06-11 23:14:10 +01:00
|
|
|
using namespace Grid::QCD;
|
2015-12-08 13:54:00 +00:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
GRID_SERIALIZABLE_ENUM(myenum, undef, red, 1, blue, 2, green, 3);
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
class myclass: Serializable {
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(myclass,
|
|
|
|
myenum, e,
|
|
|
|
std::vector<myenum>, ve,
|
|
|
|
std::string, name,
|
|
|
|
int, x,
|
|
|
|
double, y,
|
|
|
|
bool , b,
|
|
|
|
std::vector<double>, array,
|
2017-06-13 10:48:43 +01:00
|
|
|
std::vector<std::vector<double> >, twodimarray,
|
2018-03-08 19:12:03 +00:00
|
|
|
std::vector<std::vector<std::vector<Complex> > >, cmplx3darray,
|
|
|
|
SpinColourMatrix, scm
|
2017-01-19 01:41:05 +00:00
|
|
|
);
|
|
|
|
myclass() {}
|
|
|
|
myclass(int i)
|
2017-01-20 20:10:41 +00:00
|
|
|
: array(4,5.1)
|
|
|
|
, twodimarray(3,std::vector<double>(5, 1.23456))
|
|
|
|
, cmplx3darray(3,std::vector<std::vector<Complex>>(5, std::vector<Complex>(7, Complex(1.2, 3.4))))
|
|
|
|
, ve(2, myenum::blue)
|
2017-01-19 01:41:05 +00:00
|
|
|
{
|
|
|
|
e=myenum::red;
|
|
|
|
x=i;
|
|
|
|
y=2*i;
|
|
|
|
b=true;
|
|
|
|
name="bother said pooh";
|
2018-03-08 19:12:03 +00:00
|
|
|
scm()(0, 1)(2, 1) = 2.356;
|
|
|
|
scm()(3, 0)(1, 1) = 1.323;
|
|
|
|
scm()(2, 1)(0, 1) = 5.3336;
|
|
|
|
scm()(0, 2)(1, 1) = 6.336;
|
|
|
|
scm()(2, 1)(2, 2) = 7.344;
|
|
|
|
scm()(1, 1)(2, 0) = 8.3534;
|
2017-01-19 01:41:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int16_t i16 = 1;
|
2015-08-20 16:21:26 +01:00
|
|
|
uint16_t u16 = 2;
|
2017-01-19 01:41:05 +00:00
|
|
|
int32_t i32 = 3;
|
2015-08-20 16:21:26 +01:00
|
|
|
uint32_t u32 = 4;
|
2017-01-19 01:41:05 +00:00
|
|
|
int64_t i64 = 5;
|
2015-08-20 16:21:26 +01:00
|
|
|
uint64_t u64 = 6;
|
2017-01-19 01:41:05 +00:00
|
|
|
float f = M_PI;
|
|
|
|
double d = 2*M_PI;
|
|
|
|
bool b = false;
|
2015-08-20 16:21:26 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
template <typename W, typename R, typename O>
|
|
|
|
void ioTest(const std::string &filename, const O &object, const std::string &name)
|
2015-08-20 16:21:26 +01:00
|
|
|
{
|
2019-02-18 08:55:50 +00:00
|
|
|
std::cout << name << " IO test: writing ...";
|
2017-01-19 01:41:05 +00:00
|
|
|
// writer needs to be destroyed so that writing physically happens
|
2015-08-20 16:21:26 +01:00
|
|
|
{
|
2017-01-19 01:41:05 +00:00
|
|
|
W writer(filename);
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
write(writer, "testobject", object);
|
|
|
|
}
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2019-02-18 08:55:50 +00:00
|
|
|
std::cout << " done. reading...";
|
2017-01-19 01:41:05 +00:00
|
|
|
R reader(filename);
|
|
|
|
O buf;
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
read(reader, "testobject", buf);
|
2019-02-18 08:55:50 +00:00
|
|
|
bool good = Serializable::CompareMember(object, buf);
|
|
|
|
if (!good) {
|
|
|
|
std::cout << " failure!" << std::endl;
|
2019-02-18 17:12:27 +00:00
|
|
|
if constexpr (EigenIO::is_tensor<O>::value)
|
|
|
|
dump_tensor(buf,"???");
|
2019-02-18 08:55:50 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
std::cout << " done." << std::endl;
|
2019-02-13 12:14:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 21:40:53 +00:00
|
|
|
#ifdef HAVE_HDF5
|
|
|
|
typedef Eigen::Tensor<int, 5> ShortRank5Tensor;
|
2019-02-13 12:14:01 +00:00
|
|
|
//typedef int TestScalar;
|
|
|
|
typedef std::complex<double> TestScalar;
|
2019-02-13 21:48:35 +00:00
|
|
|
typedef Eigen::Tensor<TestScalar, 3, Eigen::StorageOptions::RowMajor> TestTensor;
|
|
|
|
typedef Eigen::TensorFixedSize<TestScalar, Eigen::Sizes<9,4,2>, Eigen::StorageOptions::RowMajor> TestTensorFixed;
|
2019-02-13 12:14:01 +00:00
|
|
|
typedef std::vector<TestTensorFixed> aTestTensorFixed;
|
2019-02-18 17:12:27 +00:00
|
|
|
typedef Eigen::TensorFixedSize<SpinColourVector, Eigen::Sizes<11,3,2>, Eigen::StorageOptions::RowMajor> LSCTensor;
|
|
|
|
typedef Eigen::TensorFixedSize<LorentzColourMatrix, Eigen::Sizes<5,7,2>, Eigen::StorageOptions::RowMajor> LCMTensor;
|
2019-02-13 12:14:01 +00:00
|
|
|
// From Test_serialisation.cc
|
2019-02-18 17:12:27 +00:00
|
|
|
class PerambIOTestClass: Serializable {
|
2019-02-13 12:14:01 +00:00
|
|
|
public:
|
2019-02-18 17:12:27 +00:00
|
|
|
using PerambTensor = Eigen::Tensor<SpinColourVector, 6, Eigen::StorageOptions::RowMajor>;
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(PerambIOTestClass
|
2019-02-18 21:40:53 +00:00
|
|
|
, ShortRank5Tensor, shortRank5Tensor
|
|
|
|
, PerambTensor, Perambulator
|
2019-02-18 17:12:27 +00:00
|
|
|
, std::vector<std::string>, DistilParameterNames
|
|
|
|
, std::vector<int>, DistilParameterValues
|
2019-02-18 21:40:53 +00:00
|
|
|
, PerambTensor, Perambulator2
|
|
|
|
, SpinColourVector, scv
|
|
|
|
, SpinColourMatrix, scm
|
2019-02-18 17:12:27 +00:00
|
|
|
//, TestTensor, Critter
|
|
|
|
//, TestTensorFixed, FixedCritter
|
|
|
|
//, aTestTensorFixed, aFixedCritter
|
|
|
|
//, LSCTensor, MyLSCTensor
|
|
|
|
//, LCMTensor, MyLCMTensor
|
2019-02-13 12:14:01 +00:00
|
|
|
);
|
2019-02-18 21:40:53 +00:00
|
|
|
PerambIOTestClass() : Perambulator(2,3,1,4,5,1), Perambulator2(7,1,6,1,5,1),
|
2019-02-18 17:12:27 +00:00
|
|
|
DistilParameterNames {"alpha", "beta", "gamma", "delta", "epsilon", "what's f?"},
|
2019-02-18 21:40:53 +00:00
|
|
|
DistilParameterValues{2,3,1,4,5,1}
|
|
|
|
, shortRank5Tensor{5,4,3,2,1}
|
|
|
|
//, Critter(7,3,2)//, aFixedCritter(3)
|
|
|
|
{
|
|
|
|
Sequential_Init(Perambulator);
|
|
|
|
Sequential_Init(Perambulator2, {-3.1415927,7});
|
|
|
|
Sequential_Init(shortRank5Tensor);
|
|
|
|
}
|
2019-02-13 12:14:01 +00:00
|
|
|
};
|
|
|
|
|
2019-02-18 21:40:53 +00:00
|
|
|
void EigenHdf5IOTest(void) {
|
2019-02-13 12:14:01 +00:00
|
|
|
SpinColourVector scv, scv2;
|
|
|
|
scv2 = scv;
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, SpinColourVector>("iotest_vector.h5", scv, "SpinColourVector");
|
|
|
|
SpinColourMatrix scm;
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, SpinColourMatrix>("iotest_matrix.h5", scm, "SpinColourMatrix");
|
2019-02-18 08:55:50 +00:00
|
|
|
|
|
|
|
constexpr TestScalar Inc{1,-1};
|
|
|
|
{
|
|
|
|
using TestTensorSingle = Eigen::TensorFixedSize<int, Eigen::Sizes<1>>;
|
|
|
|
TestTensorSingle ts;
|
|
|
|
ts(0) = 7; // lucky
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, TestTensorSingle>("iotest_single.h5", ts, "Tensor_single");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
using TestTensorSimple = Eigen::Tensor<iMatrix<TestScalar,1>, 6>;
|
|
|
|
TestTensorSimple ts(1,1,1,1,1,1);
|
|
|
|
ts(0,0,0,0,0,0) = Inc * 3.1415927;
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, TestTensorSimple>("iotest_simple.h5", ts, "Tensor_simple");
|
|
|
|
}
|
|
|
|
|
2019-02-13 21:48:35 +00:00
|
|
|
TestTensor t(6,3,2);
|
2019-02-13 12:14:01 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, TestTensor>("iotest_tensor.h5", t, "eigen_tensor_instance_name");
|
2019-02-18 17:12:27 +00:00
|
|
|
//dump_tensor(t, "t");
|
2019-02-13 21:48:35 +00:00
|
|
|
|
2019-02-13 12:14:01 +00:00
|
|
|
// Now serialise a fixed size tensor
|
|
|
|
using FixedTensor = Eigen::TensorFixedSize<TestScalar, Eigen::Sizes<8,4,3>>;
|
|
|
|
FixedTensor tf;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, FixedTensor>("iotest_tensor_fixed.h5", tf, "eigen_tensor_fixed_name");
|
2019-02-18 17:12:27 +00:00
|
|
|
//dump_tensor(tf, "tf");
|
|
|
|
|
|
|
|
PerambIOTestClass o;
|
2019-02-18 21:40:53 +00:00
|
|
|
//dump_tensor(o.Perambulator, "Perambulator" );
|
|
|
|
dump_tensor(o.shortRank5Tensor, "shortRank5Tensor");
|
2019-02-18 17:12:27 +00:00
|
|
|
/*for_all( o.FixedCritter, [&](TestScalar &c, float f, const std::array<size_t,TestTensorFixed::NumIndices> &Dims ){
|
|
|
|
c = TestScalar{f,-f};
|
|
|
|
//std::cout << " a(" << Dims[0] << "," << Dims[1] << "," << Dims[2] << ")=" << c;
|
|
|
|
} );
|
|
|
|
for( auto &z : o.aFixedCritter )
|
|
|
|
for_all( z, [&](TestScalar &c, float f, const std::array<size_t,TestTensorFixed::NumIndices> &Dims ){
|
|
|
|
c = TestScalar{f,-f};
|
|
|
|
//std::cout << " a(" << Dims[0] << "," << Dims[1] << "," << Dims[2] << ")=" << c;
|
|
|
|
} );*/
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, PerambIOTestClass>("iotest_object.h5", o, "PerambIOTestClass_object_instance_name");
|
|
|
|
//DumpMemoryOrder(o.Perambulator);
|
2019-02-14 19:05:35 +00:00
|
|
|
|
2019-02-13 12:14:01 +00:00
|
|
|
// Tensor of spin colour
|
|
|
|
LSCTensor l;
|
|
|
|
Val = 0;
|
|
|
|
for( int i = 0 ; i < l.dimension(0) ; i++)
|
|
|
|
for( int j = 0 ; j < l.dimension(1) ; j++)
|
|
|
|
for( int k = 0 ; k < l.dimension(2) ; k++)
|
|
|
|
for( int s = 0 ; s < Ns ; s++ )
|
|
|
|
for( int c = 0 ; c < Nc ; c++ )
|
|
|
|
{
|
|
|
|
l(i,j,k)()(s)(c) = Val;
|
|
|
|
Val += Inc;
|
|
|
|
}
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, LSCTensor>("iotest_LSCTensor.h5", l, "LSCTensor_object_instance_name");
|
2019-02-18 17:12:27 +00:00
|
|
|
//dump_tensor(l, "l");
|
2019-02-13 21:48:35 +00:00
|
|
|
|
2019-02-13 12:14:01 +00:00
|
|
|
// Tensor of spin colour
|
|
|
|
LCMTensor l2;
|
|
|
|
Val = 0;
|
|
|
|
for( int i = 0 ; i < l2.dimension(0) ; i++)
|
|
|
|
for( int j = 0 ; j < l2.dimension(1) ; j++)
|
|
|
|
for( int k = 0 ; k < l2.dimension(2) ; k++)
|
|
|
|
for( int l = 0 ; l < Ns ; l++ )
|
|
|
|
for( int c = 0 ; c < Nc ; c++ )
|
|
|
|
for( int c2 = 0 ; c2 < Nc ; c2++ )
|
|
|
|
{
|
|
|
|
l2(i,j,k)(l)()(c,c2) = Val;
|
|
|
|
Val += Inc;
|
|
|
|
}
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader, LCMTensor>("iotest_LCMTensor.h5", l2, "LCMTensor_object_instance_name");
|
2019-02-18 17:12:27 +00:00
|
|
|
//dump_tensor(l2, "l2");
|
2017-01-19 01:41:05 +00:00
|
|
|
}
|
2019-02-13 12:14:01 +00:00
|
|
|
#endif
|
2017-01-19 01:41:05 +00:00
|
|
|
|
2018-03-08 09:50:39 +00:00
|
|
|
template <typename T>
|
|
|
|
void tensorConvTestFn(GridSerialRNG &rng, const std::string label)
|
|
|
|
{
|
|
|
|
T t, ft;
|
|
|
|
Real n;
|
|
|
|
bool good;
|
|
|
|
|
|
|
|
random(rng, t);
|
|
|
|
auto tv = tensorToVec(t);
|
|
|
|
vecToTensor(ft, tv);
|
|
|
|
n = norm2(t - ft);
|
|
|
|
good = (n == 0);
|
|
|
|
std::cout << label << " norm 2 diff: " << n << " -- "
|
|
|
|
<< (good ? "success" : "failure") << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define tensorConvTest(rng, type) tensorConvTestFn<type>(rng, #type)
|
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
int main(int argc,char **argv)
|
|
|
|
{
|
2018-04-04 17:19:34 +01:00
|
|
|
Grid_init(&argc,&argv);
|
2019-02-13 12:14:01 +00:00
|
|
|
std::cout << std::boolalpha << "==== basic IO" << std::endl; // display true / false for boolean
|
|
|
|
|
2018-03-08 19:12:03 +00:00
|
|
|
GridSerialRNG rng;
|
|
|
|
|
|
|
|
rng.SeedFixedIntegers(std::vector<int>({42,10,81,9}));
|
2019-02-13 12:14:01 +00:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
XmlWriter WR("bother.xml");
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
// test basic type writing
|
|
|
|
std::cout << "-- basic writing to 'bother.xml'..." << std::endl;
|
|
|
|
push(WR,"BasicTypes");
|
|
|
|
write(WR,std::string("i16"),i16);
|
|
|
|
write(WR,"u16",u16);
|
|
|
|
write(WR,"i32",i32);
|
|
|
|
write(WR,"u32",u32);
|
|
|
|
write(WR,"i64",i64);
|
|
|
|
write(WR,"u64",u64);
|
|
|
|
write(WR,"f",f);
|
|
|
|
write(WR,"d",d);
|
|
|
|
write(WR,"b",b);
|
|
|
|
pop(WR);
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
// test serializable class writing
|
|
|
|
myclass obj(1234); // non-trivial constructor
|
|
|
|
std::vector<myclass> vec;
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
std::cout << "-- serialisable class writing to 'bother.xml'..." << std::endl;
|
|
|
|
write(WR,"obj",obj);
|
|
|
|
WR.write("obj2", obj);
|
2018-03-08 19:12:03 +00:00
|
|
|
vec.push_back(obj);
|
2017-01-19 01:41:05 +00:00
|
|
|
vec.push_back(myclass(5678));
|
|
|
|
vec.push_back(myclass(3838));
|
2017-02-06 14:08:59 +00:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
write(WR, "objvec", vec);
|
|
|
|
std::cout << "-- serialisable class writing to std::cout:" << std::endl;
|
|
|
|
std::cout << obj << std::endl;
|
|
|
|
std::cout << "-- serialisable class comparison:" << std::endl;
|
2019-02-13 12:14:01 +00:00
|
|
|
std::cout << "vec[0] == obj: " << (vec[0] == obj) << std::endl;
|
|
|
|
std::cout << "vec[1] == obj: " << (vec[1] == obj) << std::endl;
|
2017-02-06 14:08:59 +00:00
|
|
|
std::cout << "-- pair writing to std::cout:" << std::endl;
|
2019-02-18 21:40:53 +00:00
|
|
|
std::pair<myenum, myenum> pair = std::make_pair(myenum::red, myenum::blue);
|
2017-02-06 14:08:59 +00:00
|
|
|
std::cout << pair << std::endl;
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2015-11-16 18:14:37 +00:00
|
|
|
// read tests
|
2017-01-19 01:41:05 +00:00
|
|
|
std::cout << "\n==== IO self-consistency tests" << std::endl;
|
2015-11-16 18:14:37 +00:00
|
|
|
//// XML
|
2017-01-19 01:41:05 +00:00
|
|
|
ioTest<XmlWriter, XmlReader>("iotest.xml", obj, "XML (object) ");
|
|
|
|
ioTest<XmlWriter, XmlReader>("iotest.xml", vec, "XML (vector of objects)");
|
2015-11-16 18:14:37 +00:00
|
|
|
//// binary
|
2017-01-19 01:41:05 +00:00
|
|
|
ioTest<BinaryWriter, BinaryReader>("iotest.bin", obj, "binary (object) ");
|
|
|
|
ioTest<BinaryWriter, BinaryReader>("iotest.bin", vec, "binary (vector of objects)");
|
2015-11-16 18:14:37 +00:00
|
|
|
//// text
|
2017-01-19 01:41:05 +00:00
|
|
|
ioTest<TextWriter, TextReader>("iotest.dat", obj, "text (object) ");
|
|
|
|
ioTest<TextWriter, TextReader>("iotest.dat", vec, "text (vector of objects)");
|
2017-06-19 14:38:39 +01:00
|
|
|
//// text
|
2017-07-12 14:44:53 +01:00
|
|
|
ioTest<JSONWriter, JSONReader>("iotest.json", obj, "JSON (object) ");
|
|
|
|
ioTest<JSONWriter, JSONReader>("iotest.json", vec, "JSON (vector of objects)");
|
2017-06-19 14:38:39 +01:00
|
|
|
|
2017-01-18 00:21:18 +00:00
|
|
|
//// HDF5
|
2017-01-19 01:41:05 +00:00
|
|
|
#ifdef HAVE_HDF5
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader>("iotest.h5", obj, "HDF5 (object) ");
|
|
|
|
ioTest<Hdf5Writer, Hdf5Reader>("iotest.h5", vec, "HDF5 (vector of objects)");
|
2019-02-18 21:40:53 +00:00
|
|
|
std::cout << "\n==== detailed Hdf5 tensor tests (Grid::EigenIO)" << std::endl;
|
|
|
|
EigenHdf5IOTest();
|
2017-01-18 00:21:18 +00:00
|
|
|
#endif
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
std::cout << "\n==== vector flattening/reconstruction" << std::endl;
|
2017-01-19 00:50:21 +00:00
|
|
|
typedef std::vector<std::vector<std::vector<double>>> vec3d;
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 00:50:21 +00:00
|
|
|
vec3d dv, buf;
|
|
|
|
double d = 0.;
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 00:50:21 +00:00
|
|
|
dv.resize(4);
|
|
|
|
for (auto &v1: dv)
|
2016-04-30 08:15:24 +01:00
|
|
|
{
|
2017-01-19 00:50:21 +00:00
|
|
|
v1.resize(3);
|
|
|
|
for (auto &v2: v1)
|
|
|
|
{
|
|
|
|
v2.resize(5);
|
|
|
|
for (auto &x: v2)
|
|
|
|
{
|
|
|
|
x = d++;
|
|
|
|
}
|
|
|
|
}
|
2016-04-30 08:15:24 +01:00
|
|
|
}
|
2017-01-19 01:41:05 +00:00
|
|
|
std::cout << "original 3D vector:" << std::endl;
|
2017-01-19 00:50:21 +00:00
|
|
|
std::cout << dv << std::endl;
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 00:50:21 +00:00
|
|
|
Flatten<vec3d> flatdv(dv);
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 01:41:05 +00:00
|
|
|
std::cout << "\ndimensions:" << std::endl;
|
2017-01-19 00:50:21 +00:00
|
|
|
std::cout << flatdv.getDim() << std::endl;
|
2017-01-19 01:41:05 +00:00
|
|
|
std::cout << "\nflattened vector:" << std::endl;
|
2017-01-19 00:50:21 +00:00
|
|
|
std::cout << flatdv.getFlatVector() << std::endl;
|
2017-07-11 14:31:57 +01:00
|
|
|
|
2017-01-19 00:50:21 +00:00
|
|
|
Reconstruct<vec3d> rec(flatdv.getFlatVector(), flatdv.getDim());
|
2017-01-19 01:41:05 +00:00
|
|
|
std::cout << "\nreconstructed vector:" << std::endl;
|
2017-01-19 00:50:21 +00:00
|
|
|
std::cout << flatdv.getVector() << std::endl;
|
2016-04-30 08:15:24 +01:00
|
|
|
std::cout << std::endl;
|
2017-01-23 14:57:38 +00:00
|
|
|
|
2018-03-06 19:22:03 +00:00
|
|
|
std::cout << "==== Grid tensor to vector test" << std::endl;
|
2018-03-08 09:50:39 +00:00
|
|
|
tensorConvTest(rng, SpinColourMatrix);
|
|
|
|
tensorConvTest(rng, SpinColourVector);
|
|
|
|
tensorConvTest(rng, ColourMatrix);
|
|
|
|
tensorConvTest(rng, ColourVector);
|
|
|
|
tensorConvTest(rng, SpinMatrix);
|
|
|
|
tensorConvTest(rng, SpinVector);
|
2019-02-18 21:40:53 +00:00
|
|
|
|
2019-02-13 12:14:01 +00:00
|
|
|
Grid_finalize();
|
2015-08-20 16:21:26 +01:00
|
|
|
}
|