7 #ifndef ALPS_HDF5_STD_VALARRAY_HPP 8 #define ALPS_HDF5_STD_VALARRAY_HPP 13 #include <type_traits> 35 template<
typename T>
struct get_extent<std::valarray<T> > {
36 static std::vector<std::size_t> apply(std::valarray<T>
const & value) {
38 std::vector<std::size_t>
result(1, value.size());
40 std::vector<std::size_t> extent(
get_extent(
const_cast<std::valarray<T> &
>(value)[0]));
41 if (!std::is_scalar<T>::value)
42 for (std::size_t i = 1; i < value.size(); ++i)
43 if (!std::equal(extent.begin(), extent.end(),
get_extent(
const_cast<std::valarray<T> &
>(value)[i]).begin()))
45 std::copy(extent.begin(), extent.end(), std::back_inserter(
result));
51 template<
typename T>
struct set_extent<std::valarray<T> > {
52 static void apply(std::valarray<T> & value, std::vector<std::size_t>
const & extent) {
54 value.resize(extent[0]);
55 if (extent.size() > 1)
56 for(std::size_t i = 0; i < value.size(); ++i)
57 set_extent(value[i], std::vector<std::size_t>(extent.begin() + 1, extent.end()));
58 else if (extent.size() == 0 && !std::is_same<typename scalar_type<T>::type, T>::value)
64 static bool apply(std::valarray<T>
const & value) {
70 std::vector<std::size_t> first(
get_extent(
const_cast<std::valarray<T> &
>(value)[0]));
71 if (!std::is_scalar<T>::value) {
72 for(std::size_t i = 0; i < value.size(); ++i)
76 std::vector<std::size_t>
size(
get_extent(
const_cast<std::valarray<T> &
>(value)[i]));
78 first.size() != size.size()
79 || !std::equal(first.begin(), first.end(), size.begin())
90 template<
typename T>
struct get_pointer<std::valarray<T> > {
97 template<
typename T>
struct get_pointer<std::valarray<T> const> {
100 return get_pointer(
const_cast<std::valarray<T> &
>(value)[0]);
105 template<
typename T>
void save(
107 , std::string
const & path
108 , std::valarray<T>
const & value
109 , std::vector<std::size_t>
size = std::vector<std::size_t>()
110 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
111 , std::vector<std::size_t> offset = std::vector<std::size_t>()
116 ar.
write(path, static_cast<
typename scalar_type<std::valarray<T> >::
type const *>(NULL), std::vector<std::size_t>());
118 std::vector<std::size_t> extent(
get_extent(value));
119 std::copy(extent.begin(), extent.end(), std::back_inserter(
size));
120 std::copy(extent.begin(), extent.end(), std::back_inserter(chunk));
121 std::fill_n(std::back_inserter(offset), extent.size(), 0);
123 }
else if (value.size() == 0)
124 ar.
write(path, static_cast<int const *>(NULL), std::vector<std::size_t>());
126 size.push_back(value.size());
129 for(std::size_t i = 0; i < value.size(); ++i) {
131 save(ar, path,
const_cast<std::valarray<T> &
>(value)[i],
size, chunk, offset);
136 for(std::size_t i = 0; i < value.size(); ++i)
137 save(ar, ar.
complete_path(path) +
"/" + cast<std::string>(i),
const_cast<std::valarray<T> &
>(value)[i]);
141 template<
typename T>
void load(
143 , std::string
const & path
144 , std::valarray<T> & value
145 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
146 , std::vector<std::size_t> offset = std::vector<std::size_t>()
150 value.resize(children.size());
151 for (
typename std::vector<std::string>::const_iterator it = children.begin(); it != children.end(); ++it)
156 std::vector<std::size_t>
size(ar.
extent(path));
159 std::copy(
size.begin() + chunk.size(),
size.end(), std::back_inserter(chunk));
160 std::fill_n(std::back_inserter(offset),
size.size() - offset.size(), 0);
163 set_extent(value, std::vector<std::size_t>(1, *(
size.begin() + chunk.size())));
166 for(std::size_t i = 0; i < value.size(); ++i) {
168 load(ar, path, value[i], chunk, offset);
void load(archive &ar, std::string const &path, T &value, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())
bool is_vectorizable(T const &value)
void set_extent(T &value, std::vector< std::size_t > const &size)
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
bool is_data(std::string path) const
std::vector< std::size_t > get_extent(T const &value)
void delete_data(std::string path) const
void delete_group(std::string path) const
scalar_type< T >::type * get_pointer(T &value)
std::vector< std::size_t > extent(std::string path) const
std::vector< std::string > list_children(std::string path) const
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
scalar_type< T >::type type
traits< Acc >::result_type result(const Acc &acc)
bool is_group(std::string path) const
std::string complete_path(std::string path) const
bool is_complex(std::string path) const
void save(archive &ar, std::string const &path, T const &value, std::vector< std::size_t >=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())