12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355 |
- // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
- // Copyright 2008-2016 National ICT Australia (NICTA)
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // ------------------------------------------------------------------------
- //! \addtogroup debug
- //! @{
- template<typename T>
- inline
- std::ostream&
- arma_cout_stream(std::ostream* user_stream)
- {
- static std::ostream* cout_stream = &(ARMA_COUT_STREAM);
-
- if(user_stream != NULL) { cout_stream = user_stream; }
-
- return (*cout_stream);
- }
- template<typename T>
- inline
- std::ostream&
- arma_cerr_stream(std::ostream* user_stream)
- {
- static std::ostream* cerr_stream = &(ARMA_CERR_STREAM);
-
- if(user_stream != NULL) { cerr_stream = user_stream; }
-
- return (*cerr_stream);
- }
- inline
- void
- set_cout_stream(std::ostream& user_stream)
- {
- arma_cout_stream<char>(&user_stream);
- }
- inline
- void
- set_cerr_stream(std::ostream& user_stream)
- {
- arma_cerr_stream<char>(&user_stream);
- }
- inline
- std::ostream&
- get_cout_stream()
- {
- return arma_cout_stream<char>(NULL);
- }
- inline
- std::ostream&
- get_cerr_stream()
- {
- return arma_cerr_stream<char>(NULL);
- }
- //! do not use this function - it's deprecated and will be removed
- inline
- arma_deprecated
- void
- set_stream_err1(std::ostream& user_stream)
- {
- set_cerr_stream(user_stream);
- }
- //! do not use this function - it's deprecated and will be removed
- inline
- arma_deprecated
- void
- set_stream_err2(std::ostream& user_stream)
- {
- set_cerr_stream(user_stream);
- }
- //! do not use this function - it's deprecated and will be removed
- inline
- arma_deprecated
- std::ostream&
- get_stream_err1()
- {
- return get_cerr_stream();
- }
- //! do not use this function - it's deprecated and will be removed
- inline
- arma_deprecated
- std::ostream&
- get_stream_err2()
- {
- return get_cerr_stream();
- }
- //! print a message to get_cerr_stream() and throw logic_error exception
- template<typename T1>
- arma_cold
- arma_noinline
- static
- void
- arma_stop_logic_error(const T1& x)
- {
- #if defined(ARMA_PRINT_ERRORS)
- {
- get_cerr_stream() << "\nerror: " << x << std::endl;
- }
- #endif
-
- throw std::logic_error( std::string(x) );
- }
- //! print a message to get_cerr_stream() and throw bad_alloc exception
- template<typename T1>
- arma_cold
- arma_noinline
- static
- void
- arma_stop_bad_alloc(const T1& x)
- {
- #if defined(ARMA_PRINT_ERRORS)
- {
- get_cerr_stream() << "\nerror: " << x << std::endl;
- }
- #else
- {
- arma_ignore(x);
- }
- #endif
-
- throw std::bad_alloc();
- }
- //! print a message to get_cerr_stream() and throw runtime_error exception
- template<typename T1>
- arma_cold
- arma_noinline
- static
- void
- arma_stop_runtime_error(const T1& x)
- {
- #if defined(ARMA_PRINT_ERRORS)
- {
- get_cerr_stream() << "\nerror: " << x << std::endl;
- }
- #endif
-
- throw std::runtime_error( std::string(x) );
- }
- //
- // arma_print
- arma_cold
- inline
- void
- arma_print()
- {
- get_cerr_stream() << std::endl;
- }
- template<typename T1>
- arma_cold
- arma_noinline
- static
- void
- arma_print(const T1& x)
- {
- get_cerr_stream() << x << std::endl;
- }
- template<typename T1, typename T2>
- arma_cold
- arma_noinline
- static
- void
- arma_print(const T1& x, const T2& y)
- {
- get_cerr_stream() << x << y << std::endl;
- }
- template<typename T1, typename T2, typename T3>
- arma_cold
- arma_noinline
- static
- void
- arma_print(const T1& x, const T2& y, const T3& z)
- {
- get_cerr_stream() << x << y << z << std::endl;
- }
- //
- // arma_sigprint
- //! print a message the the log stream with a preceding @ character.
- //! by default the log stream is cout.
- //! used for printing the signature of a function
- //! (see the arma_extra_debug_sigprint macro)
- inline
- void
- arma_sigprint(const char* x)
- {
- get_cerr_stream() << "@ " << x;
- }
- //
- // arma_bktprint
- inline
- void
- arma_bktprint()
- {
- get_cerr_stream() << std::endl;
- }
- template<typename T1>
- inline
- void
- arma_bktprint(const T1& x)
- {
- get_cerr_stream() << " [" << x << ']' << std::endl;
- }
- template<typename T1, typename T2>
- inline
- void
- arma_bktprint(const T1& x, const T2& y)
- {
- get_cerr_stream() << " [" << x << y << ']' << std::endl;
- }
- //
- // arma_thisprint
- inline
- void
- arma_thisprint(const void* this_ptr)
- {
- get_cerr_stream() << " [this = " << this_ptr << ']' << std::endl;
- }
- //
- // arma_warn
- //! print a message to the warn stream
- template<typename T1>
- arma_cold
- arma_noinline
- static
- void
- arma_warn(const T1& x)
- {
- #if defined(ARMA_PRINT_ERRORS)
- {
- get_cerr_stream() << "\nwarning: " << x << '\n';
- }
- #else
- {
- arma_ignore(x);
- }
- #endif
- }
- template<typename T1, typename T2>
- arma_cold
- arma_noinline
- static
- void
- arma_warn(const T1& x, const T2& y)
- {
- #if defined(ARMA_PRINT_ERRORS)
- {
- get_cerr_stream() << "\nwarning: " << x << y << '\n';
- }
- #else
- {
- arma_ignore(x);
- arma_ignore(y);
- }
- #endif
- }
- template<typename T1, typename T2, typename T3>
- arma_cold
- arma_noinline
- static
- void
- arma_warn(const T1& x, const T2& y, const T3& z)
- {
- #if defined(ARMA_PRINT_ERRORS)
- {
- get_cerr_stream() << "\nwarning: " << x << y << z << '\n';
- }
- #else
- {
- arma_ignore(x);
- arma_ignore(y);
- arma_ignore(z);
- }
- #endif
- }
- //
- // arma_check
- //! if state is true, abort program
- template<typename T1>
- arma_hot
- inline
- void
- arma_check(const bool state, const T1& x)
- {
- if(state) { arma_stop_logic_error(arma_str::str_wrapper(x)); }
- }
- template<typename T1, typename T2>
- arma_hot
- inline
- void
- arma_check(const bool state, const T1& x, const T2& y)
- {
- if(state) { arma_stop_logic_error( std::string(x) + std::string(y) ); }
- }
- template<typename T1>
- arma_hot
- inline
- void
- arma_check_bad_alloc(const bool state, const T1& x)
- {
- if(state) { arma_stop_bad_alloc(x); }
- }
- //
- // arma_set_error
- arma_hot
- arma_inline
- void
- arma_set_error(bool& err_state, char*& err_msg, const bool expression, const char* message)
- {
- if(expression)
- {
- err_state = true;
- err_msg = const_cast<char*>(message);
- }
- }
- //
- // functions for generating strings indicating size errors
- arma_cold
- arma_noinline
- static
- std::string
- 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)
- {
- std::ostringstream tmp;
-
- tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_n_cols << " and " << B_n_rows << 'x' << B_n_cols;
-
- return tmp.str();
- }
- arma_cold
- arma_noinline
- static
- std::string
- 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)
- {
- std::ostringstream tmp;
-
- 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;
-
- return tmp.str();
- }
- template<typename eT>
- arma_cold
- arma_noinline
- static
- std::string
- arma_incompat_size_string(const subview_cube<eT>& Q, const Mat<eT>& A, const char* x)
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": interpreting matrix as cube with dimensions: "
- << A.n_rows << 'x' << A.n_cols << 'x' << 1
- << " or "
- << A.n_rows << 'x' << 1 << 'x' << A.n_cols
- << " or "
- << 1 << 'x' << A.n_rows << 'x' << A.n_cols
- << " is incompatible with cube dimensions: "
- << Q.n_rows << 'x' << Q.n_cols << 'x' << Q.n_slices;
-
- return tmp.str();
- }
- //
- // functions for checking whether two dense matrices have the same dimensions
- arma_inline
- arma_hot
- void
- 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)
- {
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- //! stop if given matrices have different sizes
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.n_rows;
- const uword A_n_cols = A.n_cols;
-
- const uword B_n_rows = B.n_rows;
- const uword B_n_cols = B.n_cols;
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- //! stop if given proxies have different sizes
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.get_n_rows();
- const uword A_n_cols = A.get_n_cols();
-
- const uword B_n_rows = B.get_n_rows();
- const uword B_n_cols = B.get_n_cols();
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.n_rows;
- const uword A_n_cols = A.n_cols;
-
- const uword B_n_rows = B.n_rows;
- const uword B_n_cols = B.n_cols;
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.n_rows;
- const uword A_n_cols = A.n_cols;
-
- const uword B_n_rows = B.n_rows;
- const uword B_n_cols = B.n_cols;
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.n_rows;
- const uword A_n_cols = A.n_cols;
-
- const uword B_n_rows = B.n_rows;
- const uword B_n_cols = B.n_cols;
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.n_rows;
- const uword A_n_cols = A.n_cols;
-
- const uword B_n_rows = B.get_n_rows();
- const uword B_n_cols = B.get_n_cols();
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.get_n_rows();
- const uword A_n_cols = A.get_n_cols();
-
- const uword B_n_rows = B.n_rows;
- const uword B_n_cols = B.n_cols;
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.get_n_rows();
- const uword A_n_cols = A.get_n_cols();
-
- const uword B_n_rows = B.n_rows;
- const uword B_n_cols = B.n_cols;
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.n_rows;
- const uword A_n_cols = A.n_cols;
-
- const uword B_n_rows = B.get_n_rows();
- const uword B_n_cols = B.get_n_cols();
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- //
- // functions for checking whether two sparse matrices have the same dimensions
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const SpMat<eT1>& A, const SpMat<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.n_rows;
- const uword A_n_cols = A.n_cols;
-
- const uword B_n_rows = B.n_rows;
- const uword B_n_cols = B.n_cols;
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- //
- // functions for checking whether two cubes have the same dimensions
- arma_hot
- inline
- void
- 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)
- {
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) );
- }
- }
- //! stop if given cubes have different sizes
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x)
- {
- if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const char* x)
- {
- if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const char* x)
- {
- if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const subview_cube<eT1>& A, const subview_cube<eT2>& B, const char* x)
- {
- if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices))
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) );
- }
- }
- //! stop if given cube proxies have different sizes
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, const char* x)
- {
- const uword A_n_rows = A.get_n_rows();
- const uword A_n_cols = A.get_n_cols();
- const uword A_n_slices = A.get_n_slices();
-
- const uword B_n_rows = B.get_n_rows();
- const uword B_n_cols = B.get_n_cols();
- const uword B_n_slices = B.get_n_slices();
-
- if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices))
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) );
- }
- }
- //
- // functions for checking whether a cube or subcube can be interpreted as a matrix (i.e. single slice)
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x)
- {
- if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x)
- {
- if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const char* x)
- {
- if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const char* x)
- {
- if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) )
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) );
- }
- }
- template<typename eT, typename T1>
- inline
- void
- arma_assert_cube_as_mat(const Mat<eT>& M, const T1& Q, const char* x, const bool check_compat_size)
- {
- const uword Q_n_rows = Q.n_rows;
- const uword Q_n_cols = Q.n_cols;
- const uword Q_n_slices = Q.n_slices;
-
- const uword M_vec_state = M.vec_state;
-
- if(M_vec_state == 0)
- {
- if( ( (Q_n_rows == 1) || (Q_n_cols == 1) || (Q_n_slices == 1) ) == false )
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": can't interpret cube with dimensions "
- << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
- << " as a matrix; one of the dimensions must be 1";
-
- arma_stop_logic_error( tmp.str() );
- }
- }
- else
- {
- if(Q_n_slices == 1)
- {
- if( (M_vec_state == 1) && (Q_n_cols != 1) )
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": can't interpret cube with dimensions "
- << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
- << " as a column vector";
-
- arma_stop_logic_error( tmp.str() );
- }
-
- if( (M_vec_state == 2) && (Q_n_rows != 1) )
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": can't interpret cube with dimensions "
- << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
- << " as a row vector";
-
- arma_stop_logic_error( tmp.str() );
- }
- }
- else
- {
- if( (Q_n_cols != 1) && (Q_n_rows != 1) )
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": can't interpret cube with dimensions "
- << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
- << " as a vector";
-
- arma_stop_logic_error( tmp.str() );
- }
- }
- }
-
-
- if(check_compat_size)
- {
- const uword M_n_rows = M.n_rows;
- const uword M_n_cols = M.n_cols;
-
- if(M_vec_state == 0)
- {
- if(
- (
- ( (Q_n_rows == M_n_rows) && (Q_n_cols == M_n_cols) )
- ||
- ( (Q_n_rows == M_n_rows) && (Q_n_slices == M_n_cols) )
- ||
- ( (Q_n_cols == M_n_rows) && (Q_n_slices == M_n_cols) )
- )
- == false
- )
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": can't interpret cube with dimensions "
- << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
- << " as a matrix with dimensions "
- << M_n_rows << 'x' << M_n_cols;
-
- arma_stop_logic_error( tmp.str() );
- }
- }
- else
- {
- if(Q_n_slices == 1)
- {
- if( (M_vec_state == 1) && (Q_n_rows != M_n_rows) )
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": can't interpret cube with dimensions "
- << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
- << " as a column vector with dimensions "
- << M_n_rows << 'x' << M_n_cols;
-
- arma_stop_logic_error( tmp.str() );
- }
-
- if( (M_vec_state == 2) && (Q_n_cols != M_n_cols) )
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": can't interpret cube with dimensions "
- << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
- << " as a row vector with dimensions "
- << M_n_rows << 'x' << M_n_cols;
-
- arma_stop_logic_error( tmp.str() );
- }
- }
- else
- {
- if( ( (M_n_cols == Q_n_slices) || (M_n_rows == Q_n_slices) ) == false )
- {
- std::ostringstream tmp;
-
- tmp << x
- << ": can't interpret cube with dimensions "
- << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
- << " as a vector with dimensions "
- << M_n_rows << 'x' << M_n_cols;
-
- arma_stop_logic_error( tmp.str() );
- }
- }
- }
- }
- }
- //
- // functions for checking whether two matrices have dimensions that are compatible with the matrix multiply operation
- arma_hot
- inline
- void
- 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)
- {
- if(A_n_cols != B_n_rows)
- {
- arma_stop_logic_error( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
- }
- }
- //! stop if given matrices are incompatible for multiplication
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x)
- {
- const uword A_n_cols = A.n_cols;
- const uword B_n_rows = B.n_rows;
-
- if(A_n_cols != B_n_rows)
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_cols, x) );
- }
- }
- //! stop if given matrices are incompatible for multiplication
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const bool do_trans_A, const bool do_trans_B, const char* x)
- {
- const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows;
- const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols;
-
- if(final_A_n_cols != final_B_n_rows)
- {
- const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols;
- const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows;
-
- arma_stop_logic_error( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) );
- }
- }
- template<const bool do_trans_A, const bool do_trans_B>
- arma_hot
- inline
- void
- arma_assert_trans_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)
- {
- const uword final_A_n_cols = (do_trans_A == false) ? A_n_cols : A_n_rows;
- const uword final_B_n_rows = (do_trans_B == false) ? B_n_rows : B_n_cols;
-
- if(final_A_n_cols != final_B_n_rows)
- {
- const uword final_A_n_rows = (do_trans_A == false) ? A_n_rows : A_n_cols;
- const uword final_B_n_cols = (do_trans_B == false) ? B_n_cols : B_n_rows;
-
- arma_stop_logic_error( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_mul_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x)
- {
- if(A.n_cols != B.n_rows)
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_mul_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x)
- {
- if(A.n_cols != B.n_rows)
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
- }
- }
- template<typename eT1, typename eT2>
- arma_hot
- inline
- void
- arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const char* x)
- {
- if(A.n_cols != B.n_rows)
- {
- arma_stop_logic_error( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
- }
- }
- template<typename T1>
- arma_hot
- inline
- void
- arma_assert_blas_size(const T1& A)
- {
- if(sizeof(uword) >= sizeof(blas_int))
- {
- bool overflow;
-
- overflow = (A.n_rows > ARMA_MAX_BLAS_INT);
- overflow = (A.n_cols > ARMA_MAX_BLAS_INT) || overflow;
-
- if(overflow)
- {
- arma_stop_runtime_error("integer overflow: matrix dimensions are too large for integer type used by BLAS and LAPACK");
- }
- }
- }
- template<typename T1, typename T2>
- arma_hot
- inline
- void
- arma_assert_blas_size(const T1& A, const T2& B)
- {
- if(sizeof(uword) >= sizeof(blas_int))
- {
- bool overflow;
-
- overflow = (A.n_rows > ARMA_MAX_BLAS_INT);
- overflow = (A.n_cols > ARMA_MAX_BLAS_INT) || overflow;
- overflow = (B.n_rows > ARMA_MAX_BLAS_INT) || overflow;
- overflow = (B.n_cols > ARMA_MAX_BLAS_INT) || overflow;
-
- if(overflow)
- {
- arma_stop_runtime_error("integer overflow: matrix dimensions are too large for integer type used by BLAS and LAPACK");
- }
- }
- }
- template<typename T1>
- arma_hot
- inline
- void
- arma_assert_atlas_size(const T1& A)
- {
- if(sizeof(uword) >= sizeof(int))
- {
- bool overflow;
-
- overflow = (A.n_rows > INT_MAX);
- overflow = (A.n_cols > INT_MAX) || overflow;
-
- if(overflow)
- {
- arma_stop_runtime_error("integer overflow: matrix dimensions are too large for integer type used by ATLAS");
- }
- }
- }
- template<typename T1, typename T2>
- arma_hot
- inline
- void
- arma_assert_atlas_size(const T1& A, const T2& B)
- {
- if(sizeof(uword) >= sizeof(int))
- {
- bool overflow;
-
- overflow = (A.n_rows > INT_MAX);
- overflow = (A.n_cols > INT_MAX) || overflow;
- overflow = (B.n_rows > INT_MAX) || overflow;
- overflow = (B.n_cols > INT_MAX) || overflow;
-
- if(overflow)
- {
- arma_stop_runtime_error("integer overflow: matrix dimensions are too large for integer type used by ATLAS");
- }
- }
- }
- //
- // macros
- // #define ARMA_STRING1(x) #x
- // #define ARMA_STRING2(x) ARMA_STRING1(x)
- // #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__)
- #if defined(ARMA_NO_DEBUG)
-
- #undef ARMA_EXTRA_DEBUG
-
- #define arma_debug_print true ? (void)0 : arma_print
- #define arma_debug_warn true ? (void)0 : arma_warn
- #define arma_debug_check true ? (void)0 : arma_check
- #define arma_debug_set_error true ? (void)0 : arma_set_error
- #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_size
- #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_size
- #define arma_debug_assert_trans_mul_size true ? (void)0 : arma_assert_trans_mul_size
- #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_assert_cube_as_mat
- #define arma_debug_assert_blas_size true ? (void)0 : arma_assert_blas_size
- #define arma_debug_assert_atlas_size true ? (void)0 : arma_assert_atlas_size
-
- #else
-
- #define arma_debug_print arma_print
- #define arma_debug_warn arma_warn
- #define arma_debug_check arma_check
- #define arma_debug_set_error arma_set_error
- #define arma_debug_assert_same_size arma_assert_same_size
- #define arma_debug_assert_mul_size arma_assert_mul_size
- #define arma_debug_assert_trans_mul_size arma_assert_trans_mul_size
- #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat
- #define arma_debug_assert_blas_size arma_assert_blas_size
- #define arma_debug_assert_atlas_size arma_assert_atlas_size
-
- #endif
- #if defined(ARMA_EXTRA_DEBUG)
-
- #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_bktprint
- #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_thisprint
- #define arma_extra_debug_print arma_print
- #define arma_extra_debug_warn arma_warn
- #define arma_extra_debug_check arma_check
- #else
-
- #define arma_extra_debug_sigprint true ? (void)0 : arma_bktprint
- #define arma_extra_debug_sigprint_this true ? (void)0 : arma_thisprint
- #define arma_extra_debug_print true ? (void)0 : arma_print
- #define arma_extra_debug_warn true ? (void)0 : arma_warn
- #define arma_extra_debug_check true ? (void)0 : arma_check
-
- #endif
- #if defined(ARMA_EXTRA_DEBUG)
- namespace junk
- {
- class arma_first_extra_debug_message
- {
- public:
-
- inline
- arma_first_extra_debug_message()
- {
- union
- {
- unsigned short a;
- unsigned char b[sizeof(unsigned short)];
- } endian_test;
-
- endian_test.a = 1;
-
- const bool little_endian = (endian_test.b[0] == 1);
- const char* nickname = ARMA_VERSION_NAME;
-
- std::ostream& out = get_cerr_stream();
-
- out << "@ ---" << '\n';
- out << "@ Armadillo "
- << arma_version::major << '.' << arma_version::minor << '.' << arma_version::patch
- << " (" << nickname << ")\n";
-
- out << "@ arma_config::wrapper = " << arma_config::wrapper << '\n';
- out << "@ arma_config::cxx11 = " << arma_config::cxx11 << '\n';
- out << "@ arma_config::cxx11_mutex = " << arma_config::cxx11_mutex << '\n';
- out << "@ arma_config::posix = " << arma_config::posix << '\n';
- out << "@ arma_config::openmp = " << arma_config::openmp << '\n';
- out << "@ arma_config::lapack = " << arma_config::lapack << '\n';
- out << "@ arma_config::blas = " << arma_config::blas << '\n';
- out << "@ arma_config::newarp = " << arma_config::newarp << '\n';
- out << "@ arma_config::arpack = " << arma_config::arpack << '\n';
- out << "@ arma_config::superlu = " << arma_config::superlu << '\n';
- out << "@ arma_config::atlas = " << arma_config::atlas << '\n';
- out << "@ arma_config::hdf5 = " << arma_config::hdf5 << '\n';
- out << "@ arma_config::good_comp = " << arma_config::good_comp << '\n';
- out << "@ arma_config::extra_code = " << arma_config::extra_code << '\n';
- out << "@ arma_config::hidden_args = " << arma_config::hidden_args << '\n';
- out << "@ arma_config::mat_prealloc = " << arma_config::mat_prealloc << '\n';
- out << "@ arma_config::mp_threshold = " << arma_config::mp_threshold << '\n';
- out << "@ arma_config::mp_threads = " << arma_config::mp_threads << '\n';
- out << "@ sizeof(void*) = " << sizeof(void*) << '\n';
- out << "@ sizeof(int) = " << sizeof(int) << '\n';
- out << "@ sizeof(long) = " << sizeof(long) << '\n';
- out << "@ sizeof(uword) = " << sizeof(uword) << '\n';
- out << "@ sizeof(blas_int) = " << sizeof(blas_int) << '\n';
- out << "@ little_endian = " << little_endian << '\n';
- out << "@ ---" << std::endl;
- }
-
- };
-
- static arma_first_extra_debug_message arma_first_extra_debug_message_run;
- }
- #endif
- //! @}
|