Arma_ostream

Classes

class  arma_ostream_state
class  arma_ostream

Functions

 arma_ostream_state::arma_ostream_state (const std::ostream &o)
void arma_ostream_state::restore (std::ostream &o) const
template<typename eT >
static u32 arma_ostream::modify_stream (std::ostream &o, const eT *data, const u32 n_elem)
template<typename T >
static u32 arma_ostream::modify_stream (std::ostream &o, const std::complex< T > *data, const u32 n_elem)
 "better than nothing" settings for complex numbers
template<typename eT >
static arma_inline void arma_ostream::print_elem (std::ostream &o, const eT &x)
 Print an element to the specified stream.
template<typename T >
static arma_inline void arma_ostream::print_elem (std::ostream &o, const std::complex< T > &x)
 Print a complex element to the specified stream EXPERIMENTAL !
template<typename eT >
static void arma_ostream::print (std::ostream &o, const Mat< eT > &m, const bool modify)
 Print a matrix to the specified stream.
template<typename eT >
static void arma_ostream::print (std::ostream &o, const Cube< eT > &m, const bool modify)
 Print a cube to the specified stream.
template<typename oT >
static void arma_ostream::print (std::ostream &o, const field< oT > &m)
 Print a field to the specified stream Assumes type oT can be printed, i.e. oT has std::ostream& operator<< (std::ostream&, const oT&).
template<typename oT >
static void arma_ostream::print (std::ostream &o, const subview_field< oT > &m)
 Print a subfield to the specified stream Assumes type oT can be printed, i.e. oT has std::ostream& operator<< (std::ostream&, const oT&).

Function Documentation

arma_ostream_state::arma_ostream_state ( const std::ostream &  o  )  [inline, inherited]

Definition at line 23 of file arma_ostream_meat.hpp.

00024   : orig_flags    (o.flags())
00025   , orig_precision(o.precision())
00026   , orig_width    (o.width())
00027   , orig_fill     (o.fill())
00028   {
00029   }

void arma_ostream_state::restore ( std::ostream &  o  )  const [inline, inherited]

Definition at line 35 of file arma_ostream_meat.hpp.

References arma_ostream_state::orig_fill, arma_ostream_state::orig_flags, arma_ostream_state::orig_precision, and arma_ostream_state::orig_width.

Referenced by print().

00036   {
00037   o.flags    (orig_flags);
00038   o.precision(orig_precision);
00039   o.width    (orig_width);
00040   o.fill     (orig_fill);
00041   }

template<typename eT >
u32 arma_ostream::modify_stream ( std::ostream &  o,
const eT *  data,
const u32  n_elem 
) [inline, static, inherited]

Definition at line 53 of file arma_ostream_meat.hpp.

Referenced by print().

