7 #ifndef ALPS_HDF5_TENSOR_HPP_H 8 #define ALPS_HDF5_TENSOR_HPP_H 18 template<
typename T, std::
size_t N,
typename A>
struct scalar_type<
alps::numerics::detail::tensor_base<T, N, A> > {
22 template<
typename T, std::
size_t N,
typename A>
struct has_complex_elements<
alps::numerics::detail::tensor_base<T, N, A> >
23 :
public has_complex_elements<typename alps::detail::remove_cvr<T>::type>
28 template<
typename T, std::
size_t N,
typename A>
struct get_extent<alps::numerics::detail::tensor_base<T, N, A> > {
29 static std::vector<std::size_t> apply(
const alps::numerics::detail::tensor_base<T, N, A> & value) {
31 std::vector < std::size_t >
result(value.shape().begin(), value.shape().begin() + N);
33 std::vector < std::size_t > extent(
get_extent(value.data()[0]));
34 for (std::size_t i = 1; i < value.size(); ++i)
35 if (!std::equal(extent.begin(), extent.end(),
get_extent(value.data()[i]).begin()))
36 throw archive_error(
"no rectangular matrix");
37 std::copy(extent.begin(), extent.end(), std::back_inserter(
result));
43 template<
typename T, std::
size_t N,
typename A>
struct set_extent<alps::numerics::detail::tensor_base<T, N, A> > {
44 static void apply(alps::numerics::detail::tensor_base<T, N, A> & value, std::vector<std::size_t>
const &
size) {
48 throw archive_error(
"invalid data size");
49 std::vector < std::size_t > extent(
get_extent(value.data()[0]));
50 std::array<size_t, N> new_size;
51 std::copy(size.begin(), size.end() - extent.size(), new_size.begin());
52 value.reshape(new_size);
56 template<
typename T, std::
size_t N,
typename A>
struct get_pointer<alps::numerics::detail::tensor_base<T, N, A>> {
62 template<
typename T, std::
size_t N,
typename A>
struct get_pointer<const alps::numerics::detail::tensor_base<T, N, A> > {
71 template<
typename T, std::
size_t N,
typename S>
void save(
73 , std::string
const & path
74 ,
const alps::numerics::detail::tensor_base<T, N, S>& value
75 , std::vector<std::size_t> size = std::vector<std::size_t>()
76 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
77 , std::vector<std::size_t> offset = std::vector<std::size_t>()
79 std::vector<std::size_t> extent =
get_extent(value);
80 std::copy(extent.begin(), extent.end(), std::back_inserter(size));
81 std::copy(extent.begin(), extent.end(), std::back_inserter(chunk));
82 std::fill_n(std::back_inserter(offset), extent.size(), 0);
86 template<
typename T, std::
size_t N,
typename S>
void load(
88 , std::string
const & path
89 , numerics::detail::tensor_base<T, N, S> & value
90 , std::vector<std::size_t> chunk = std::vector<std::size_t>()
91 , std::vector<std::size_t> offset = std::vector<std::size_t>()
98 std::vector<std::size_t>
size(ar.
extent(path));
99 if (value.dimension() > size.size()) {
102 set_extent(value, std::vector<std::size_t>(size.begin() + chunk.size(), size.end()));
104 std::copy(size.begin() + chunk.size(), size.end(), std::back_inserter(chunk));
105 std::fill_n(std::back_inserter(offset), size.size() - offset.size(), 0);
112 #endif //ALPSCORE_TENSOR_HPP_H
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 >())
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 &)
std::vector< std::size_t > get_extent(T const &value)
scalar_type< T >::type * get_pointer(T &value)
std::vector< std::size_t > extent(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
traits< Acc >::result_type result(const Acc &acc)
bool is_group(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 >())