1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-09 21:50:45 +01:00

Merge branch 'develop' into feature/hadrons

# Conflicts:
#	lib/serialisation/BaseIO.h
This commit is contained in:
Antonin Portelli 2018-03-07 15:22:16 +00:00
commit 9942723189
2 changed files with 56 additions and 23 deletions

View File

@ -35,37 +35,72 @@ Author: Guido Cossu <guido.cossu@ed.ac.uk>
namespace Grid { namespace Grid {
// Grid scalar tensors to nested std::vectors ////////////////////////////////// // Grid scalar tensors to nested std::vectors //////////////////////////////////
template <typename T, typename V> template <typename T>
void tensorToVec(V &v, const T& t) struct TensorToVec
{ {
v = t; typedef T type;
};
template <typename T>
struct TensorToVec<iScalar<T>>
{
typedef typename TensorToVec<T>::type type;
};
template <typename T, int N>
struct TensorToVec<iVector<T, N>>
{
typedef typename std::vector<typename TensorToVec<T>::type> type;
};
template <typename T, int N>
struct TensorToVec<iMatrix<T, N>>
{
typedef typename std::vector<std::vector<typename TensorToVec<T>::type>> type;
};
template <typename T>
typename TensorToVec<T>::type tensorToVec(const T &t)
{
return t;
} }
template <typename T, typename V> template <typename T>
void tensorToVec(V &v, const iScalar<T>& t) typename TensorToVec<iScalar<T>>::type tensorToVec(const iScalar<T>& t)
{ {
tensorToVec(v, t._internal); return tensorToVec(t._internal);
} }
template <typename T, typename V, int N> template <typename T, int N>
void tensorToVec(std::vector<V> &v, const iVector<T, N>& t) typename TensorToVec<iVector<T, N>>::type tensorToVec(const iVector<T, N>& t)
{ {
typename TensorToVec<iVector<T, N>>::type v;
v.resize(N); v.resize(N);
for (unsigned int i = 0; i < N; i++) for (unsigned int i = 0; i < N; i++)
{ {
tensorToVec(v[i], t._internal[i]); v[i] = tensorToVec(t._internal[i]);
} }
return v;
} }
template <typename T, typename V, int N> template <typename T, int N>
void tensorToVec(std::vector<std::vector<V>> &v, const iMatrix<T, N>& t) typename TensorToVec<iMatrix<T, N>>::type tensorToVec(const iMatrix<T, N>& t)
{ {
v.resize(N, std::vector<V>(N)); typename TensorToVec<iMatrix<T, N>>::type v;
v.resize(N);
for (unsigned int i = 0; i < N; i++) for (unsigned int i = 0; i < N; i++)
for (unsigned int j = 0; j < N; j++)
{ {
tensorToVec(v[i][j], t._internal[i][j]); v[i].resize(N);
for (unsigned int j = 0; j < N; j++)
{
v[i][j] = tensorToVec(t._internal[i][j]);
}
} }
return v;
} }
// Vector element trait ////////////////////////////////////////////////////// // Vector element trait //////////////////////////////////////////////////////
@ -150,15 +185,15 @@ namespace Grid {
do do
{ {
is.get(c); is.get(c);
} while (c != '{' && !is.eof()); } while (c != '(' && !is.eof());
if (c == '{') if (c == '(')
{ {
int start = is.tellg(); int start = is.tellg();
do do
{ {
is.get(c); is.get(c);
} while (c != '}' && !is.eof()); } while (c != ')' && !is.eof());
if (c == '}') if (c == ')')
{ {
int end = is.tellg(); int end = is.tellg();
int psize = end - start - 1; int psize = end - start - 1;
@ -181,7 +216,7 @@ namespace Grid {
template <class T1, class T2> template <class T1, class T2>
inline std::ostream & operator<<(std::ostream &os, const std::pair<T1, T2> &p) inline std::ostream & operator<<(std::ostream &os, const std::pair<T1, T2> &p)
{ {
os << "{" << p.first << " " << p.second << "}"; os << "(" << p.first << " " << p.second << ")";
return os; return os;
} }

View File

@ -202,8 +202,6 @@ int main(int argc,char **argv)
GridSerialRNG rng; GridSerialRNG rng;
SpinColourMatrix scm; SpinColourMatrix scm;
SpinColourVector scv; 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})); rng.SeedFixedIntegers(std::vector<int>({42,10,81,9}));
random(rng, scm); random(rng, scm);
@ -211,8 +209,8 @@ int main(int argc,char **argv)
std::cout << "Test spin-color matrix: " << scm << std::endl; std::cout << "Test spin-color matrix: " << scm << std::endl;
std::cout << "Test spin-color vector: " << scv << std::endl; std::cout << "Test spin-color vector: " << scv << std::endl;
std::cout << "Converting to std::vector" << std::endl; std::cout << "Converting to std::vector" << std::endl;
tensorToVec(scmv, scm); auto scmv = tensorToVec(scm);
tensorToVec(scvv, scv); auto scvv = tensorToVec(scv);
std::cout << "Spin-color matrix: " << scmv << std::endl; std::cout << "Spin-color matrix: " << scmv << std::endl;
std::cout << "Spin-color vector: " << scvv << std::endl; std::cout << "Spin-color vector: " << scvv << std::endl;
} }