print directly from Base

This commit is contained in:
conrad
2020-12-17 14:30:22 +10:00
parent cae62f3324
commit 28e7077452
3 changed files with 48 additions and 115 deletions
+48 -4
View File
@@ -35,9 +35,20 @@ inline
void
Base<elem_type,derived>::print(const std::string extra_text) const
{
arma_extra_debug_sigprint();
const quasi_unwrap<derived> tmp( (*this).get_ref() );
tmp.M.impl_print(extra_text);
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::print(get_cout_stream(), tmp.M, true);
}
@@ -48,9 +59,20 @@ inline
void
Base<elem_type,derived>::print(std::ostream& user_stream, const std::string extra_text) const
{
arma_extra_debug_sigprint();
const quasi_unwrap<derived> tmp( (*this).get_ref() );
tmp.M.impl_print(user_stream, extra_text);
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::print(user_stream, tmp.M, true);
}
@@ -61,9 +83,20 @@ inline
void
Base<elem_type,derived>::raw_print(const std::string extra_text) const
{
arma_extra_debug_sigprint();
const quasi_unwrap<derived> tmp( (*this).get_ref() );
tmp.M.impl_raw_print(extra_text);
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::print(get_cout_stream(), tmp.M, false);
}
@@ -74,9 +107,20 @@ inline
void
Base<elem_type,derived>::raw_print(std::ostream& user_stream, const std::string extra_text) const
{
arma_extra_debug_sigprint();
const quasi_unwrap<derived> tmp( (*this).get_ref() );
tmp.M.impl_raw_print(user_stream, extra_text);
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::print(user_stream, tmp.M, false);
}
-7
View File
@@ -436,13 +436,6 @@ class Mat : public Base< eT, Mat<eT> >
arma_inline arma_warn_unused const eT* memptr() const;
arma_cold inline void impl_print( const std::string& extra_text) const;
arma_cold inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const;
arma_cold inline void impl_raw_print( const std::string& extra_text) const;
arma_cold inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const;
template<typename eT2, typename expr>
inline void copy_size(const Base<eT2,expr>& X);
-104
View File
@@ -6468,110 +6468,6 @@ Mat<eT>::memptr() const
//! print contents of the matrix (to the cout stream),
//! optionally preceding with a user specified line of text.
//! the precision and cell width are modified.
//! on return, the stream's state are restored to their original values.
template<typename eT>
arma_cold
inline
void
Mat<eT>::impl_print(const std::string& extra_text) const
{
arma_extra_debug_sigprint();
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::print(get_cout_stream(), *this, true);
}
//! print contents of the matrix to a user specified stream,
//! optionally preceding with a user specified line of text.
//! the precision and cell width are modified.
//! on return, the stream's state are restored to their original values.
template<typename eT>
arma_cold
inline
void
Mat<eT>::impl_print(std::ostream& user_stream, const std::string& extra_text) const
{
arma_extra_debug_sigprint();
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::print(user_stream, *this, true);
}
//! print contents of the matrix (to the cout stream),
//! optionally preceding with a user specified line of text.
//! the stream's state are used as is and are not modified
//! (i.e. the precision and cell width are not modified).
template<typename eT>
arma_cold
inline
void
Mat<eT>::impl_raw_print(const std::string& extra_text) const
{
arma_extra_debug_sigprint();
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::print(get_cout_stream(), *this, false);
}
//! print contents of the matrix to a user specified stream,
//! optionally preceding with a user specified line of text.
//! the stream's state are used as is and are not modified.
//! (i.e. the precision and cell width are not modified).
template<typename eT>
arma_cold
inline
void
Mat<eT>::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const
{
arma_extra_debug_sigprint();
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::print(user_stream, *this, false);
}
//! change the matrix to have user specified dimensions (data is not preserved)
template<typename eT>
inline