initial implementation of .snip_print()
This commit is contained in:
@@ -119,6 +119,9 @@ struct Base
|
||||
arma_cold inline void raw_print( const std::string extra_text = "") const;
|
||||
arma_cold inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const;
|
||||
|
||||
arma_cold inline void snip_print( const std::string extra_text = "") const;
|
||||
arma_cold inline void snip_print(std::ostream& user_stream, const std::string extra_text = "") const;
|
||||
|
||||
inline arma_warn_unused elem_type sum() const;
|
||||
|
||||
inline arma_warn_unused elem_type min() const;
|
||||
|
||||
@@ -125,6 +125,54 @@ Base<elem_type,derived>::raw_print(std::ostream& user_stream, const std::string
|
||||
|
||||
|
||||
|
||||
template<typename elem_type, typename derived>
|
||||
arma_cold
|
||||
inline
|
||||
void
|
||||
Base<elem_type,derived>::snip_print(const std::string extra_text) const
|
||||
{
|
||||
arma_extra_debug_sigprint();
|
||||
|
||||
const quasi_unwrap<derived> tmp( (*this).get_ref() );
|
||||
|
||||
if(extra_text.length() != 0)
|
||||
{
|
||||
const std::streamsize orig_width = get_cout_stream().width();
|
||||
|
||||
get_cout_stream() << extra_text << '\n';
|
||||
|
||||
get_cout_stream().width(orig_width);
|
||||
}
|
||||
|
||||
arma_ostream::snip_print(get_cout_stream(), tmp.M);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename elem_type, typename derived>
|
||||
arma_cold
|
||||
inline
|
||||
void
|
||||
Base<elem_type,derived>::snip_print(std::ostream& user_stream, const std::string extra_text) const
|
||||
{
|
||||
arma_extra_debug_sigprint();
|
||||
|
||||
const quasi_unwrap<derived> tmp( (*this).get_ref() );
|
||||
|
||||
if(extra_text.length() != 0)
|
||||
{
|
||||
const std::streamsize orig_width = user_stream.width();
|
||||
|
||||
user_stream << extra_text << '\n';
|
||||
|
||||
user_stream.width(orig_width);
|
||||
}
|
||||
|
||||
arma_ostream::snip_print(user_stream, tmp.M);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename elem_type, typename derived>
|
||||
inline
|
||||
arma_warn_unused
|
||||
|
||||
@@ -61,13 +61,14 @@ class arma_ostream
|
||||
|
||||
template<typename oT> arma_cold inline static void print(std::ostream& o, const field<oT>& m);
|
||||
template<typename oT> arma_cold inline static void print(std::ostream& o, const subview_field<oT>& m);
|
||||
|
||||
|
||||
|
||||
template<typename eT> arma_cold inline static void print_dense(std::ostream& o, const SpMat<eT>& m, const bool modify);
|
||||
template<typename eT> arma_cold inline static void print(std::ostream& o, const SpMat<eT>& m, const bool modify);
|
||||
|
||||
arma_cold inline static void print(std::ostream& o, const SizeMat& S);
|
||||
arma_cold inline static void print(std::ostream& o, const SizeCube& S);
|
||||
|
||||
template<typename eT> arma_cold inline static void snip_print(std::ostream& o, const Mat<eT>& m);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -875,4 +875,146 @@ arma_ostream::print(std::ostream& o, const SizeCube& S)
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
arma_cold
|
||||
inline
|
||||
void
|
||||
arma_ostream::snip_print(std::ostream& o, const Mat<eT>& m)
|
||||
{
|
||||
arma_extra_debug_sigprint();
|
||||
|
||||
const arma_ostream_state stream_state(o);
|
||||
|
||||
if((m.n_elem == 0) || ((m.n_rows <= 5) && (m.n_cols <= 5))) { arma_ostream::print(o, m, true); return; }
|
||||
|
||||
const bool print_row_ellipsis = (m.n_rows >= 6);
|
||||
const bool print_col_ellipsis = (m.n_cols >= 6);
|
||||
|
||||
|
||||
if( (print_row_ellipsis == true) && (print_col_ellipsis == true) )
|
||||
{
|
||||
Mat<eT> X(4,4);
|
||||
|
||||
X( span(0,2), span(0,2) ) = m( span(0,2), span(0,2) ); // top left submatrix
|
||||
X( 3, span(0,2) ) = m( m.n_rows-1, span(0,2) ); // truncated last row
|
||||
X( span(0,2), 3 ) = m( span(0,2), m.n_cols-1 ); // truncated last column
|
||||
X( 3, 3 ) = m( m.n_rows-1, m.n_cols-1 ); // bottom right element
|
||||
|
||||
const std::streamsize cell_width = arma_ostream::modify_stream(o, X.memptr(), X.n_elem);
|
||||
|
||||
for(uword row=0; row <= 2; ++row)
|
||||
{
|
||||
for(uword col=0; col <= 2; ++col)
|
||||
{
|
||||
o.width(cell_width);
|
||||
arma_ostream::print_elem(o, X.at(row,col), true);
|
||||
}
|
||||
|
||||
o.width(cell_width);
|
||||
o << "...";
|
||||
|
||||
o.width(cell_width);
|
||||
o << X.at(row,3) << '\n';
|
||||
}
|
||||
|
||||
for(uword col=0; col <= 4; ++col)
|
||||
{
|
||||
o.width(cell_width);
|
||||
o << ':';
|
||||
}
|
||||
|
||||
o.width(cell_width);
|
||||
o << '\n';
|
||||
|
||||
const uword row = 3;
|
||||
{
|
||||
for(uword col=0; col <= 2; ++col)
|
||||
{
|
||||
o.width(cell_width);
|
||||
arma_ostream::print_elem(o, X.at(row,col), true);
|
||||
}
|
||||
|
||||
o.width(cell_width);
|
||||
o << "...";
|
||||
|
||||
o.width(cell_width);
|
||||
o << X.at(row,3) << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( (print_row_ellipsis == true) && (print_col_ellipsis == false) )
|
||||
{
|
||||
Mat<eT> X(4, m.n_cols);
|
||||
|
||||
X( span(0,2), span::all ) = m( span(0,2), span::all ); // top
|
||||
X( 3, span::all ) = m( m.n_rows-1, span::all ); // bottom
|
||||
|
||||
const std::streamsize cell_width = arma_ostream::modify_stream(o, X.memptr(), X.n_elem);
|
||||
|
||||
for(uword row=0; row <= 2; ++row) // first 3 rows
|
||||
{
|
||||
for(uword col=0; col < m.n_cols; ++col)
|
||||
{
|
||||
o.width(cell_width);
|
||||
arma_ostream::print_elem(o, X.at(row,col), true);
|
||||
}
|
||||
|
||||
o << '\n';
|
||||
}
|
||||
|
||||
for(uword col=0; col < m.n_cols; ++col)
|
||||
{
|
||||
o.width(cell_width);
|
||||
o << ':';
|
||||
}
|
||||
|
||||
o.width(cell_width);
|
||||
o << '\n';
|
||||
|
||||
const uword row = 3;
|
||||
{
|
||||
for(uword col=0; col < m.n_cols; ++col)
|
||||
{
|
||||
o.width(cell_width);
|
||||
arma_ostream::print_elem(o, X.at(row,col), true);
|
||||
}
|
||||
}
|
||||
|
||||
o << '\n';
|
||||
}
|
||||
|
||||
|
||||
if( (print_row_ellipsis == false) && (print_col_ellipsis == true) )
|
||||
{
|
||||
Mat<eT> X(m.n_rows, 4);
|
||||
|
||||
X( span::all, span(0,2) ) = m( span::all, span(0,2) ); // left
|
||||
X( span::all, 3 ) = m( span::all, m.n_cols-1 ); // right
|
||||
|
||||
const std::streamsize cell_width = arma_ostream::modify_stream(o, X.memptr(), X.n_elem);
|
||||
|
||||
for(uword row=0; row < m.n_rows; ++row)
|
||||
{
|
||||
for(uword col=0; col <= 2; ++col)
|
||||
{
|
||||
o.width(cell_width);
|
||||
arma_ostream::print_elem(o, X.at(row,col), true);
|
||||
}
|
||||
|
||||
o.width(cell_width);
|
||||
o << "...";
|
||||
|
||||
o.width(cell_width);
|
||||
o << X.at(row,3) << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
o.flush();
|
||||
stream_state.restore(o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
Reference in New Issue
Block a user