16 namespace alps {
namespace alea {
31 void enter(
const std::string &group)
override 34 group_.push_back(group);
40 throw std::runtime_error(
"exit without enter");
48 void write(
const std::string &key,
ndview<
const std::complex<double>> value)
override {
66 std::vector<size_t>
get_shape(
const std::string &key)
override {
74 void read(
const std::string &key,
ndview<std::complex<double>> value)
override {
93 if (!group_.empty()) {
94 std::cerr <<
"alps::alea::hdf5_serializer: warning: " 95 <<
"enter without exit\n Lingering groups:" 101 template <
typename T>
104 std::string path =
get_path(relpath);
106 std::vector<size_t> shape(data.
shape(), data.
shape() + data.
ndim());
107 std::vector<size_t> offset(shape.size(), 0);
108 std::vector<size_t> chunk = shape;
110 if (data.
ndim() == 0)
113 archive_->
write(path, data.
data(), shape, chunk, offset);
116 template <
typename T>
119 std::string path =
get_path(relpath);
121 if (data.ndim() == 0)
124 std::vector<size_t> shape(data.shape(), data.shape() + data.ndim());
126 std::vector<size_t> offset(shape.size(), 0);
127 std::vector<size_t> chunk = shape;
130 archive_->
write(path, reinterpret_cast<const T*>(data.data()), shape,
132 archive_->
write(path +
"/@__complex__",
true);
135 template <
typename T>
138 std::string path =
get_path(relpath);
142 if (data.
ndim() != shape.size())
144 for (
size_t i = 0; i != shape.size(); ++i)
145 if (shape[i] != data.
shape()[i])
149 if (data.
data() ==
nullptr)
156 std::vector<size_t> offset(shape.size(), 0);
157 std::vector<size_t> chunk = shape;
158 archive_->
read(path, data.
data(), chunk, offset);
162 template <
typename T>
165 std::string path =
get_path(relpath);
169 if (data.ndim() != shape.size() - 1)
171 for (
size_t i = 0; i != data.ndim(); ++i)
172 if (shape[i] != data.shape()[i])
174 if (shape[data.ndim()] != 2)
178 if (data.data() ==
nullptr)
182 std::vector<size_t> offset(shape.size(), 0);
183 std::vector<size_t> chunk = shape;
184 archive_->
read(path, reinterpret_cast<T*>(data.data()), chunk, offset);
187 archive_->
read(path +
"/@__complex__", tag);
192 std::ostringstream maker(path_, std::ios_base::app);
194 for (
const std::string &group : group_)
195 maker << group <<
'/';
196 if (key.find(
'/') != std::string::npos)
197 throw std::runtime_error(
"Key must not contain '/'");
205 return std::vector<size_t>();
207 return archive_->
extent(path);
213 std::vector<std::string> group_;
hdf5_serializer(hdf5::archive &ar, const std::string &path)
bool is_scalar(std::string path) const
std::string get_path(const std::string &key)
const size_t * shape() const
void read(const std::string &key, ndview< long > value) override
void do_write(const std::string &relpath, ndview< const T > data)
void enter(const std::string &group) override
void write(const std::string &key, ndview< const unsigned long > value) override
void read(const std::string &key, ndview< unsigned long > value) override
void write(const std::string &key, ndview< const long > value) override
void do_write(const std::string &relpath, ndview< const std::complex< T >> data)
void write(const std::string &key, ndview< const std::complex< double >> value) override
std::vector< std::size_t > extent(std::string path) const
std::vector< size_t > get_shape(const std::string &key) override
void read(const std::string &key, ndview< std::complex< double >> value) override
void create_group(std::string path) const
void write(const std::string &key, ndview< const complex_op< double >> value) override
auto read(std::string path, T *, std::vector< std::size_t >, std::vector< std::size_t >=std::vector< std::size_t >()) const -> typename std::enable_if<!is_native_type< T >::value, void >::type
auto write(std::string path, T const *value, std::vector< std::size_t > size, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t > offset=std::vector< std::size_t >()) const -> typename std::enable_if<!is_native_type< T >::value, void >::type
void read(const std::string &key, ndview< complex_op< double >> value) override
void do_read(const std::string &relpath, ndview< std::complex< T >> data)
void write(const std::string &key, ndview< const double > value) override
void read(const std::string &key, ndview< double > value) override
std::vector< size_t > get_extent(const std::string &path)
void do_read(const std::string &relpath, ndview< T > data)