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},
56 std::ostream&
display(std::ostream& os)
const override
61 for (
auto it = _first; it !=
_last; ++it)
74 template<
typename Po
interType>
77 const PointerType*
_p;
82 const std::string& separator,
83 const std::string& start =
"[",
84 const std::string& end =
"]") :
87 _separator{separator},
99 std::ostream&
display(std::ostream& os)
const override
103 for (
idx i = 0; i < _n - 1; ++i)
104 os << _p[i] << _separator;
120 template<
typename Derived>
123 _A{A.template cast<cplx>()}, _chop{
chop}
129 _A{cmat::Zero(1, 1)}, _chop{
chop}
136 std::ostream&
display(std::ostream& os)
const override
140 os <<
"Empty [" << _A.rows() <<
" x " << _A.cols() <<
"] matrix";
145 std::ostringstream ostr;
148 std::vector <std::string> vstr;
151 for (
idx i = 0; i < static_cast<idx>(_A.rows()); ++i)
154 j < static_cast<idx>(_A.cols()); ++j)
158 ostr.str(std::string {});
161 double re =
static_cast<cplx>(
_A(i, j)).real();
162 double im =
static_cast<cplx>(
_A(i, j)).imag();
164 if (std::abs(re) < _chop && std::abs(im) <
_chop)
169 vstr.push_back(ostr.str());
171 else if (std::abs(re) <
_chop)
174 vstr.push_back(ostr.str() +
"i");
176 else if (std::abs(im) <
_chop)
179 vstr.push_back(ostr.str() +
" ");
186 strA += (im > 0 ?
" + " :
" - ");
188 ostr.str(std::string());
189 ostr << std::abs(im);
192 vstr.push_back(strA);
198 std::vector <idx> maxlengthcols(_A.cols(), 0);
200 for (
idx i = 0; i < static_cast<idx>(_A.rows());
203 j < static_cast<idx>(_A.cols()); ++j)
204 if (vstr[i * _A.cols() + j].size() > maxlengthcols[j])
205 maxlengthcols[j] = vstr[i * _A.cols() + j].size();
208 for (
idx i = 0; i < static_cast<idx>(_A.rows()); ++i)
210 os << std::setw(static_cast<int>(maxlengthcols[0])) << std::right
211 << vstr[i * _A.cols()];
214 j < static_cast<idx>(_A.cols()); ++j)
215 os << std::setw(static_cast<int>(maxlengthcols[j] + 2))
216 << std::right << vstr[i * _A.cols() + j];
218 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:67
std::string _start
Definition: iomanip.h:79
IOManipEigen(const Eigen::MatrixBase< Derived > &A, double chop=qpp::chop)
Definition: iomanip.h:121
std::string _separator
Definition: iomanip.h:41
double _chop
Definition: iomanip.h:117
std::string _separator
Definition: iomanip.h:79
cmat _A
Definition: iomanip.h:116
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:56
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
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:99
std::string _end
Definition: iomanip.h:79
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:114
std::complex< double > cplx
Complex number in double precision.
Definition: types.h:52
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:81
bool _check_nonzero_size(const T &x) noexcept
Definition: util.h:113
IOManipEigen(const cplx z, double chop=qpp::chop)
Definition: iomanip.h:128
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:136
const PointerType * _p
Definition: iomanip.h:77
Eigen::MatrixXcd cmat
Complex (double precision) dynamic Eigen matrix.
Definition: types.h:67
std::size_t idx
Non-negative integer index.
Definition: types.h:36
InputIterator _first
Definition: iomanip.h:40
idx _n
Definition: iomanip.h:78