max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // Copyright (C) 2011 Stanislav Funiak max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup debug max@0: //! @{ max@0: max@0: max@0: max@0: template max@0: inline max@0: std::ostream& max@0: arma_stream_err1(std::ostream* user_stream) max@0: { max@0: static std::ostream* stream_err1 = &(ARMA_DEFAULT_OSTREAM); max@0: max@0: if(user_stream != NULL) max@0: { max@0: stream_err1 = user_stream; max@0: } max@0: max@0: return *stream_err1; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: std::ostream& max@0: arma_stream_err2(std::ostream* user_stream) max@0: { max@0: static std::ostream* stream_err2 = &(ARMA_DEFAULT_OSTREAM); max@0: max@0: if(user_stream != NULL) max@0: { max@0: stream_err2 = user_stream; max@0: } max@0: max@0: return *stream_err2; max@0: } max@0: max@0: max@0: max@0: inline max@0: void max@0: set_stream_err1(std::ostream& user_stream) max@0: { max@0: arma_stream_err1(&user_stream); max@0: } max@0: max@0: max@0: max@0: inline max@0: void max@0: set_stream_err2(std::ostream& user_stream) max@0: { max@0: arma_stream_err2(&user_stream); max@0: } max@0: max@0: max@0: max@0: inline max@0: std::ostream& max@0: get_stream_err1() max@0: { max@0: return arma_stream_err1(NULL); max@0: } max@0: max@0: max@0: max@0: inline max@0: std::ostream& max@0: get_stream_err2() max@0: { max@0: return arma_stream_err2(NULL); max@0: } max@0: max@0: max@0: max@0: // max@0: // arma_stop max@0: max@0: //! print a message to get_stream_err1() and/or throw a logic_error exception max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_stop(const T1& x) max@0: { max@0: #if defined(ARMA_PRINT_LOGIC_ERRORS) max@0: { max@0: std::ostream& out = get_stream_err1(); max@0: max@0: out.flush(); max@0: max@0: out << '\n'; max@0: out << "error: " << x << '\n'; max@0: out << '\n'; max@0: out.flush(); max@0: } max@0: #else max@0: { max@0: arma_ignore(x); max@0: } max@0: #endif max@0: max@0: throw std::logic_error(""); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_stop_bad_alloc(const T1& x) max@0: { max@0: std::ostream& out = get_stream_err1(); max@0: max@0: out.flush(); max@0: max@0: out << '\n'; max@0: out << "error: " << x << '\n'; max@0: out << '\n'; max@0: out.flush(); max@0: max@0: throw std::bad_alloc(); max@0: } max@0: max@0: max@0: max@0: // max@0: // arma_bad max@0: max@0: //! print a message to get_stream_err2() and/or throw a run-time error exception max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_bad(const T1& x, const bool hurl = true) max@0: { max@0: #if defined(ARMA_PRINT_RUNTIME_ERRORS) max@0: { max@0: std::ostream& out = get_stream_err2(); max@0: max@0: out.flush(); max@0: max@0: out << '\n'; max@0: out << "error: " << x << '\n'; max@0: out << '\n'; max@0: out.flush(); max@0: } max@0: #else max@0: { max@0: arma_ignore(x); max@0: } max@0: #endif max@0: max@0: if(hurl == true) max@0: { max@0: throw std::runtime_error(""); max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // arma_print max@0: max@0: max@0: inline max@0: void max@0: arma_cold max@0: arma_print() max@0: { max@0: get_stream_err1() << std::endl; max@0: } max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_print(const T1& x) max@0: { max@0: get_stream_err1() << x << std::endl; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_print(const T1& x, const T2& y) max@0: { max@0: get_stream_err1() << x << y << std::endl; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_print(const T1& x, const T2& y, const T3& z) max@0: { max@0: get_stream_err1() << x << y << z << std::endl; max@0: } max@0: max@0: max@0: max@0: max@0: max@0: max@0: // max@0: // arma_sigprint max@0: max@0: //! print a message the the log stream with a preceding @ character. max@0: //! by default the log stream is cout. max@0: //! used for printing the signature of a function max@0: //! (see the arma_extra_debug_sigprint macro) max@0: inline max@0: void max@0: arma_sigprint(const char* x) max@0: { max@0: get_stream_err1() << "@ " << x; max@0: } max@0: max@0: max@0: max@0: // max@0: // arma_bktprint max@0: max@0: max@0: inline max@0: void max@0: arma_bktprint() max@0: { max@0: get_stream_err1() << std::endl; max@0: } max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_bktprint(const T1& x) max@0: { max@0: get_stream_err1() << " [" << x << ']' << std::endl; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_bktprint(const T1& x, const T2& y) max@0: { max@0: get_stream_err1() << " [" << x << y << ']' << std::endl; max@0: } max@0: max@0: max@0: max@0: max@0: max@0: max@0: // max@0: // arma_thisprint max@0: max@0: inline max@0: void max@0: arma_thisprint(const void* this_ptr) max@0: { max@0: get_stream_err1() << " [this = " << this_ptr << ']' << std::endl; max@0: } max@0: max@0: max@0: max@0: // max@0: // arma_warn max@0: max@0: max@0: //! print a message to the warn stream max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_warn(const bool state, const T1& x) max@0: { max@0: if(state==true) max@0: { max@0: get_stream_err2() << x << std::endl; max@0: } max@0: } max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_warn(const bool state, const T1& x, const T2& y) max@0: { max@0: if(state==true) max@0: { max@0: get_stream_err2() << x << y << std::endl; max@0: } max@0: } max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_cold max@0: arma_warn(const bool state, const T1& x, const T2& y, const T3& z) max@0: { max@0: if(state==true) max@0: { max@0: get_stream_err2() << x << y << z << std::endl; max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // arma_check max@0: max@0: //! if state is true, abort program max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_check(const bool state, const T1& x) max@0: { max@0: if(state==true) max@0: { max@0: arma_stop(arma_boost::str_wrapper(x)); max@0: } max@0: } max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_check(const bool state, const T1& x, const T2& y) max@0: { max@0: if(state==true) max@0: { max@0: arma_stop( std::string(x) + std::string(y) ); max@0: } max@0: } max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_check_bad_alloc(const bool state, const T1& x) max@0: { max@0: if(state==true) max@0: { max@0: arma_stop_bad_alloc(x); max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // arma_set_error max@0: max@0: max@0: arma_inline max@0: void max@0: arma_hot max@0: arma_set_error(bool& err_state, char*& err_msg, const bool expression, const char* message) max@0: { max@0: if(expression == true) max@0: { max@0: err_state = true; max@0: err_msg = const_cast(message); max@0: } max@0: } max@0: max@0: max@0: max@0: max@0: // max@0: // functions for generating strings indicating size errors max@0: max@0: inline max@0: std::string max@0: arma_cold max@0: arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_n_cols << " and " << B_n_rows << 'x' << B_n_cols; max@0: max@0: return tmp.str(); max@0: } max@0: max@0: max@0: max@0: inline max@0: arma_cold max@0: std::string max@0: arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_slices, const char* x) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x << ": incompatible cube dimensions: " << A_n_rows << 'x' << A_n_cols << 'x' << A_n_slices << " and " << B_n_rows << 'x' << B_n_cols << 'x' << B_n_slices; max@0: max@0: return tmp.str(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_cold max@0: std::string max@0: arma_incompat_size_string(const subview_cube& Q, const Mat& A, const char* x) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": interpreting matrix as cube with dimenensions: " max@0: << A.n_rows << 'x' << A.n_cols << 'x' << 1 max@0: << " or " max@0: << A.n_rows << 'x' << 1 << 'x' << A.n_cols max@0: << " or " max@0: << 1 << 'x' << A.n_rows << 'x' << A.n_cols max@0: << " is incompatible with cube dimensions: " max@0: << Q.n_rows << 'x' << Q.n_cols << 'x' << Q.n_slices; max@0: max@0: return tmp.str(); max@0: } max@0: max@0: max@0: max@0: // max@0: // functions for checking whether two matrices have the same dimensions max@0: max@0: max@0: max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) max@0: { max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! stop if given matrices have different sizes max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Mat& A, const Mat& B, const char* x) max@0: { max@0: const uword A_n_rows = A.n_rows; max@0: const uword A_n_cols = A.n_cols; max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! stop if given proxies have different sizes max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Proxy& A, const Proxy& B, const char* x) max@0: { max@0: const uword A_n_rows = A.get_n_rows(); max@0: const uword A_n_cols = A.get_n_cols(); max@0: max@0: const uword B_n_rows = B.get_n_rows(); max@0: const uword B_n_cols = B.get_n_cols(); max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const subview& A, const subview& B, const char* x) max@0: { max@0: const uword A_n_rows = A.n_rows; max@0: const uword A_n_cols = A.n_cols; max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Mat& A, const subview& B, const char* x) max@0: { max@0: const uword A_n_rows = A.n_rows; max@0: const uword A_n_cols = A.n_cols; max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const subview& A, const Mat& B, const char* x) max@0: { max@0: const uword A_n_rows = A.n_rows; max@0: const uword A_n_cols = A.n_cols; max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Mat& A, const Proxy& B, const char* x) max@0: { max@0: const uword A_n_rows = A.n_rows; max@0: const uword A_n_cols = A.n_cols; max@0: max@0: const uword B_n_rows = B.get_n_rows(); max@0: const uword B_n_cols = B.get_n_cols(); max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Proxy& A, const Mat& B, const char* x) max@0: { max@0: const uword A_n_rows = A.get_n_rows(); max@0: const uword A_n_cols = A.get_n_cols(); max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Proxy& A, const subview& B, const char* x) max@0: { max@0: const uword A_n_rows = A.get_n_rows(); max@0: const uword A_n_cols = A.get_n_cols(); max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const subview& A, const Proxy& B, const char* x) max@0: { max@0: const uword A_n_rows = A.n_rows; max@0: const uword A_n_cols = A.n_cols; max@0: max@0: const uword B_n_rows = B.get_n_rows(); max@0: const uword B_n_cols = B.get_n_cols(); max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // functions for checking whether two cubes have the same dimensions max@0: max@0: max@0: max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_slices, const char* x) max@0: { max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! stop if given cubes have different sizes max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Cube& A, const Cube& B, const char* x) max@0: { max@0: if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Cube& A, const subview_cube& B, const char* x) max@0: { max@0: if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const subview_cube& A, const Cube& B, const char* x) max@0: { max@0: if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const subview_cube& A, const subview_cube& B, const char* x) max@0: { max@0: if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices)) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! stop if given cube proxies have different sizes max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const ProxyCube& A, const ProxyCube& B, const char* x) max@0: { max@0: const uword A_n_rows = A.get_n_rows(); max@0: const uword A_n_cols = A.get_n_cols(); max@0: const uword A_n_slices = A.get_n_slices(); max@0: max@0: const uword B_n_rows = B.get_n_rows(); max@0: const uword B_n_cols = B.get_n_cols(); max@0: const uword B_n_slices = B.get_n_slices(); max@0: max@0: if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices)) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // functions for checking whether a cube or subcube can be interpreted as a matrix (i.e. single slice) max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Cube& A, const Mat& B, const char* x) max@0: { max@0: if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Mat& A, const Cube& B, const char* x) max@0: { max@0: if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const subview_cube& A, const Mat& B, const char* x) max@0: { max@0: if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_same_size(const Mat& A, const subview_cube& B, const char* x) max@0: { max@0: if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_assert_cube_as_mat(const Mat& M, const T1& Q, const char* x, const bool check_compat_size) max@0: { max@0: const uword Q_n_rows = Q.n_rows; max@0: const uword Q_n_cols = Q.n_cols; max@0: const uword Q_n_slices = Q.n_slices; max@0: max@0: const uword M_vec_state = M.vec_state; max@0: max@0: if(M_vec_state == 0) max@0: { max@0: if( ( (Q_n_rows == 1) || (Q_n_cols == 1) || (Q_n_slices == 1) ) == false ) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": can't interpret cube with dimensions " max@0: << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices max@0: << " as a matrix; one of the dimensions must be 1"; max@0: max@0: arma_stop( tmp.str() ); max@0: } max@0: } max@0: else max@0: { max@0: if(Q_n_slices == 1) max@0: { max@0: if( (M_vec_state == 1) && (Q_n_cols != 1) ) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": can't interpret cube with dimensions " max@0: << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices max@0: << " as a column vector"; max@0: max@0: arma_stop( tmp.str() ); max@0: } max@0: max@0: if( (M_vec_state == 2) && (Q_n_rows != 1) ) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": can't interpret cube with dimensions " max@0: << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices max@0: << " as a row vector"; max@0: max@0: arma_stop( tmp.str() ); max@0: } max@0: } max@0: else max@0: { max@0: if( (Q_n_cols != 1) && (Q_n_rows != 1) ) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": can't interpret cube with dimensions " max@0: << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices max@0: << " as a vector"; max@0: max@0: arma_stop( tmp.str() ); max@0: } max@0: } max@0: } max@0: max@0: max@0: if(check_compat_size == true) max@0: { max@0: const uword M_n_rows = M.n_rows; max@0: const uword M_n_cols = M.n_cols; max@0: max@0: if(M_vec_state == 0) max@0: { max@0: if( max@0: ( max@0: ( (Q_n_rows == M_n_rows) && (Q_n_cols == M_n_cols) ) max@0: || max@0: ( (Q_n_rows == M_n_rows) && (Q_n_slices == M_n_cols) ) max@0: || max@0: ( (Q_n_cols == M_n_rows) && (Q_n_slices == M_n_cols) ) max@0: ) max@0: == false max@0: ) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": can't interpret cube with dimenensions " max@0: << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices max@0: << " as a matrix with dimensions " max@0: << M_n_rows << 'x' << M_n_cols; max@0: max@0: arma_stop( tmp.str() ); max@0: } max@0: } max@0: else max@0: { max@0: if(Q_n_slices == 1) max@0: { max@0: if( (M_vec_state == 1) && (Q_n_rows != M_n_rows) ) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": can't interpret cube with dimensions " max@0: << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices max@0: << " as a column vector with dimensions " max@0: << M_n_rows << 'x' << M_n_cols; max@0: max@0: arma_stop( tmp.str() ); max@0: } max@0: max@0: if( (M_vec_state == 2) && (Q_n_cols != M_n_cols) ) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": can't interpret cube with dimensions " max@0: << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices max@0: << " as a row vector with dimensions " max@0: << M_n_rows << 'x' << M_n_cols; max@0: max@0: arma_stop( tmp.str() ); max@0: } max@0: } max@0: else max@0: { max@0: if( ( (M_n_cols == Q_n_slices) || (M_n_rows == Q_n_slices) ) == false ) max@0: { max@0: std::stringstream tmp; max@0: max@0: tmp << x max@0: << ": can't interpret cube with dimensions " max@0: << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices max@0: << " as a vector with dimensions " max@0: << M_n_rows << 'x' << M_n_cols; max@0: max@0: arma_stop( tmp.str() ); max@0: } max@0: } max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // functions for checking whether two matrices have dimensions that are compatible with the matrix multiply operation max@0: max@0: max@0: max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_mul_size(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) max@0: { max@0: if(A_n_cols != B_n_rows) max@0: { max@0: arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! stop if given matrices are incompatible for multiplication max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_mul_size(const Mat& A, const Mat& B, const char* x) max@0: { max@0: const uword A_n_cols = A.n_cols; max@0: const uword B_n_rows = B.n_rows; max@0: max@0: if(A_n_cols != B_n_rows) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! stop if given matrices are incompatible for multiplication max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_mul_size(const Mat& A, const Mat& B, const bool do_trans_A, const bool do_trans_B, const char* x) max@0: { max@0: const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows; max@0: const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols; max@0: max@0: if(final_A_n_cols != final_B_n_rows) max@0: { max@0: const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols; max@0: const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows; max@0: max@0: arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_mul_size(const Mat& A, const subview& B, const char* x) max@0: { max@0: if(A.n_cols != B.n_rows) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_mul_size(const subview& A, const Mat& B, const char* x) max@0: { max@0: if(A.n_cols != B.n_rows) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: arma_hot max@0: arma_assert_mul_size(const subview& A, const subview& B, const char* x) max@0: { max@0: if(A.n_cols != B.n_rows) max@0: { max@0: arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // macros max@0: max@0: max@0: #define ARMA_STRING1(x) #x max@0: #define ARMA_STRING2(x) ARMA_STRING1(x) max@0: #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__) max@0: max@0: max@0: #if defined (__GNUG__) max@0: #define ARMA_FNSIG __PRETTY_FUNCTION__ max@0: #elif defined (_MSC_VER) max@0: #define ARMA_FNSIG __FUNCSIG__ max@0: #elif defined (ARMA_USE_BOOST) max@0: #define ARMA_FNSIG BOOST_CURRENT_FUNCTION max@0: #else max@0: #define ARMA_FNSIG "(unknown)" max@0: #endif max@0: max@0: max@0: max@0: #if !defined(ARMA_NO_DEBUG) && !defined(NDEBUG) max@0: max@0: #define arma_debug_print arma_print max@0: #define arma_debug_warn arma_warn max@0: #define arma_debug_check arma_check max@0: #define arma_debug_set_error arma_set_error max@0: #define arma_debug_assert_same_size arma_assert_same_size max@0: #define arma_debug_assert_mul_size arma_assert_mul_size max@0: #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat max@0: max@0: #else max@0: max@0: #undef ARMA_EXTRA_DEBUG max@0: max@0: #define arma_debug_print true ? (void)0 : arma_print max@0: #define arma_debug_warn true ? (void)0 : arma_warn max@0: #define arma_debug_check true ? (void)0 : arma_check max@0: #define arma_debug_set_error true ? (void)0 : arma_set_error max@0: #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_size max@0: #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_size max@0: #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_debug_assert_cube_as_mat max@0: max@0: #endif max@0: max@0: max@0: max@0: #if defined(ARMA_EXTRA_DEBUG) max@0: max@0: #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_bktprint max@0: #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_thisprint max@0: #define arma_extra_debug_print arma_print max@0: #define arma_extra_debug_warn arma_warn max@0: #define arma_extra_debug_check arma_check max@0: max@0: #else max@0: max@0: #define arma_extra_debug_sigprint true ? (void)0 : arma_bktprint max@0: #define arma_extra_debug_sigprint_this true ? (void)0 : arma_thisprint max@0: #define arma_extra_debug_print true ? (void)0 : arma_print max@0: #define arma_extra_debug_warn true ? (void)0 : arma_warn max@0: #define arma_extra_debug_check true ? (void)0 : arma_check max@0: max@0: #endif max@0: max@0: max@0: max@0: max@0: #if defined(ARMA_EXTRA_DEBUG) max@0: max@0: namespace junk max@0: { max@0: class arma_first_extra_debug_message max@0: { max@0: public: max@0: max@0: inline max@0: arma_cold max@0: arma_first_extra_debug_message() max@0: { max@0: union max@0: { max@0: unsigned short a; max@0: unsigned char b[sizeof(unsigned short)]; max@0: } endian_test; max@0: max@0: endian_test.a = 1; max@0: max@0: const bool little_endian = (endian_test.b[0] == 1); max@0: const char* nickname = ARMA_VERSION_NAME; max@0: max@0: std::ostream& out = get_stream_err1(); max@0: max@0: out << "@ ---" << '\n'; max@0: out << "@ Armadillo " max@0: << arma_version::major << '.' << arma_version::minor << '.' << arma_version::patch max@0: << " (" << nickname << ")\n"; max@0: max@0: out << "@ arma_config::mat_prealloc = " << arma_config::mat_prealloc << " element(s)\n"; max@0: out << "@ arma_config::atlas = " << arma_config::atlas << '\n'; max@0: out << "@ arma_config::lapack = " << arma_config::lapack << '\n'; max@0: out << "@ arma_config::blas = " << arma_config::blas << '\n'; max@0: out << "@ arma_config::boost = " << arma_config::boost << '\n'; max@0: out << "@ arma_config::boost_date = " << arma_config::boost_date << '\n'; max@0: out << "@ arma_config::good_comp = " << arma_config::good_comp << '\n'; max@0: out << "@ arma_config::extra_code = " << arma_config::extra_code << '\n'; max@0: out << "@ sizeof(void*) = " << sizeof(void*) << '\n'; max@0: out << "@ sizeof(uword) = " << sizeof(uword) << '\n'; max@0: out << "@ sizeof(int) = " << sizeof(int) << '\n'; max@0: out << "@ sizeof(long) = " << sizeof(long) << '\n'; max@0: out << "@ sizeof(blas_int) = " << sizeof(blas_int) << '\n'; max@0: out << "@ little_endian = " << little_endian << '\n'; max@0: out << "@ ---" << std::endl; max@0: } max@0: max@0: }; max@0: max@0: static arma_first_extra_debug_message arma_first_extra_debug_message_run; max@0: } max@0: max@0: #endif max@0: max@0: max@0: max@0: //! @}