mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-25 13:15:55 +01:00
Started read routines. Introduced readMultiDim and tested I didnt break anything
This commit is contained in:
parent
74a3a5b825
commit
9815ddb853
@ -215,6 +215,7 @@ namespace Grid {
|
|||||||
|
|
||||||
// Helper to dump a tensor
|
// Helper to dump a tensor
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
#define dump_tensor(args...) dump_tensor_func(args)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename std::enable_if<EigenIO::is_tensor<T>::value, void>::type
|
typename std::enable_if<EigenIO::is_tensor<T>::value, void>::type
|
||||||
dump_tensor_func(T &t, const char * pName = nullptr)
|
dump_tensor_func(T &t, const char * pName = nullptr)
|
||||||
@ -235,17 +236,13 @@ namespace Grid {
|
|||||||
} );
|
} );
|
||||||
std::cout << "========================================" << std::endl;
|
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
|
// Helper to dump a tensor in memory order
|
||||||
// Kind of superfluous given the above
|
// Kind of superfluous given the above
|
||||||
#ifdef DEBUG
|
#define DumpMemoryOrder(args...) DumpMemoryOrder_func(args)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename std::enable_if<EigenIO::is_tensor_of_scalar<T>::value, void>::type
|
typename std::enable_if<EigenIO::is_tensor_of_scalar<T>::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 rank = t.rank();
|
||||||
const auto &dims = t.dimensions();
|
const auto &dims = t.dimensions();
|
||||||
@ -287,6 +284,9 @@ namespace Grid {
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define dump_tensor(args...)
|
||||||
|
#define DumpMemoryOrder(args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Abstract writer/reader classes ////////////////////////////////////////////
|
// Abstract writer/reader classes ////////////////////////////////////////////
|
||||||
@ -345,7 +345,8 @@ namespace Grid {
|
|||||||
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
|
||||||
read(const std::string& s, U &output);
|
read(const std::string& s, U &output);
|
||||||
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
|
||||||
|
&& !std::is_base_of<Eigen::TensorBase<U, Eigen::ReadOnlyAccessors>, U>::value, void>::type
|
||||||
read(const std::string& s, U &output);
|
read(const std::string& s, U &output);
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void read(const std::string &s, iScalar<U> &output);
|
void read(const std::string &s, iScalar<U> &output);
|
||||||
@ -353,6 +354,12 @@ namespace Grid {
|
|||||||
void read(const std::string &s, iVector<U, N> &output);
|
void read(const std::string &s, iVector<U, N> &output);
|
||||||
template <typename U, int N>
|
template <typename U, int N>
|
||||||
void read(const std::string &s, iMatrix<U, N> &output);
|
void read(const std::string &s, iMatrix<U, N> &output);
|
||||||
|
template <typename ETensor>
|
||||||
|
typename std::enable_if<std::is_base_of<Eigen::TensorBase<ETensor, Eigen::ReadOnlyAccessors>, ETensor>::value && EigenIO::is_scalar<typename ETensor::Scalar>::value, void>::type
|
||||||
|
read(const std::string &s, ETensor &output);
|
||||||
|
template <typename ETensor>
|
||||||
|
typename std::enable_if<std::is_base_of<Eigen::TensorBase<ETensor, Eigen::ReadOnlyAccessors>, ETensor>::value && EigenIO::is_container<typename ETensor::Scalar>::value, void>::type
|
||||||
|
read(const std::string &s, ETensor &output);
|
||||||
protected:
|
protected:
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void fromString(U &output, const std::string &s);
|
void fromString(U &output, const std::string &s);
|
||||||
@ -602,7 +609,8 @@ namespace Grid {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
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
|
||||||
|
&& !std::is_base_of<Eigen::TensorBase<U, Eigen::ReadOnlyAccessors>, U>::value, void>::type
|
||||||
Reader<T>::read(const std::string &s, U &output)
|
Reader<T>::read(const std::string &s, U &output)
|
||||||
{
|
{
|
||||||
upcast->readDefault(s, output);
|
upcast->readDefault(s, output);
|
||||||
@ -638,6 +646,20 @@ namespace Grid {
|
|||||||
vecToTensor(output, v);
|
vecToTensor(output, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
template <typename ETensor>
|
||||||
|
typename std::enable_if<std::is_base_of<Eigen::TensorBase<ETensor, Eigen::ReadOnlyAccessors>, ETensor>::value && EigenIO::is_scalar<typename ETensor::Scalar>::value, void>::type
|
||||||
|
Reader<T>::read(const std::string &s, ETensor &output)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
template <typename ETensor>
|
||||||
|
typename std::enable_if<std::is_base_of<Eigen::TensorBase<ETensor, Eigen::ReadOnlyAccessors>, ETensor>::value && EigenIO::is_container<typename ETensor::Scalar>::value, void>::type
|
||||||
|
Reader<T>::read(const std::string &s, ETensor &output)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void Reader<T>::fromString(U &output, const std::string &s)
|
void Reader<T>::fromString(U &output, const std::string &s)
|
||||||
|
@ -68,6 +68,8 @@ namespace Grid
|
|||||||
template <typename U>
|
template <typename U>
|
||||||
typename std::enable_if<!element<std::vector<U>>::is_number, void>::type
|
typename std::enable_if<!element<std::vector<U>>::is_number, void>::type
|
||||||
readDefault(const std::string &s, std::vector<U> &x);
|
readDefault(const std::string &s, std::vector<U> &x);
|
||||||
|
template <typename U>
|
||||||
|
void readMultiDim(const std::string &s, std::vector<U> &buf, std::vector<size_t> &dim);
|
||||||
H5NS::Group & getGroup(void);
|
H5NS::Group & getGroup(void);
|
||||||
private:
|
private:
|
||||||
template <typename U>
|
template <typename U>
|
||||||
@ -184,8 +186,7 @@ namespace Grid
|
|||||||
void Hdf5Reader::readDefault(const std::string &s, std::string &x);
|
void Hdf5Reader::readDefault(const std::string &s, std::string &x);
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
typename std::enable_if<element<std::vector<U>>::is_number, void>::type
|
void Hdf5Reader::readMultiDim(const std::string &s, std::vector<U> &buf, std::vector<size_t> &dim)
|
||||||
Hdf5Reader::readDefault(const std::string &s, std::vector<U> &x)
|
|
||||||
{
|
{
|
||||||
// alias to element type
|
// alias to element type
|
||||||
typedef typename element<std::vector<U>>::type Element;
|
typedef typename element<std::vector<U>>::type Element;
|
||||||
@ -193,7 +194,6 @@ namespace Grid
|
|||||||
// read the dimensions
|
// read the dimensions
|
||||||
H5NS::DataSpace dataSpace;
|
H5NS::DataSpace dataSpace;
|
||||||
std::vector<hsize_t> hdim;
|
std::vector<hsize_t> hdim;
|
||||||
std::vector<size_t> dim;
|
|
||||||
hsize_t size = 1;
|
hsize_t size = 1;
|
||||||
|
|
||||||
if (group_.attrExists(s))
|
if (group_.attrExists(s))
|
||||||
@ -213,7 +213,7 @@ namespace Grid
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read the flat vector
|
// read the flat vector
|
||||||
std::vector<Element> buf(size);
|
buf.resize(size);
|
||||||
|
|
||||||
if (size * sizeof(Element) > dataSetThres_)
|
if (size * sizeof(Element) > dataSetThres_)
|
||||||
{
|
{
|
||||||
@ -229,6 +229,18 @@ namespace Grid
|
|||||||
attribute = group_.openAttribute(s);
|
attribute = group_.openAttribute(s);
|
||||||
attribute.read(Hdf5Type<Element>::type(), buf.data());
|
attribute.read(Hdf5Type<Element>::type(), buf.data());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U>
|
||||||
|
typename std::enable_if<element<std::vector<U>>::is_number, void>::type
|
||||||
|
Hdf5Reader::readDefault(const std::string &s, std::vector<U> &x)
|
||||||
|
{
|
||||||
|
// alias to element type
|
||||||
|
typedef typename element<std::vector<U>>::type Element;
|
||||||
|
|
||||||
|
std::vector<size_t> dim;
|
||||||
|
std::vector<Element> buf;
|
||||||
|
readMultiDim( s, buf, dim );
|
||||||
|
|
||||||
// reconstruct the multidimensional vector
|
// reconstruct the multidimensional vector
|
||||||
Reconstruct<std::vector<U>> r(buf, dim);
|
Reconstruct<std::vector<U>> r(buf, dim);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user