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

Adding Eigen::Tensor still WIP

This commit is contained in:
Michael Marshall 2019-02-09 17:12:36 +00:00
parent 6a4515d0cd
commit 3720103f41
3 changed files with 55 additions and 12 deletions

View File

@ -55,14 +55,21 @@ namespace Grid {
template <typename U> template <typename U>
typename std::enable_if<!std::is_base_of<Serializable, U>::value, void>::type typename std::enable_if<!std::is_base_of<Serializable, U>::value, void>::type
write(const std::string& s, const U &output); write(const std::string& s, const U &output);
template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
typename std::enable_if<std::is_arithmetic<Scalar_>::value || Grid::is_complex<Scalar_>::value, void>::type
write(const std::string &s, const Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType_> &output);
template<typename U, int NumIndices_, int Options_, typename IndexType_>
void write(const std::string &s, const Eigen::Tensor<iScalar<U>, NumIndices_, Options_, IndexType_> &output);
template<typename U, int N, int NumIndices_, int Options_, typename IndexType_>
void write(const std::string &s, const Eigen::Tensor<iVector<U, N>, NumIndices_, Options_, IndexType_> &output);
template<typename U, int N, int NumIndices_, int Options_, typename IndexType_>
void write(const std::string &s, const Eigen::Tensor<iMatrix<U, N>, NumIndices_, Options_, IndexType_> &output);
template <typename U> template <typename U>
void write(const std::string &s, const iScalar<U> &output); void write(const std::string &s, const iScalar<U> &output);
template <typename U, int N> template <typename U, int N>
void write(const std::string &s, const iVector<U, N> &output); void write(const std::string &s, const iVector<U, N> &output);
template <typename U, int N> template <typename U, int N>
void write(const std::string &s, const iMatrix<U, N> &output); void write(const std::string &s, const iMatrix<U, N> &output);
template <typename Scalar_, int NumIndices_>
void write(const std::string &s, const Eigen::Tensor<Scalar_, NumIndices_, Eigen::RowMajor> &output);
void scientificFormat(const bool set); void scientificFormat(const bool set);
bool isScientific(void); bool isScientific(void);
@ -145,6 +152,44 @@ namespace Grid {
upcast->writeDefault(s, output); upcast->writeDefault(s, output);
} }
// Eigen::Tensors of arithmetic/complex base type
template <typename T>
template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
typename std::enable_if<std::is_arithmetic<Scalar_>::value || Grid::is_complex<Scalar_>::value, void>::type
Writer<T>::write(const std::string &s, const Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType_> &output)
{
//upcast->writeDefault(s, tensorToVec(output));
std::cout << "I really should add code to write Eigen::Tensor (arithmetic/complex) ..." << std::endl;
}
// Eigen::Tensors of iScalar<U>
template <typename T>
template<typename U, int NumIndices_, int Options_, typename IndexType_>
void Writer<T>::write(const std::string &s, const Eigen::Tensor<iScalar<U>, NumIndices_, Options_, IndexType_> &output)
{
//upcast->writeDefault(s, tensorToVec(output));
std::cout << "I really should add code to write Eigen::Tensor (iScalar) ..." << std::endl;
}
// Eigen::Tensors of iVector<U, N>
template <typename T>
template<typename U, int N, int NumIndices_, int Options_, typename IndexType_>
void Writer<T>::write(const std::string &s, const Eigen::Tensor<iVector<U, N>, NumIndices_, Options_, IndexType_> &output)
{
//upcast->writeDefault(s, tensorToVec(output));
std::cout << "I really should add code to write Eigen::Tensor (iVector) ..." << std::endl;
}
// Eigen::Tensors of iMatrix<U, N>
template <typename T>
template<typename U, int N, int NumIndices_, int Options_, typename IndexType_>
void Writer<T>::write(const std::string &s, const Eigen::Tensor<iMatrix<U, N>, NumIndices_, Options_, IndexType_> &output)
{
//upcast->writeDefault(s, tensorToVec(output));
std::cout << "I really should add code to write Eigen::Tensor (iMatrix) ..." << std::endl;
}
template <typename T> template <typename T>
template <typename U> template <typename U>
void Writer<T>::write(const std::string &s, const iScalar<U> &output) void Writer<T>::write(const std::string &s, const iScalar<U> &output)
@ -166,14 +211,6 @@ namespace Grid {
upcast->writeDefault(s, tensorToVec(output)); upcast->writeDefault(s, tensorToVec(output));
} }
template <typename T>
template <typename Scalar_, int NumIndices_>
void Writer<T>::write(const std::string &s, const Eigen::Tensor<Scalar_, NumIndices_, Eigen::RowMajor> &output)
{
//upcast->writeDefault(s, tensorToVec(output));
std::cout << "I really should add code to write Eigen::Tensor ..." << std::endl;
}
template <typename T> template <typename T>
void Writer<T>::scientificFormat(const bool set) void Writer<T>::scientificFormat(const bool set)
{ {

View File

@ -436,4 +436,4 @@ std::string vecToStr(const std::vector<T> &v)
return sstr.str(); return sstr.str();
} }
#endif #endif

View File

@ -424,12 +424,15 @@ bool DebugEigenTest()
} }
typedef iMatrix<Complex,7> OddBall; typedef iMatrix<Complex,7> OddBall;
typedef Eigen::Tensor<int, 3, Eigen::RowMajor> TensorInt;
typedef Eigen::Tensor<std::complex<double>, 3, Eigen::RowMajor> TensorComplex;
typedef Eigen::Tensor<OddBall, 3, Eigen::RowMajor> TensorOddBall;
// From Test_serialisation.cc // From Test_serialisation.cc
class myclass: Serializable { class myclass: Serializable {
public: public:
GRID_SERIALIZABLE_CLASS_MEMBERS(myclass GRID_SERIALIZABLE_CLASS_MEMBERS(myclass
, OddBall, critter //, OddBall, critter
, SpinColourVector, scv , SpinColourVector, scv
, SpinColourMatrix, scm , SpinColourMatrix, scm
); );
@ -465,6 +468,9 @@ bool DebugIOTest(void) {
ioTest<Hdf5Writer, Hdf5Reader, SpinColourVector>("iotest_vector.h5", scv, "SpinColourVector"); ioTest<Hdf5Writer, Hdf5Reader, SpinColourVector>("iotest_vector.h5", scv, "SpinColourVector");
myclass o; myclass o;
ioTest<Hdf5Writer, Hdf5Reader, myclass>("iotest_object.h5", o, "myclass_object_instance_name"); ioTest<Hdf5Writer, Hdf5Reader, myclass>("iotest_object.h5", o, "myclass_object_instance_name");
TensorInt t(3,6,2);
ioTest<Hdf5Writer, Hdf5Reader, TensorInt>("iotest_tensor.h5", t, "eigen_tensor_instance_name");
return true; return true;
} }
#endif #endif