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

Merge branch 'develop' into feature/hadrons

# Conflicts:
#	lib/serialisation/BaseIO.h
This commit is contained in:
Antonin Portelli 2018-03-06 19:25:51 +00:00
commit e79ef469ac
2 changed files with 51 additions and 62 deletions

View File

@ -31,8 +31,43 @@ Author: Guido Cossu <guido.cossu@ed.ac.uk>
#define GRID_SERIALISATION_ABSTRACT_READER_H
#include <type_traits>
#include <Grid/tensors/Tensors.h>
namespace Grid {
// Grid scalar tensors to nested std::vectors //////////////////////////////////
template <typename T, typename V>
void tensorToVec(V &v, const T& t)
{
v = t;
}
template <typename T, typename V>
void tensorToVec(V &v, const iScalar<T>& t)
{
tensorToVec(v, t._internal);
}
template <typename T, typename V, int N>
void tensorToVec(std::vector<V> &v, const iVector<T, N>& t)
{
v.resize(N);
for (unsigned int i = 0; i < N; i++)
{
tensorToVec(v[i], t._internal[i]);
}
}
template <typename T, typename V, int N>
void tensorToVec(std::vector<std::vector<V>> &v, const iMatrix<T, N>& t)
{
v.resize(N, std::vector<V>(N));
for (unsigned int i = 0; i < N; i++)
for (unsigned int j = 0; j < N; j++)
{
tensorToVec(v[i][j], t._internal[i][j]);
}
}
// Vector element trait //////////////////////////////////////////////////////
template <typename T>
struct element

View File

@ -197,68 +197,22 @@ int main(int argc,char **argv)
std::cout << flatdv.getVector() << std::endl;
std::cout << std::endl;
std::cout << "==== Grid tensor to vector test" << std::endl;
std::cout << ".:::::: Testing JSON classes "<< std::endl;
{
JSONWriter JW("bother.json");
// test basic type writing
myenum a = myenum::red;
push(JW,"BasicTypes");
write(JW,std::string("i16"),i16);
write(JW,"myenum",a);
write(JW,"u16",u16);
write(JW,"i32",i32);
write(JW,"u32",u32);
write(JW,"i64",i64);
write(JW,"u64",u64);
write(JW,"f",f);
write(JW,"d",d);
write(JW,"b",b);
pop(JW);
// test serializable class writing
myclass obj(1234); // non-trivial constructor
std::cout << obj << std::endl;
std::cout << "-- serialisable class writing to 'bother.json'..." << std::endl;
write(JW,"obj",obj);
JW.write("obj2", obj);
std::vector<myclass> vec;
vec.push_back(myclass(1234));
vec.push_back(myclass(5678));
vec.push_back(myclass(3838));
write(JW, "objvec", vec);
}
{
JSONReader RD("bother.json");
myclass jcopy1;
std::vector<myclass> jveccopy1;
read(RD,"obj",jcopy1);
read(RD,"objvec", jveccopy1);
std::cout << "Loaded (JSON) -----------------" << std::endl;
std::cout << jcopy1 << std::endl << jveccopy1 << std::endl;
}
/*
// This is still work in progress
{
// Testing the next element function
JSONReader RD("test.json");
RD.push("grid");
RD.push("Observable");
std::string name;
read(RD,"name", name);
}
*/
GridSerialRNG rng;
SpinColourMatrix scm;
SpinColourVector scv;
std::vector<std::vector<std::vector<std::vector<ComplexD>>>> scmv;
std::vector<std::vector<ComplexD>> scvv;
rng.SeedFixedIntegers(std::vector<int>({42,10,81,9}));
random(rng, scm);
random(rng, scv);
std::cout << "Test spin-color matrix: " << scm << std::endl;
std::cout << "Test spin-color vector: " << scv << std::endl;
std::cout << "Converting to std::vector" << std::endl;
tensorToVec(scmv, scm);
tensorToVec(scvv, scv);
std::cout << "Spin-color matrix: " << scmv << std::endl;
std::cout << "Spin-color vector: " << scvv << std::endl;
}