Ostream


Classes

class  arma_ostream

Functions

template<typename T1 >
std::ostream & operator<< (std::ostream &o, const Op< T1, op_diagmat > &X)
 Print a diagonal matrix to the specified stream.
template<typename T1 >
std::ostream & operator<< (std::ostream &o, const field< T1 > &X)
 Print the contents of a field to the specified stream Assumes type T1 can be printed, i.e. T1 has std::ostream& operator<< (std::ostream&, const T1&).
template<typename T1 >
std::ostream & operator<< (std::ostream &o, const subview_field< T1 > &X)
 Print the contents of a subfield to the specified stream Assumes type T1 can be printed, i.e. T1 has std::ostream& operator<< (std::ostream&, const T1&).
template<typename eT >
std::ostream & operator<< (std::ostream &o, const Mat< eT > &m)
 Print a matrix to the specified stream.
template<typename T1 >
std::ostream & operator<< (std::ostream &o, const Base< typename T1::elem_type, T1 > &X)
template<typename eT >
static u32 arma_ostream::set_flags (std::ostream &o, const Mat< eT > &m)
template<typename T >
static u32 arma_ostream::set_flags (std::ostream &o, const Mat< std::complex< T > > &m)
 "better than nothing" settings for complex numbers

Function Documentation

template<typename T1 >
std::ostream& operator<< ( std::ostream &  o,
const Op< T1, op_diagmat > &  X 
) [inline]

Print a diagonal matrix to the specified stream.

Definition at line 24 of file ostream_diagmat.hpp.

References Mat< eT >::at(), Mat< eT >::is_square(), Mat< eT >::is_vec(), max(), Mat< eT >::mem, Mat< eT >::n_cols, Mat< eT >::n_rows, and arma_ostream::set_flags().

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 ios::fmtflags orig_flags = o.flags();
00036   const u32 cell_width = arma_ostream::set_flags(o, m);
00037   
00038   const u32 local_n_rows = (std::max)(m.n_rows, m.n_cols);
00039   
00040   for(u32 row=0; row < local_n_rows; ++row)
00041     {
00042     for(u32 col=0; col < local_n_rows; ++col)
00043       {
00044       if(row != col)
00045         {
00046         o.width(cell_width);
00047         if(is_complex<eT>::value == false)
00048           {
00049           o << "0.0";
00050           }
00051         else
00052           {
00053           o << "(0.0,0.0)";
00054           }
00055         }
00056       else
00057         {
00058         const eT val = m.is_vec() ? m.mem[row] : m.at(row,row);
00059         
00060         o.width(cell_width);
00061         o << val;
00062         }
00063       }
00064       o << '\n';
00065     }
00066   
00067   o.flags(orig_flags);
00068   return o;
00069   }

template<typename T1 >
std::ostream& operator<< ( std::ostream &  o,
const field< T1 > &  X 
) [inline]

Print the contents of a field to the specified stream Assumes type T1 can be printed, i.e. T1 has std::ostream& operator<< (std::ostream&, const T1&).

Definition at line 26 of file ostream_field.hpp.

00027   {
00028   arma_extra_debug_sigprint();
00029   
00030   const ios::fmtflags orig_flags = o.flags();
00031   
00032   for(u32 col=0; col<X.n_cols; ++col)
00033     {
00034     o << "[field column " << col << ']' << '\n'; 
00035     for(u32 row=0; row<X.n_rows; ++row)
00036       {
00037       o << X.at(row,col) << '\n';
00038       }
00039     
00040     o << '\n';
00041     }
00042   
00043   o.flush();
00044   o.flags(orig_flags);
00045   
00046   return o;
00047   }

template<typename T1 >
std::ostream& operator<< ( std::ostream &  o,
const subview_field< T1 > &  X 
) [inline]

Print the contents of a subfield to the specified stream Assumes type T1 can be printed, i.e. T1 has std::ostream& operator<< (std::ostream&, const T1&).

Definition at line 57 of file ostream_field.hpp.

