27 #ifndef INTERNAL_CLASSES_IOMANIP_H_
28 #define INTERNAL_CLASSES_IOMANIP_H_
38 template<
typename InputIterator>
41 InputIterator _first, _last;
42 std::string _separator, _start, _end;
45 const std::string& separator,
46 const std::string& start =
"[",
47 const std::string& end =
"]") :
50 _separator{separator},
56 template<
typename charT,
typename traits>
57 friend std::basic_ostream<charT, traits>&
58 operator<<(std::basic_ostream<charT, traits>& os,
const IOManipRange& rhs)
63 for (
auto it = rhs._first; it != rhs._last; ++it)
76 template<
typename Po
interType>
79 const PointerType* _p;
81 std::string _separator, _start, _end;
84 const std::string& separator,
85 const std::string& start =
"[",
86 const std::string& end =
"]") :
89 _separator{separator},
100 template<
typename charT,
typename traits>
101 friend std::basic_ostream<charT, traits>&
102 operator<<(std::basic_ostream<charT, traits>& os,
107 for (
idx i = 0; i < rhs._n - 1; ++i)
108 os << rhs._p[i] << rhs._separator;
110 os << rhs._p[rhs._n - 1];
124 template<
typename Derived>
127 _A{A.template cast<cplx>()}, _chop{
chop}
133 _A{cmat::Zero(1, 1)}, _chop{
chop}
139 template<
typename charT,
typename traits>
140 friend std::basic_ostream<charT, traits>&
141 operator<<(std::basic_ostream<charT, traits>& os,
const IOManipEigen& rhs)
145 os <<
"Empty [" << rhs._A.rows() <<
" x "
146 << rhs._A.cols() <<
"] matrix";
151 std::ostringstream ostr;
154 std::vector<std::string> vstr;
157 for (
idx i = 0; i < static_cast<idx>(rhs._A.rows());
161 j < static_cast<idx>(rhs._A.cols()); ++j)
165 ostr.str(std::string {});
168 double re =
static_cast<cplx>(rhs._A(i, j)).real();
169 double im =
static_cast<cplx>(rhs._A(i, j)).imag();
171 if (std::abs(re) < rhs._chop && std::abs(im) < rhs._chop)
176 vstr.push_back(ostr.str());
178 else if (std::abs(re) < rhs._chop)
181 vstr.push_back(ostr.str() +
"i");
183 else if (std::abs(im) < rhs._chop)
186 vstr.push_back(ostr.str() +
" ");
193 strA += (im > 0 ?
" + " :
" - ");
195 ostr.str(std::string());
196 ostr << std::abs(im);
199 vstr.push_back(strA);
205 std::vector<idx> maxlengthcols(rhs._A.cols(), 0);
207 for (
idx i = 0; i < static_cast<idx>(rhs._A.rows());
210 j < static_cast<idx>(rhs._A.cols()); ++j)
211 if (vstr[i * rhs._A.cols() + j].size() > maxlengthcols[j])
212 maxlengthcols[j] = vstr[i * rhs._A.cols() + j].size();
215 for (
idx i = 0; i < static_cast<idx>(rhs._A.rows());
218 os << std::setw(static_cast<int>(maxlengthcols[0])) << std::right
219 << vstr[i * rhs._A.cols()];
222 j < static_cast<idx>(rhs._A.cols()); ++j)
223 os << std::setw(static_cast<int>(maxlengthcols[j] + 2))
224 << std::right << vstr[i * rhs._A.cols() + j];
226 if (i < static_cast<idx>(rhs._A.rows()) - 1)
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
IOManipEigen(const Eigen::MatrixBase< Derived > &A, double chop=qpp::chop)
Definition: iomanip.h:125
IOManipPointer & operator=(const IOManipPointer &)=default
Quantum++ main namespace.
Definition: codes.h:30
Definition: iomanip.h:118
std::complex< double > cplx
Complex number in double precision.
Definition: types.h:41
IOManipRange(InputIterator first, InputIterator last, const std::string &separator, const std::string &start="[", const std::string &end="]")
Definition: iomanip.h:44
IOManipPointer(const PointerType *p, const idx n, const std::string &separator, const std::string &start="[", const std::string &end="]")
Definition: iomanip.h:83
bool _check_nonzero_size(const T &x) noexcept
Definition: util.h:119
IOManipEigen(const cplx z, double chop=qpp::chop)
Definition: iomanip.h:132
Eigen::MatrixXcd cmat
Complex (double precision) dynamic Eigen matrix.
Definition: types.h:56
std::size_t idx
Non-negative integer index.
Definition: types.h:36