25#ifndef __SERIALIZE_MDARRAY_HPP__
26#define __SERIALIZE_MDARRAY_HPP__
33template <
typename T,
int N>
35serialize(sddk::mdarray<T, N>
const& a__)
38 std::array<sddk::mdarray_index_descriptor::index_type, N> begin;
39 std::array<sddk::mdarray_index_descriptor::index_type, N> end;
40 for (
int i = 0; i < N; i++) {
41 begin[i] = a__.dim(i).begin();
42 end[i] = a__.dim(i).begin();
44 dict[
"begin"] = begin;
46 dict[
"data"] = std::vector<T>(a__.size());
47 for (
size_t i = 0; i < a__.size(); i++) {
48 dict[
"data"][i] = a__[i];
53template <
typename T,
int N>
55serialize(sddk::mdarray<std::complex<T>, N>
const& a__)
58 std::array<sddk::mdarray_index_descriptor::index_type, N> begin;
59 std::array<sddk::mdarray_index_descriptor::index_type, N> end;
60 for (
int i = 0; i < N; i++) {
61 begin[i] = a__.dim(i).begin();
62 end[i] = a__.dim(i).begin();
64 dict[
"begin"] = begin;
66 dict[
"data"] = std::vector<T>(2 * a__.size());
67 for (
size_t i = 0; i < a__.size(); i++) {
68 dict[
"data"][2 * i] = a__[i].real();
69 dict[
"data"][2 * i + 1] = a__[i].imag();
74template <
typename T,
int N>
76write_to_json_file(sddk::mdarray<T, N>
const& a__, std::string
const& fname__)
79 auto dict = serialize(a__);
80 std::ofstream ofs(fname__, std::ofstream::out | std::ofstream::trunc);
84 s <<
"Error writing mdarray to file " << fname__;
85 printf(
"%s\n", s.str().c_str());
Interface to nlohmann::json library and helper functions.
Memory management functions and classes.
Namespace of the SIRIUS library.