00058   {
00059   arma_extra_debug_sigprint();
00060   
00061   const ios::fmtflags orig_flags = o.flags();
00062   
00063   for(u32 col=0; col<X.n_cols; ++col)
00064     {
00065     for(u32 row=0; row<X.n_rows; ++row)
00066       {
00067       o << X.at(row,col) << '\n';
00068       }
00069     
00070     o << '\n';
00071     }
00072   
00073   o.flush();
00074   o.flags(orig_flags);
00075   
00076   return o;
00077   }

template<typename eT >
std::ostream& operator<< ( std::ostream &  o,
const Mat< eT > &  m 
) [inline]

Print a matrix to the specified stream.

Definition at line 122 of file ostream_mat.hpp.

References arma_ostream::set_flags().

00123   {
00124   arma_extra_debug_sigprint();
00125   
00126   const ios::fmtflags orig_flags = o.flags();
00127   const u32 cell_width = arma_ostream::set_flags(o, m);
00128   
00129   for(u32 row=0; row != m.n_rows; ++row)
00130     {
00131     for(u32 col=0; col != m.n_cols; ++col)
00132       {
00133       o.width(cell_width);
00134       o << m.at(row,col);
00135       }
00136     
00137     o << '\n';
00138     }
00139   
00140   o.flush();
00141   o.flags(orig_flags);
00142   
00143   return o;
00144   }

template<typename T1 >
std::ostream& operator<< ( std::ostream &  o,
const Base< typename T1::elem_type, T1 > &  X 
) [inline]

Definition at line 22 of file ostream_misc.hpp.

00023   {
00024   arma_extra_debug_sigprint();
00025   
00026   const unwrap<T1> tmp(X.get_ref());
00027   
00028   o << tmp.M;
00029   
00030   return o;
00031   }

template<typename eT >
u32 arma_ostream::set_flags ( std::ostream &  o,
const Mat< eT > &  m 
) [inline, static, inherited]

Definition at line 36 of file ostream_mat.hpp.

References Mat< eT >::mem, and Mat< eT >::n_elem.

Referenced by operator<<().

00037   {
00038   o.unsetf(ios::showbase);
00039   o.unsetf(ios::uppercase);
00040   o.fill(' ');
00041   
00042   bool use_layout_B = false;
00043   bool use_layout_C = false;
00044   
00045   for(u32 i=0; i<m.n_elem; ++i)
00046     {
00047     const eT val = m.mem[i];
00048     
00049     if(
00050       val >= eT(+100) ||
00051       ( (is_signed<eT>::value == true) && (val <= eT(-100)) ) ||
00052       ( (is_non_integral<eT>::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) ||
00053       ( (is_non_integral<eT>::value == true) && (is_signed<eT>::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) ) 
00054       )
00055       {
00056       use_layout_C = true;
00057       break;
00058       }
00059       
00060     if(
00061       (val >= eT(+10)) || ( (is_signed<eT>::value == true) && (val <= eT(-10)) )
00062       )
00063       {
00064       use_layout_B = true;
00065       }
00066     }
00067   
00068   u32 cell_width;
00069   
00070   if(use_layout_C == true)
00071     {
00072     o.setf(ios::scientific);
00073     o.unsetf(ios::fixed);
00074     o.precision(4);
00075     cell_width = 13;
00076     }
00077   else
00078   if(use_layout_B == true)
00079     {
00080     o.unsetf(ios::scientific);
00081     o.setf(ios::fixed);
00082     o.precision(4);
00083     cell_width = 10;
00084     }
00085   else
00086     {
00087     o.unsetf(ios::scientific);
00088     o.setf(ios::fixed);
00089     o.precision(4);
00090     cell_width = 9;
00091     }
00092  
00093   return cell_width;
00094   }

template<typename T >
u32 arma_ostream::set_flags ( std::ostream &  o,
const Mat< std::complex< T > > &  m 
) [inline, static, inherited]

"better than nothing" settings for complex numbers

Definition at line 102 of file ostream_mat.hpp.

00103   {
00104   o.unsetf(ios::showbase);
00105   o.unsetf(ios::uppercase);
00106   o.fill(' ');
00107   
00108   o.setf(ios::scientific);
00109   o.setf(ios::showpos);
00110   o.unsetf(ios::fixed);
00111   o.precision(3);
00112   const u32 cell_width = 25;
00113   return cell_width;
00114   }