27 #ifndef INTERNAL_CLASSES_IOMANIP_H_
28 #define INTERNAL_CLASSES_IOMANIP_H_
37 template<
typename InputIterator>
44 const std::string& separator,
45 const std::string& start =
"[",
46 const std::string& end =
"]") :
49 _separator{separator},
63 std::ostream&
display(std::ostream& os)
const override
68 for (
auto it = _first; it !=
_last; ++it)
81 template<
typename Po
interType>
84 const PointerType*
_p;
89 const std::string& separator,
90 const std::string& start =
"[",
91 const std::string& end =
"]") :
94 _separator{separator},
106 std::ostream&
display(std::ostream& os)
const override
110 for (
idx i = 0; i < _n - 1; ++i)
111 os << _p[i] << _separator;
127 template<
typename Derived>
130 _A{A.template cast<cplx>()}, _chop{
chop}
136 _A{cmat::Zero(1, 1)}, _chop{
chop}
143 std::ostream&
display(std::ostream& os)
const override
147 os <<
"Empty [" << _A.rows() <<
" x " << _A.cols() <<
"] matrix";
152 std::ostringstream ostr;
155 std::vector <std::string> vstr;
158 for (
idx i = 0; i < static_cast<idx>(_A.rows()); ++i)
161 j < static_cast<idx>(_A.cols()); ++j)
165 ostr.str(std::string {});
168 double re =
static_cast<cplx>(
_A(i, j)).real();
169 double im =
static_cast<cplx>(
_A(i, j)).imag();
171 if (std::abs(re) < _chop && std::abs(im) <
_chop)
176 vstr.push_back(ostr.str());
178 else if (std::abs(re) <
_chop)
181 vstr.push_back(ostr.str() +
"i");
183 else if (std::abs(im) <
_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(_A.cols(), 0);
207 for (
idx i = 0; i < static_cast<idx>(_A.rows());
210 j < static_cast<idx>(_A.cols()); ++j)
211 if (vstr[i * _A.cols() + j].size() > maxlengthcols[j])
212 maxlengthcols[j] = vstr[i * _A.cols() + j].size();
215 for (
idx i = 0; i < static_cast<idx>(_A.rows()); ++i)
217 os << std::setw(static_cast<int>(maxlengthcols[0])) << std::right
218 << vstr[i * _A.cols()];
221 j < static_cast<idx>(_A.cols()); ++j)
222 os << std::setw(static_cast<int>(maxlengthcols[j] + 2))
223 << std::right << vstr[i * _A.cols() + j];
225 if (i < static_cast<idx>(_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:65
std::string _start
Definition: iomanip.h:86
IOManipEigen(const Eigen::MatrixBase< Derived > &A, double chop=qpp::chop)
Definition: iomanip.h:128
std::string _separator
Definition: iomanip.h:41
double _chop
Definition: iomanip.h:124
std::string _separator
Definition: iomanip.h:86
cmat _A
Definition: iomanip.h:123
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:63
IOManipPointer & operator=(const IOManipPointer &)=default
Quantum++ main namespace.
Definition: codes.h:30
std::string _start
Definition: iomanip.h:41
std::string _end
Definition: iomanip.h:41
IOManipRange & operator=(const IOManipRange &)=default
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:106
std::string _end
Definition: iomanip.h:86
InputIterator _last
Definition: iomanip.h:40
Abstract class (interface) that mandates the definition of virtual std::ostream& display(std::ostream...
Definition: idisplay.h:43
Definition: iomanip.h:121
std::complex< double > cplx
Complex number in double precision.
Definition: types.h:51
IOManipRange(InputIterator first, InputIterator last, const std::string &separator, const std::string &start="[", const std::string &end="]")
Definition: iomanip.h:43
IOManipPointer(const PointerType *p, const idx n, const std::string &separator, const std::string &start="[", const std::string &end="]")
Definition: iomanip.h:88
bool _check_nonzero_size(const T &x) noexcept
Definition: util.h:113
IOManipEigen(const cplx z, double chop=qpp::chop)
Definition: iomanip.h:135
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:143
const PointerType * _p
Definition: iomanip.h:84
Eigen::MatrixXcd cmat
Complex (double precision) dynamic Eigen matrix.
Definition: types.h:66
std::size_t idx
Non-negative integer index.
Definition: types.h:36
InputIterator _first
Definition: iomanip.h:40
idx _n
Definition: iomanip.h:85