ostream_diagmat.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 template<typename T1>
00022 inline
00023 std::ostream&
00024 operator<< (std::ostream& o, const Op<T1,op_diagmat>& X)
00025 {
00026 arma_extra_debug_sigprint();
00027
00028 typedef typename T1::elem_type eT;
00029
00030 const unwrap<T1> tmp(X.m);
00031 const Mat<eT>& m = tmp.M;
00032
00033 arma_debug_check( ((m.is_vec() == false) && (m.is_square() == false)), "operator<<(): incompatible dimensions for diagmat operation" );
00034
00035 const arma_ostream_state stream_state(o);
00036
00037 const u32 cell_width = arma_ostream::modify_stream(o, m);
00038
00039 const u32 local_n_rows = (std::max)(m.n_rows, m.n_cols);
00040
00041 for(u32 row=0; row < local_n_rows; ++row)
00042 {
00043 for(u32 col=0; col < local_n_rows; ++col)
00044 {
00045 if(row != col)
00046 {
00047 o.width(cell_width);
00048 if(is_complex<eT>::value == false)
00049 {
00050 o << "0.0";
00051 }
00052 else
00053 {
00054 o << "(0.0,0.0)";
00055 }
00056 }
00057 else
00058 {
00059 const eT val = m.is_vec() ? m.mem[row] : m.at(row,row);
00060
00061 o.width(cell_width);
00062 o << val;
00063 }
00064 }
00065 o << '\n';
00066 }
00067
00068 o.flush();
00069
00070 stream_state.restore(o);
00071
00072 return o;
00073 }
00074
00075