diff --git a/include/armadillo_bits/Base_bones.hpp b/include/armadillo_bits/Base_bones.hpp index c0cee4bf..63aa6d0f 100644 --- a/include/armadillo_bits/Base_bones.hpp +++ b/include/armadillo_bits/Base_bones.hpp @@ -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; diff --git a/include/armadillo_bits/Base_meat.hpp b/include/armadillo_bits/Base_meat.hpp index 1cabf429..3011e6d9 100644 --- a/include/armadillo_bits/Base_meat.hpp +++ b/include/armadillo_bits/Base_meat.hpp @@ -125,6 +125,54 @@ Base::raw_print(std::ostream& user_stream, const std::string +template +arma_cold +inline +void +Base::snip_print(const std::string extra_text) const + { + arma_extra_debug_sigprint(); + + const quasi_unwrap 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 +arma_cold +inline +void +Base::snip_print(std::ostream& user_stream, const std::string extra_text) const + { + arma_extra_debug_sigprint(); + + const quasi_unwrap 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 inline arma_warn_unused diff --git a/include/armadillo_bits/arma_ostream_bones.hpp b/include/armadillo_bits/arma_ostream_bones.hpp index 4e9ceeec..c45254e9 100644 --- a/include/armadillo_bits/arma_ostream_bones.hpp +++ b/include/armadillo_bits/arma_ostream_bones.hpp @@ -61,13 +61,14 @@ class arma_ostream template arma_cold inline static void print(std::ostream& o, const field& m); template arma_cold inline static void print(std::ostream& o, const subview_field& m); - - + template arma_cold inline static void print_dense(std::ostream& o, const SpMat& m, const bool modify); template arma_cold inline static void print(std::ostream& o, const SpMat& 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 arma_cold inline static void snip_print(std::ostream& o, const Mat& m); }; diff --git a/include/armadillo_bits/arma_ostream_meat.hpp b/include/armadillo_bits/arma_ostream_meat.hpp index a66798c9..1b0ea7c9 100644 --- a/include/armadillo_bits/arma_ostream_meat.hpp +++ b/include/armadillo_bits/arma_ostream_meat.hpp @@ -875,4 +875,146 @@ arma_ostream::print(std::ostream& o, const SizeCube& S) +template +arma_cold +inline +void +arma_ostream::snip_print(std::ostream& o, const Mat& 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 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 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 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); + } + + + //! @}