1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00: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>
typename std::enable_if<!std::is_base_of<Serializable, U>::value, void>::type
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>
void write(const std::string &s, const iScalar<U> &output);
template <typename U, int N>
void write(const std::string &s, const iVector<U, N> &output);
template <typename U, int N>
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);
bool isScientific(void);
@ -145,6 +152,44 @@ namespace Grid {
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 U>
void Writer<T>::write(const std::string &s, const iScalar<U> &output)
@ -166,14 +211,6 @@ namespace Grid {
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>
void Writer<T>::scientificFormat(const bool set)
{

View File

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

View File

@ -424,12 +424,15 @@ bool DebugEigenTest()
}
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
class myclass: Serializable {
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(myclass
, OddBall, critter
//, OddBall, critter
, SpinColourVector, scv
, SpinColourMatrix, scm
);
@ -465,6 +468,9 @@ bool DebugIOTest(void) {
ioTest<Hdf5Writer, Hdf5Reader, SpinColourVector>("iotest_vector.h5", scv, "SpinColourVector");
myclass o;
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;
}
#endif