27 #ifndef INPUT_OUTPUT_H_
28 #define INPUT_OUTPUT_H_
43 template<
typename Derived>
74 template<
typename InputIterator>
76 const InputIterator& last,
77 const std::string& separator,
78 const std::string& start =
"[",
79 const std::string& end =
"]")
82 >(first, last, separator, start, end);
95 template<
typename Container>
97 const Container& c,
const std::string& separator,
98 const std::string& start =
"[",
const std::string& end =
"]")
101 c.begin(), c.end(), separator, start, end);
114 template<
typename Po
interType>
116 const std::string& separator,
117 const std::string& start =
"[",
118 const std::string& end =
"]")
131 template<
typename Derived>
132 void save(
const Eigen::MatrixBase<Derived>& A,
const std::string& fname)
141 fout.open(fname, std::ios::out | std::ios::binary);
145 throw std::runtime_error(
146 "qpp::save(): Error writing output file \""
147 + std::string(fname) +
"\"!");
151 const char _header[] =
"TYPE::Eigen::Matrix";
152 fout.write(_header,
sizeof(_header));
154 idx rows =
static_cast<idx>(rA.rows());
155 idx cols =
static_cast<idx>(rA.cols());
156 fout.write((
char*) &rows,
sizeof(rows));
157 fout.write((
char*) &cols,
sizeof(cols));
159 fout.write((
char*) rA.data(),
160 sizeof(
typename Derived::Scalar) * rows * cols);
183 template<
typename Derived>
187 fin.open(fname, std::ios::in | std::ios::binary);
191 throw std::runtime_error(
192 "qpp::load(): Error opening input file \""
193 + std::string(fname) +
"\"!");
196 const char _header[] =
"TYPE::Eigen::Matrix";
197 char* _fheader =
new char[
sizeof(_header)];
200 fin.read(_fheader,
sizeof(_header));
201 if (strcmp(_fheader, _header))
204 throw std::runtime_error(
205 "qpp::load(): Input file \"" + std::string(fname)
206 +
"\" is corrupted!");
211 fin.read((
char*) &rows,
sizeof(rows));
212 fin.read((
char*) &cols,
sizeof(cols));
216 fin.read((
char*) A.data(),
217 sizeof(
typename Derived::Scalar) * rows * cols);
constexpr double chop
Used in qpp::disp() for setting to zero numbers that have their absolute value smaller than qpp::chop...
Definition: constants.h:67
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > dyn_mat
Dynamic Eigen matrix over the field specified by Scalar.
Definition: types.h:84
Quantum++ main namespace.
Definition: codes.h:30
Definition: iomanip.h:114
std::complex< double > cplx
Complex number in double precision.
Definition: types.h:52
Generates custom exceptions, used when validating function parameters.
Definition: exception.h:39
bool _check_nonzero_size(const T &x) noexcept
Definition: util.h:113
dyn_mat< typename Derived::Scalar > load(const std::string &fname)
Loads Eigen matrix from a binary file (internal format) in double precision.
Definition: input_output.h:184
void save(const Eigen::MatrixBase< Derived > &A, const std::string &fname)
Saves Eigen expression to a binary file (internal format) in double precision.
Definition: input_output.h:132
std::size_t idx
Non-negative integer index.
Definition: types.h:36
internal::IOManipEigen disp(const Eigen::MatrixBase< Derived > &A, double chop=qpp::chop)
Eigen expression ostream manipulator.
Definition: input_output.h:44