mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-13 01:05:36 +00:00
Added text read/write
This commit is contained in:
parent
ec45b16840
commit
7c7ffa3b10
@ -51,6 +51,8 @@ namespace Grid
|
|||||||
void writeDefault(const std::string &s, const U &x);
|
void writeDefault(const std::string &s, const U &x);
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void writeDefault(const std::string &s, const std::vector<U> &x);
|
void writeDefault(const std::string &s, const std::vector<U> &x);
|
||||||
|
template <typename U>
|
||||||
|
void writeMultiDim(const std::string &s, const std::vector<size_t> & Dimensions, const U * pDataRowMajor, size_t NumElements);
|
||||||
private:
|
private:
|
||||||
void indent(void);
|
void indent(void);
|
||||||
private:
|
private:
|
||||||
@ -69,6 +71,8 @@ namespace Grid
|
|||||||
void readDefault(const std::string &s, U &output);
|
void readDefault(const std::string &s, U &output);
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void readDefault(const std::string &s, std::vector<U> &output);
|
void readDefault(const std::string &s, std::vector<U> &output);
|
||||||
|
template <typename U>
|
||||||
|
void readMultiDim(const std::string &s, std::vector<U> &buf, std::vector<size_t> &dim);
|
||||||
private:
|
private:
|
||||||
void checkIndent(void);
|
void checkIndent(void);
|
||||||
private:
|
private:
|
||||||
@ -95,7 +99,18 @@ namespace Grid
|
|||||||
write(s, x[i]);
|
write(s, x[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename U>
|
||||||
|
void TextWriter::writeMultiDim(const std::string &s, const std::vector<size_t> & Dimensions, const U * pDataRowMajor, size_t NumElements)
|
||||||
|
{
|
||||||
|
uint64_t Rank = Dimensions.size();
|
||||||
|
write(s, Rank);
|
||||||
|
for( uint64_t d : Dimensions )
|
||||||
|
write(s, d);
|
||||||
|
while( NumElements-- )
|
||||||
|
write(s, *pDataRowMajor++);
|
||||||
|
}
|
||||||
|
|
||||||
// Reader template implementation ////////////////////////////////////////////
|
// Reader template implementation ////////////////////////////////////////////
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void TextReader::readDefault(const std::string &s, U &output)
|
void TextReader::readDefault(const std::string &s, U &output)
|
||||||
@ -121,6 +136,23 @@ namespace Grid
|
|||||||
read("", output[i]);
|
read("", output[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename U>
|
||||||
|
void TextReader::readMultiDim(const std::string &s, std::vector<U> &buf, std::vector<size_t> &dim)
|
||||||
|
{
|
||||||
|
const char sz[] = "";
|
||||||
|
uint64_t Rank;
|
||||||
|
read(sz, Rank);
|
||||||
|
dim.resize( Rank );
|
||||||
|
size_t NumElements = 1;
|
||||||
|
for( auto &d : dim ) {
|
||||||
|
read(sz, d);
|
||||||
|
NumElements *= d;
|
||||||
|
}
|
||||||
|
buf.resize( NumElements );
|
||||||
|
for( auto i = 0; i < NumElements; i++ )
|
||||||
|
read(s, buf[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -299,6 +299,8 @@ int main(int argc,char **argv)
|
|||||||
EigenHdf5IOTest<XmlWriter, XmlReader>(".xml");
|
EigenHdf5IOTest<XmlWriter, XmlReader>(".xml");
|
||||||
std::cout << "\n==== detailed binary tensor tests (Grid::EigenIO)" << std::endl;
|
std::cout << "\n==== detailed binary tensor tests (Grid::EigenIO)" << std::endl;
|
||||||
EigenHdf5IOTest<BinaryWriter, BinaryReader>(".bin");
|
EigenHdf5IOTest<BinaryWriter, BinaryReader>(".bin");
|
||||||
|
std::cout << "\n==== detailed text tensor tests (Grid::EigenIO)" << std::endl;
|
||||||
|
EigenHdf5IOTest<TextWriter, TextReader>(".dat");
|
||||||
|
|
||||||
std::cout << "\n==== vector flattening/reconstruction" << std::endl;
|
std::cout << "\n==== vector flattening/reconstruction" << std::endl;
|
||||||
typedef std::vector<std::vector<std::vector<double>>> vec3d;
|
typedef std::vector<std::vector<std::vector<double>>> vec3d;
|
||||||
|
Loading…
Reference in New Issue
Block a user