diff --git a/Grid/serialisation/BaseIO.h b/Grid/serialisation/BaseIO.h index bf4eb42a..96bb3bb7 100644 --- a/Grid/serialisation/BaseIO.h +++ b/Grid/serialisation/BaseIO.h @@ -215,6 +215,7 @@ namespace Grid { // Helper to dump a tensor #ifdef DEBUG +#define dump_tensor(args...) dump_tensor_func(args) template typename std::enable_if::value, void>::type dump_tensor_func(T &t, const char * pName = nullptr) @@ -235,17 +236,13 @@ namespace Grid { } ); std::cout << "========================================" << std::endl; } -#define dump_tensor(args...) dump_tensor_func(args) -#else -#define dump_tensor(args...) -#endif // Helper to dump a tensor in memory order // Kind of superfluous given the above -#ifdef DEBUG +#define DumpMemoryOrder(args...) DumpMemoryOrder_func(args) template typename std::enable_if::value, void>::type - DumpMemoryOrder(T &t, const char * pName = nullptr) + DumpMemoryOrder_func(T &t, const char * pName = nullptr) { const auto rank = t.rank(); const auto &dims = t.dimensions(); @@ -287,6 +284,9 @@ namespace Grid { std::cout << std::endl; } } +#else +#define dump_tensor(args...) +#define DumpMemoryOrder(args...) #endif // Abstract writer/reader classes //////////////////////////////////////////// @@ -345,7 +345,8 @@ namespace Grid { typename std::enable_if::value, void>::type read(const std::string& s, U &output); template - typename std::enable_if::value, void>::type + typename std::enable_if::value + && !std::is_base_of, U>::value, void>::type read(const std::string& s, U &output); template void read(const std::string &s, iScalar &output); @@ -353,6 +354,12 @@ namespace Grid { void read(const std::string &s, iVector &output); template void read(const std::string &s, iMatrix &output); + template + typename std::enable_if, ETensor>::value && EigenIO::is_scalar::value, void>::type + read(const std::string &s, ETensor &output); + template + typename std::enable_if, ETensor>::value && EigenIO::is_container::value, void>::type + read(const std::string &s, ETensor &output); protected: template void fromString(U &output, const std::string &s); @@ -398,7 +405,7 @@ namespace Grid { template template typename std::enable_if::value - && !std::is_base_of, U>::value, void>::type + && !std::is_base_of, U>::value, void>::type Writer::write(const std::string &s, const U &output) { upcast->writeDefault(s, output); @@ -602,7 +609,8 @@ namespace Grid { template template - typename std::enable_if::value, void>::type + typename std::enable_if::value + && !std::is_base_of, U>::value, void>::type Reader::read(const std::string &s, U &output) { upcast->readDefault(s, output); @@ -638,6 +646,20 @@ namespace Grid { vecToTensor(output, v); } + template + template + typename std::enable_if, ETensor>::value && EigenIO::is_scalar::value, void>::type + Reader::read(const std::string &s, ETensor &output) + { + } + + template + template + typename std::enable_if, ETensor>::value && EigenIO::is_container::value, void>::type + Reader::read(const std::string &s, ETensor &output) + { + } + template template void Reader::fromString(U &output, const std::string &s) diff --git a/Grid/serialisation/Hdf5IO.h b/Grid/serialisation/Hdf5IO.h index 7de6dc88..c1bb891c 100644 --- a/Grid/serialisation/Hdf5IO.h +++ b/Grid/serialisation/Hdf5IO.h @@ -68,6 +68,8 @@ namespace Grid template typename std::enable_if>::is_number, void>::type readDefault(const std::string &s, std::vector &x); + template + void readMultiDim(const std::string &s, std::vector &buf, std::vector &dim); H5NS::Group & getGroup(void); private: template @@ -182,10 +184,9 @@ namespace Grid template <> void Hdf5Reader::readDefault(const std::string &s, std::string &x); - + template - typename std::enable_if>::is_number, void>::type - Hdf5Reader::readDefault(const std::string &s, std::vector &x) + void Hdf5Reader::readMultiDim(const std::string &s, std::vector &buf, std::vector &dim) { // alias to element type typedef typename element>::type Element; @@ -193,7 +194,6 @@ namespace Grid // read the dimensions H5NS::DataSpace dataSpace; std::vector hdim; - std::vector dim; hsize_t size = 1; if (group_.attrExists(s)) @@ -213,8 +213,8 @@ namespace Grid } // read the flat vector - std::vector buf(size); - + buf.resize(size); + if (size * sizeof(Element) > dataSetThres_) { H5NS::DataSet dataSet; @@ -229,7 +229,19 @@ namespace Grid attribute = group_.openAttribute(s); attribute.read(Hdf5Type::type(), buf.data()); } - + } + + template + typename std::enable_if>::is_number, void>::type + Hdf5Reader::readDefault(const std::string &s, std::vector &x) + { + // alias to element type + typedef typename element>::type Element; + + std::vector dim; + std::vector buf; + readMultiDim( s, buf, dim ); + // reconstruct the multidimensional vector Reconstruct> r(buf, dim);