00054   {
00055   o.unsetf(ios::showbase);
00056   o.unsetf(ios::uppercase);
00057   o.unsetf(ios::showpos);
00058   
00059   o.fill(' ');
00060   
00061   u32 cell_width;
00062   
00063   bool use_layout_B = false;
00064   bool use_layout_C = false;
00065   
00066   for(u32 i=0; i<n_elem; ++i)
00067     {
00068     const eT val = data[i];
00069     
00070     if(
00071       val >= eT(+100) ||
00072       ( (is_signed<eT>::value == true) && (val <= eT(-100)) ) ||
00073       ( (is_non_integral<eT>::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) ||
00074       ( (is_non_integral<eT>::value == true) && (is_signed<eT>::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) ) 
00075       )
00076       {
00077       use_layout_C = true;
00078       break;
00079       }
00080       
00081     if(
00082       (val >= eT(+10)) || ( (is_signed<eT>::value == true) && (val <= eT(-10)) )
00083       )
00084       {
00085       use_layout_B = true;
00086       }
00087     }
00088   
00089   if(use_layout_C == true)
00090     {
00091     o.setf(ios::scientific);
00092     o.setf(ios::right);
00093     o.unsetf(ios::fixed);
00094     o.precision(4);
00095     cell_width = 13;
00096     }
00097   else
00098   if(use_layout_B == true)
00099     {
00100     o.unsetf(ios::scientific);
00101     o.setf(ios::right);
00102     o.setf(ios::fixed);
00103     o.precision(4);
00104     cell_width = 10;
00105     }
00106   else
00107     {
00108     o.unsetf(ios::scientific);
00109     o.setf(ios::right);
00110     o.setf(ios::fixed);
00111     o.precision(4);
00112     cell_width = 9;
00113     }
00114   
00115   return cell_width;
00116   }

template<typename T >
u32 arma_ostream::modify_stream ( std::ostream &  o,
const std::complex< T > *  data,
const u32  n_elem 
) [inline, static, inherited]

"better than nothing" settings for complex numbers

Definition at line 124 of file arma_ostream_meat.hpp.

00125   {
00126   o.unsetf(ios::showbase);
00127   o.unsetf(ios::uppercase);
00128   o.fill(' ');
00129   
00130   o.setf(ios::scientific);
00131   o.setf(ios::showpos);
00132   o.setf(ios::right);
00133   o.unsetf(ios::fixed);
00134   
00135   u32 cell_width;
00136   
00137   o.precision(3);
00138   cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1;
00139 
00140   return cell_width;
00141   }

template<typename eT >
arma_inline void arma_ostream::print_elem ( std::ostream &  o,
const eT &  x 
) [inline, static, inherited]

Print an element to the specified stream.

Definition at line 149 of file arma_ostream_meat.hpp.

Referenced by print().

00150   {
00151   if(x != eT(0))
00152     {
00153     o << x;
00154     }
00155   else
00156     {
00157     const std::streamsize orig_precision = o.precision();
00158     
00159     o.precision(0);
00160     
00161     o << eT(0);
00162     
00163     o.precision(orig_precision);
00164     }
00165   }

template<typename T >
arma_inline void arma_ostream::print_elem ( std::ostream &  o,
const std::complex< T > &  x 
) [inline, static, inherited]

Print a complex element to the specified stream EXPERIMENTAL !

Definition at line 174 of file arma_ostream_meat.hpp.

00175   {
00176   if( (x.real() != T(0)) || (x.imag() != T(0)) )
00177     {
00178     std::ostringstream ss;
00179     ss.flags(o.flags());
00180     //ss.imbue(o.getloc());
00181     ss.precision(o.precision());
00182   
00183     ss << '(' << x.real() << ',' << x.imag() << ')';
00184     o << ss.str();
00185     }
00186   else
00187     {
00188     o << "(0,0)";
00189     }
00190   }

template<typename eT >
void arma_ostream::print ( std::ostream &  o,
const Mat< eT > &  m,
const bool  modify 
) [inline, static, inherited]

Print a matrix to the specified stream.

Definition at line 198 of file arma_ostream_meat.hpp.

References Mat< eT >::at(), Mat< eT >::memptr(), modify_stream(), Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, print_elem(), and arma_ostream_state::restore().

Referenced by operator<<(), and print().

00199   {
00200   arma_extra_debug_sigprint();
00201   
00202   const arma_ostream_state stream_state(o);
00203 
00204   u32 cell_width;
00205   
00206   if(modify == true)
00207     {
00208     cell_width = arma_ostream::modify_stream(o, m.memptr(), m.n_elem);
00209     }
00210   else
00211     {
00212     cell_width = o.width();  // copy the user's cell width
00213     }
00214   
00215   if(cell_width > 0)
00216     {
00217     for(u32 row=0; row < m.n_rows; ++row)
00218       {
00219       for(u32 col=0; col < m.n_cols; ++col)
00220         {
00221         // the cell width appears to be reset after each element is printed,
00222         // hence we need to restore it
00223         o.width(cell_width);
00224         arma_ostream::print_elem(o, m.at(row,col));
00225         }
00226       
00227       o << '\n';
00228       }
00229     }
00230   else
00231     {
00232     for(u32 row=0; row < m.n_rows; ++row)
00233       {
00234       for(u32 col=0; col < m.n_cols-1; ++col)
00235         {
00236         arma_ostream::print_elem(o, m.at(row,col));
00237         o << ' ';
00238         }
00239       
00240       arma_ostream::print_elem(o, m.at(row, m.n_cols-1));
00241       o << '\n';
00242       }
00243     }
00244   
00245   o.flush();
00246   stream_state.restore(o);
00247   }

template<typename eT >
void arma_ostream::print ( std::ostream &  o,
const Cube< eT > &  m,
const bool  modify 
) [inline, static, inherited]

Print a cube to the specified stream.

Definition at line 255 of file arma_ostream_meat.hpp.

References Cube< eT >::memptr(), modify_stream(), Cube< eT >::n_elem, Cube< eT >::n_slices, print(), arma_ostream_state::restore(), and Cube< eT >::slice().

00256   {
00257   arma_extra_debug_sigprint();
00258   
00259   const arma_ostream_state stream_state(o);
00260 
00261   u32 cell_width;
00262   
00263   if(modify == true)
00264     {
00265     cell_width = arma_ostream::modify_stream(o, x.memptr(), x.n_elem);
00266     }
00267   else
00268     {
00269     cell_width = o.width();
00270     }
00271   
00272   for(u32 slice=0; slice < x.n_slices; ++slice)
00273     {
00274     o << "[cube slice " << slice << ']' << '\n';
00275     o.width(cell_width);
00276     arma_ostream::print(o, x.slice(slice), false);
00277     o << '\n';
00278     }
00279 
00280   stream_state.restore(o);
00281   }

template<typename oT >
void arma_ostream::print ( std::ostream &  o,
const field< oT > &  m 
) [inline, static, inherited]

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

Definition at line 291 of file arma_ostream_meat.hpp.

References field< oT >::at(), field< oT >::n_cols, field< oT >::n_rows, and arma_ostream_state::restore().

00292   {
00293   arma_extra_debug_sigprint();
00294   
00295   const arma_ostream_state stream_state(o);
00296 
00297   const std::streamsize cell_width = o.width();
00298 
00299   for(u32 col=0; col<x.n_cols; ++col)
00300     {
00301     o << "[field column " << col << ']' << '\n'; 
00302     for(u32 row=0; row<x.n_rows; ++row)
00303       {
00304       o.width(cell_width);
00305       o << x.at(row,col) << '\n';
00306       }
00307     
00308     o << '\n';
00309     }
00310   
00311   o.flush();
00312   stream_state.restore(o);
00313   }

template<typename oT >
void arma_ostream::print ( std::ostream &  o,
const subview_field< oT > &  m 
) [inline, static, inherited]

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

Definition at line 322 of file arma_ostream_meat.hpp.

References subview_field< oT >::at(), subview_field< oT >::n_cols, subview_field< oT >::n_rows, and arma_ostream_state::restore().

00323   {
00324   arma_extra_debug_sigprint();
00325   
00326   const arma_ostream_state stream_state(o);
00327   
00328   const std::streamsize cell_width = o.width();
00329   
00330   for(u32 col=0; col<x.n_cols; ++col)
00331     {
00332     o << "[subfield column " << col << ']' << '\n'; 
00333     for(u32 row=0; row<x.n_rows; ++row)
00334       {
00335       o.width(cell_width);
00336       o << x.at(row,col) << '\n';
00337       }
00338     
00339     o << '\n';
00340     }
00341   
00342   o.flush();
00343   stream_state.restore(o);
00344   }