$search
00001 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2008-2011 Conrad Sanderson 00003 // Copyright (C) 2011 Stanislav Funiak 00004 // 00005 // This file is part of the Armadillo C++ library. 00006 // It is provided without any warranty of fitness 00007 // for any purpose. You can redistribute this file 00008 // and/or modify it under the terms of the GNU 00009 // Lesser General Public License (LGPL) as published 00010 // by the Free Software Foundation, either version 3 00011 // of the License or (at your option) any later version. 00012 // (see http://www.opensource.org/licenses for more info) 00013 00014 00017 00018 00019 00020 template<typename T> 00021 inline 00022 std::ostream& 00023 arma_stream_err1(std::ostream* user_stream) 00024 { 00025 static std::ostream* stream_err1 = &(std::cout); 00026 00027 if(user_stream != NULL) 00028 { 00029 stream_err1 = user_stream; 00030 } 00031 00032 return *stream_err1; 00033 } 00034 00035 00036 00037 template<typename T> 00038 inline 00039 std::ostream& 00040 arma_stream_err2(std::ostream* user_stream) 00041 { 00042 static std::ostream* stream_err2 = &(std::cout); 00043 00044 if(user_stream != NULL) 00045 { 00046 stream_err2 = user_stream; 00047 } 00048 00049 return *stream_err2; 00050 } 00051 00052 00053 00054 inline 00055 void 00056 set_stream_err1(std::ostream& user_stream) 00057 { 00058 arma_stream_err1<char>(&user_stream); 00059 } 00060 00061 00062 00063 inline 00064 void 00065 set_stream_err2(std::ostream& user_stream) 00066 { 00067 arma_stream_err2<char>(&user_stream); 00068 } 00069 00070 00071 00072 inline 00073 std::ostream& 00074 get_stream_err1() 00075 { 00076 return arma_stream_err1<char>(NULL); 00077 } 00078 00079 00080 00081 inline 00082 std::ostream& 00083 get_stream_err2() 00084 { 00085 return arma_stream_err2<char>(NULL); 00086 } 00087 00088 00089 00090 // 00091 // arma_stop 00092 00094 template<typename T1> 00095 inline 00096 void 00097 arma_cold 00098 arma_stop(const T1& x) 00099 { 00100 #if defined(ARMA_PRINT_LOGIC_ERRORS) 00101 { 00102 std::ostream& out = get_stream_err1(); 00103 00104 out.flush(); 00105 00106 out << '\n'; 00107 out << "error: " << x << '\n'; 00108 out << '\n'; 00109 out.flush(); 00110 } 00111 #else 00112 { 00113 arma_ignore(x); 00114 } 00115 #endif 00116 00117 throw std::logic_error(""); 00118 } 00119 00120 00121 00122 template<typename T1> 00123 inline 00124 void 00125 arma_cold 00126 arma_stop_bad_alloc(const T1& x) 00127 { 00128 std::ostream& out = get_stream_err1(); 00129 00130 out.flush(); 00131 00132 out << '\n'; 00133 out << "error: " << x << '\n'; 00134 out << '\n'; 00135 out.flush(); 00136 00137 throw std::bad_alloc(); 00138 } 00139 00140 00141 00142 // 00143 // arma_bad 00144 00146 template<typename T1> 00147 inline 00148 void 00149 arma_cold 00150 arma_bad(const T1& x, const bool hurl = true) 00151 { 00152 #if defined(ARMA_PRINT_RUNTIME_ERRORS) 00153 { 00154 std::ostream& out = get_stream_err2(); 00155 00156 out.flush(); 00157 00158 out << '\n'; 00159 out << "error: " << x << '\n'; 00160 out << '\n'; 00161 out.flush(); 00162 } 00163 #else 00164 { 00165 arma_ignore(x); 00166 } 00167 #endif 00168 00169 if(hurl == true) 00170 { 00171 throw std::runtime_error(""); 00172 } 00173 } 00174 00175 00176 00177 // 00178 // arma_print 00179 00180 00181 inline 00182 void 00183 arma_cold 00184 arma_print() 00185 { 00186 get_stream_err1() << std::endl; 00187 } 00188 00189 00190 template<typename T1> 00191 inline 00192 void 00193 arma_cold 00194 arma_print(const T1& x) 00195 { 00196 get_stream_err1() << x << std::endl; 00197 } 00198 00199 00200 00201 template<typename T1, typename T2> 00202 inline 00203 void 00204 arma_cold 00205 arma_print(const T1& x, const T2& y) 00206 { 00207 get_stream_err1() << x << y << std::endl; 00208 } 00209 00210 00211 00212 template<typename T1, typename T2, typename T3> 00213 inline 00214 void 00215 arma_cold 00216 arma_print(const T1& x, const T2& y, const T3& z) 00217 { 00218 get_stream_err1() << x << y << z << std::endl; 00219 } 00220 00221 00222 00223 00224 00225 00226 // 00227 // arma_sigprint 00228 00233 inline 00234 void 00235 arma_sigprint(const char* x) 00236 { 00237 get_stream_err1() << "@ " << x; 00238 } 00239 00240 00241 00242 // 00243 // arma_bktprint 00244 00245 00246 inline 00247 void 00248 arma_bktprint() 00249 { 00250 get_stream_err1() << std::endl; 00251 } 00252 00253 00254 template<typename T1> 00255 inline 00256 void 00257 arma_bktprint(const T1& x) 00258 { 00259 get_stream_err1() << " [" << x << ']' << std::endl; 00260 } 00261 00262 00263 00264 template<typename T1, typename T2> 00265 inline 00266 void 00267 arma_bktprint(const T1& x, const T2& y) 00268 { 00269 get_stream_err1() << " [" << x << y << ']' << std::endl; 00270 } 00271 00272 00273 00274 00275 00276 00277 // 00278 // arma_thisprint 00279 00280 inline 00281 void 00282 arma_thisprint(const void* this_ptr) 00283 { 00284 get_stream_err1() << " [this = " << this_ptr << ']' << std::endl; 00285 } 00286 00287 00288 00289 // 00290 // arma_warn 00291 00292 00294 template<typename T1> 00295 inline 00296 void 00297 arma_cold 00298 arma_warn(const bool state, const T1& x) 00299 { 00300 if(state==true) 00301 { 00302 get_stream_err2() << x << std::endl; 00303 } 00304 } 00305 00306 00307 template<typename T1, typename T2> 00308 inline 00309 void 00310 arma_cold 00311 arma_warn(const bool state, const T1& x, const T2& y) 00312 { 00313 if(state==true) 00314 { 00315 get_stream_err2() << x << y << std::endl; 00316 } 00317 } 00318 00319 00320 template<typename T1, typename T2, typename T3> 00321 inline 00322 void 00323 arma_cold 00324 arma_warn(const bool state, const T1& x, const T2& y, const T3& z) 00325 { 00326 if(state==true) 00327 { 00328 get_stream_err2() << x << y << z << std::endl; 00329 } 00330 } 00331 00332 00333 00334 // 00335 // arma_check 00336 00338 template<typename T1> 00339 inline 00340 void 00341 arma_hot 00342 arma_check(const bool state, const T1& x) 00343 { 00344 if(state==true) 00345 { 00346 arma_stop(arma_boost::str_wrapper(x)); 00347 } 00348 } 00349 00350 00351 template<typename T1, typename T2> 00352 inline 00353 void 00354 arma_hot 00355 arma_check(const bool state, const T1& x, const T2& y) 00356 { 00357 if(state==true) 00358 { 00359 arma_stop( std::string(x) + std::string(y) ); 00360 } 00361 } 00362 00363 00364 template<typename T1> 00365 inline 00366 void 00367 arma_hot 00368 arma_check_bad_alloc(const bool state, const T1& x) 00369 { 00370 if(state==true) 00371 { 00372 arma_stop_bad_alloc(x); 00373 } 00374 } 00375 00376 00377 00378 // 00379 // arma_set_error 00380 00381 00382 arma_inline 00383 void 00384 arma_hot 00385 arma_set_error(bool& err_state, char*& err_msg, const bool expression, const char* message) 00386 { 00387 if(expression == true) 00388 { 00389 err_state = true; 00390 err_msg = const_cast<char*>(message); 00391 } 00392 } 00393 00394 00395 00396 00397 // 00398 // functions for generating strings indicating size errors 00399 00400 inline 00401 std::string 00402 arma_cold 00403 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) 00404 { 00405 std::stringstream tmp; 00406 00407 tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_n_cols << " and " << B_n_rows << 'x' << B_n_cols; 00408 00409 return tmp.str(); 00410 } 00411 00412 00413 00414 inline 00415 arma_cold 00416 std::string 00417 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) 00418 { 00419 std::stringstream tmp; 00420 00421 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; 00422 00423 return tmp.str(); 00424 } 00425 00426 00427 00428 template<typename eT> 00429 inline 00430 arma_cold 00431 std::string 00432 arma_incompat_size_string(const subview_cube<eT>& Q, const Mat<eT>& A, const char* x) 00433 { 00434 std::stringstream tmp; 00435 00436 tmp << x 00437 << ": interpreting matrix as cube with dimenensions: " 00438 << A.n_rows << 'x' << A.n_cols << 'x' << 1 00439 << " or " 00440 << A.n_rows << 'x' << 1 << 'x' << A.n_cols 00441 << " or " 00442 << 1 << 'x' << A.n_rows << 'x' << A.n_cols 00443 << " is incompatible with cube dimensions: " 00444 << Q.n_rows << 'x' << Q.n_cols << 'x' << Q.n_slices; 00445 00446 return tmp.str(); 00447 } 00448 00449 00450 00451 // 00452 // functions for checking whether two matrices have the same dimensions 00453 00454 00455 00456 inline 00457 void 00458 arma_hot 00459 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) 00460 { 00461 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00462 { 00463 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00464 } 00465 } 00466 00467 00468 00470 template<typename eT1, typename eT2> 00471 inline 00472 void 00473 arma_hot 00474 arma_assert_same_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x) 00475 { 00476 const uword A_n_rows = A.n_rows; 00477 const uword A_n_cols = A.n_cols; 00478 00479 const uword B_n_rows = B.n_rows; 00480 const uword B_n_cols = B.n_cols; 00481 00482 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00483 { 00484 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00485 } 00486 } 00487 00488 00489 00491 template<typename eT1, typename eT2> 00492 inline 00493 void 00494 arma_hot 00495 arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char* x) 00496 { 00497 const uword A_n_rows = A.get_n_rows(); 00498 const uword A_n_cols = A.get_n_cols(); 00499 00500 const uword B_n_rows = B.get_n_rows(); 00501 const uword B_n_cols = B.get_n_cols(); 00502 00503 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00504 { 00505 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00506 } 00507 } 00508 00509 00510 00511 template<typename eT1, typename eT2> 00512 inline 00513 void 00514 arma_hot 00515 arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const char* x) 00516 { 00517 const uword A_n_rows = A.n_rows; 00518 const uword A_n_cols = A.n_cols; 00519 00520 const uword B_n_rows = B.n_rows; 00521 const uword B_n_cols = B.n_cols; 00522 00523 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00524 { 00525 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00526 } 00527 } 00528 00529 00530 00531 template<typename eT1, typename eT2> 00532 inline 00533 void 00534 arma_hot 00535 arma_assert_same_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x) 00536 { 00537 const uword A_n_rows = A.n_rows; 00538 const uword A_n_cols = A.n_cols; 00539 00540 const uword B_n_rows = B.n_rows; 00541 const uword B_n_cols = B.n_cols; 00542 00543 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00544 { 00545 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00546 } 00547 } 00548 00549 00550 00551 template<typename eT1, typename eT2> 00552 inline 00553 void 00554 arma_hot 00555 arma_assert_same_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x) 00556 { 00557 const uword A_n_rows = A.n_rows; 00558 const uword A_n_cols = A.n_cols; 00559 00560 const uword B_n_rows = B.n_rows; 00561 const uword B_n_cols = B.n_cols; 00562 00563 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00564 { 00565 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00566 } 00567 } 00568 00569 00570 00571 template<typename eT1, typename eT2> 00572 inline 00573 void 00574 arma_hot 00575 arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, const char* x) 00576 { 00577 const uword A_n_rows = A.n_rows; 00578 const uword A_n_cols = A.n_cols; 00579 00580 const uword B_n_rows = B.get_n_rows(); 00581 const uword B_n_cols = B.get_n_cols(); 00582 00583 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00584 { 00585 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00586 } 00587 } 00588 00589 00590 00591 template<typename eT1, typename eT2> 00592 inline 00593 void 00594 arma_hot 00595 arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x) 00596 { 00597 const uword A_n_rows = A.get_n_rows(); 00598 const uword A_n_cols = A.get_n_cols(); 00599 00600 const uword B_n_rows = B.n_rows; 00601 const uword B_n_cols = B.n_cols; 00602 00603 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00604 { 00605 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00606 } 00607 } 00608 00609 00610 00611 template<typename eT1, typename eT2> 00612 inline 00613 void 00614 arma_hot 00615 arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const char* x) 00616 { 00617 const uword A_n_rows = A.get_n_rows(); 00618 const uword A_n_cols = A.get_n_cols(); 00619 00620 const uword B_n_rows = B.n_rows; 00621 const uword B_n_cols = B.n_cols; 00622 00623 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00624 { 00625 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00626 } 00627 } 00628 00629 00630 00631 template<typename eT1, typename eT2> 00632 inline 00633 void 00634 arma_hot 00635 arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const char* x) 00636 { 00637 const uword A_n_rows = A.n_rows; 00638 const uword A_n_cols = A.n_cols; 00639 00640 const uword B_n_rows = B.get_n_rows(); 00641 const uword B_n_cols = B.get_n_cols(); 00642 00643 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) 00644 { 00645 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00646 } 00647 } 00648 00649 00650 00651 // 00652 // functions for checking whether two cubes have the same dimensions 00653 00654 00655 00656 inline 00657 void 00658 arma_hot 00659 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) 00660 { 00661 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices) ) 00662 { 00663 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) ); 00664 } 00665 } 00666 00667 00668 00670 template<typename eT1, typename eT2> 00671 inline 00672 void 00673 arma_hot 00674 arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x) 00675 { 00676 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) 00677 { 00678 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) ); 00679 } 00680 } 00681 00682 00683 00684 template<typename eT1, typename eT2> 00685 inline 00686 void 00687 arma_hot 00688 arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const char* x) 00689 { 00690 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) 00691 { 00692 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) ); 00693 } 00694 } 00695 00696 00697 00698 template<typename eT1, typename eT2> 00699 inline 00700 void 00701 arma_hot 00702 arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const char* x) 00703 { 00704 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) 00705 { 00706 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) ); 00707 } 00708 } 00709 00710 00711 00712 template<typename eT1, typename eT2> 00713 inline 00714 void 00715 arma_hot 00716 arma_assert_same_size(const subview_cube<eT1>& A, const subview_cube<eT2>& B, const char* x) 00717 { 00718 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices)) 00719 { 00720 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) ); 00721 } 00722 } 00723 00724 00725 00727 template<typename eT1, typename eT2> 00728 inline 00729 void 00730 arma_hot 00731 arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, const char* x) 00732 { 00733 const uword A_n_rows = A.get_n_rows(); 00734 const uword A_n_cols = A.get_n_cols(); 00735 const uword A_n_slices = A.get_n_slices(); 00736 00737 const uword B_n_rows = B.get_n_rows(); 00738 const uword B_n_cols = B.get_n_cols(); 00739 const uword B_n_slices = B.get_n_slices(); 00740 00741 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices)) 00742 { 00743 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) ); 00744 } 00745 } 00746 00747 00748 00749 // 00750 // functions for checking whether a cube or subcube can be interpreted as a matrix (i.e. single slice) 00751 00752 00753 00754 template<typename eT1, typename eT2> 00755 inline 00756 void 00757 arma_hot 00758 arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x) 00759 { 00760 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) 00761 { 00762 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) ); 00763 } 00764 } 00765 00766 00767 00768 template<typename eT1, typename eT2> 00769 inline 00770 void 00771 arma_hot 00772 arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x) 00773 { 00774 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) 00775 { 00776 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) ); 00777 } 00778 } 00779 00780 00781 00782 template<typename eT1, typename eT2> 00783 inline 00784 void 00785 arma_hot 00786 arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const char* x) 00787 { 00788 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) 00789 { 00790 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) ); 00791 } 00792 } 00793 00794 00795 00796 template<typename eT1, typename eT2> 00797 inline 00798 void 00799 arma_hot 00800 arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const char* x) 00801 { 00802 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) 00803 { 00804 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) ); 00805 } 00806 } 00807 00808 00809 00810 template<typename eT, typename T1> 00811 inline 00812 void 00813 arma_assert_cube_as_mat(const Mat<eT>& M, const T1& Q, const char* x, const bool check_compat_size) 00814 { 00815 const uword Q_n_rows = Q.n_rows; 00816 const uword Q_n_cols = Q.n_cols; 00817 const uword Q_n_slices = Q.n_slices; 00818 00819 const uword M_vec_state = M.vec_state; 00820 00821 if(M_vec_state == 0) 00822 { 00823 if( ( (Q_n_rows == 1) || (Q_n_cols == 1) || (Q_n_slices == 1) ) == false ) 00824 { 00825 std::stringstream tmp; 00826 00827 tmp << x 00828 << ": can't interpret cube with dimensions " 00829 << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices 00830 << " as a matrix; one of the dimensions must be 1"; 00831 00832 arma_stop( tmp.str() ); 00833 } 00834 } 00835 else 00836 { 00837 if(Q_n_slices == 1) 00838 { 00839 if( (M_vec_state == 1) && (Q_n_cols != 1) ) 00840 { 00841 std::stringstream tmp; 00842 00843 tmp << x 00844 << ": can't interpret cube with dimensions " 00845 << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices 00846 << " as a column vector"; 00847 00848 arma_stop( tmp.str() ); 00849 } 00850 00851 if( (M_vec_state == 2) && (Q_n_rows != 1) ) 00852 { 00853 std::stringstream tmp; 00854 00855 tmp << x 00856 << ": can't interpret cube with dimensions " 00857 << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices 00858 << " as a row vector"; 00859 00860 arma_stop( tmp.str() ); 00861 } 00862 } 00863 else 00864 { 00865 if( (Q_n_cols != 1) && (Q_n_rows != 1) ) 00866 { 00867 std::stringstream tmp; 00868 00869 tmp << x 00870 << ": can't interpret cube with dimensions " 00871 << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices 00872 << " as a vector"; 00873 00874 arma_stop( tmp.str() ); 00875 } 00876 } 00877 } 00878 00879 00880 if(check_compat_size == true) 00881 { 00882 const uword M_n_rows = M.n_rows; 00883 const uword M_n_cols = M.n_cols; 00884 00885 if(M_vec_state == 0) 00886 { 00887 if( 00888 ( 00889 ( (Q_n_rows == M_n_rows) && (Q_n_cols == M_n_cols) ) 00890 || 00891 ( (Q_n_rows == M_n_rows) && (Q_n_slices == M_n_cols) ) 00892 || 00893 ( (Q_n_cols == M_n_rows) && (Q_n_slices == M_n_cols) ) 00894 ) 00895 == false 00896 ) 00897 { 00898 std::stringstream tmp; 00899 00900 tmp << x 00901 << ": can't interpret cube with dimenensions " 00902 << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices 00903 << " as a matrix with dimensions " 00904 << M_n_rows << 'x' << M_n_cols; 00905 00906 arma_stop( tmp.str() ); 00907 } 00908 } 00909 else 00910 { 00911 if(Q_n_slices == 1) 00912 { 00913 if( (M_vec_state == 1) && (Q_n_rows != M_n_rows) ) 00914 { 00915 std::stringstream tmp; 00916 00917 tmp << x 00918 << ": can't interpret cube with dimensions " 00919 << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices 00920 << " as a column vector with dimensions " 00921 << M_n_rows << 'x' << M_n_cols; 00922 00923 arma_stop( tmp.str() ); 00924 } 00925 00926 if( (M_vec_state == 2) && (Q_n_cols != M_n_cols) ) 00927 { 00928 std::stringstream tmp; 00929 00930 tmp << x 00931 << ": can't interpret cube with dimensions " 00932 << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices 00933 << " as a row vector with dimensions " 00934 << M_n_rows << 'x' << M_n_cols; 00935 00936 arma_stop( tmp.str() ); 00937 } 00938 } 00939 else 00940 { 00941 if( ( (M_n_cols == Q_n_slices) || (M_n_rows == Q_n_slices) ) == false ) 00942 { 00943 std::stringstream tmp; 00944 00945 tmp << x 00946 << ": can't interpret cube with dimensions " 00947 << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices 00948 << " as a vector with dimensions " 00949 << M_n_rows << 'x' << M_n_cols; 00950 00951 arma_stop( tmp.str() ); 00952 } 00953 } 00954 } 00955 } 00956 } 00957 00958 00959 00960 // 00961 // functions for checking whether two matrices have dimensions that are compatible with the matrix multiply operation 00962 00963 00964 00965 inline 00966 void 00967 arma_hot 00968 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) 00969 { 00970 if(A_n_cols != B_n_rows) 00971 { 00972 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); 00973 } 00974 } 00975 00976 00977 00979 template<typename eT1, typename eT2> 00980 inline 00981 void 00982 arma_hot 00983 arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x) 00984 { 00985 const uword A_n_cols = A.n_cols; 00986 const uword B_n_rows = B.n_rows; 00987 00988 if(A_n_cols != B_n_rows) 00989 { 00990 arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_cols, x) ); 00991 } 00992 } 00993 00994 00995 00997 template<typename eT1, typename eT2> 00998 inline 00999 void 01000 arma_hot 01001 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) 01002 { 01003 const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows; 01004 const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols; 01005 01006 if(final_A_n_cols != final_B_n_rows) 01007 { 01008 const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols; 01009 const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows; 01010 01011 arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) ); 01012 } 01013 } 01014 01015 01016 01017 template<typename eT1, typename eT2> 01018 inline 01019 void 01020 arma_hot 01021 arma_assert_mul_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x) 01022 { 01023 if(A.n_cols != B.n_rows) 01024 { 01025 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); 01026 } 01027 } 01028 01029 01030 01031 template<typename eT1, typename eT2> 01032 inline 01033 void 01034 arma_hot 01035 arma_assert_mul_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x) 01036 { 01037 if(A.n_cols != B.n_rows) 01038 { 01039 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); 01040 } 01041 } 01042 01043 01044 01045 template<typename eT1, typename eT2> 01046 inline 01047 void 01048 arma_hot 01049 arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const char* x) 01050 { 01051 if(A.n_cols != B.n_rows) 01052 { 01053 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); 01054 } 01055 } 01056 01057 01058 01059 // 01060 // macros 01061 01062 01063 #define ARMA_STRING1(x) #x 01064 #define ARMA_STRING2(x) ARMA_STRING1(x) 01065 #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__) 01066 01067 01068 #if defined (__GNUG__) 01069 #define ARMA_FNSIG __PRETTY_FUNCTION__ 01070 #elif defined (_MSC_VER) 01071 #define ARMA_FNSIG __FUNCSIG__ 01072 #elif defined (ARMA_USE_BOOST) 01073 #define ARMA_FNSIG BOOST_CURRENT_FUNCTION 01074 #else 01075 #define ARMA_FNSIG "(unknown)" 01076 #endif 01077 01078 01079 01080 #if !defined(ARMA_NO_DEBUG) && !defined(NDEBUG) 01081 01082 #define arma_debug_print arma_print 01083 #define arma_debug_warn arma_warn 01084 #define arma_debug_check arma_check 01085 #define arma_debug_set_error arma_set_error 01086 #define arma_debug_assert_same_size arma_assert_same_size 01087 #define arma_debug_assert_mul_size arma_assert_mul_size 01088 #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat 01089 01090 #else 01091 01092 #undef ARMA_EXTRA_DEBUG 01093 01094 #define arma_debug_print true ? (void)0 : arma_print 01095 #define arma_debug_warn true ? (void)0 : arma_warn 01096 #define arma_debug_check true ? (void)0 : arma_check 01097 #define arma_debug_set_error true ? (void)0 : arma_set_error 01098 #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_size 01099 #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_size 01100 #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_debug_assert_cube_as_mat 01101 01102 #endif 01103 01104 01105 01106 #if defined(ARMA_EXTRA_DEBUG) 01107 01108 #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_bktprint 01109 #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_thisprint 01110 #define arma_extra_debug_print arma_print 01111 #define arma_extra_debug_warn arma_warn 01112 #define arma_extra_debug_check arma_check 01113 01114 #else 01115 01116 #define arma_extra_debug_sigprint true ? (void)0 : arma_bktprint 01117 #define arma_extra_debug_sigprint_this true ? (void)0 : arma_thisprint 01118 #define arma_extra_debug_print true ? (void)0 : arma_print 01119 #define arma_extra_debug_warn true ? (void)0 : arma_warn 01120 #define arma_extra_debug_check true ? (void)0 : arma_check 01121 01122 #endif 01123 01124 01125 01126 01127 #if defined(ARMA_EXTRA_DEBUG) 01128 01129 namespace junk 01130 { 01131 class arma_first_extra_debug_message 01132 { 01133 public: 01134 01135 inline 01136 arma_cold 01137 arma_first_extra_debug_message() 01138 { 01139 union 01140 { 01141 unsigned short a; 01142 unsigned char b[sizeof(unsigned short)]; 01143 } endian_test; 01144 01145 endian_test.a = 1; 01146 01147 const bool little_endian = (endian_test.b[0] == 1); 01148 const char* nickname = ARMA_VERSION_NAME; 01149 01150 std::ostream& out = get_stream_err1(); 01151 01152 out << "@ ---" << '\n'; 01153 out << "@ Armadillo " 01154 << arma_version::major << '.' << arma_version::minor << '.' << arma_version::patch 01155 << " (" << nickname << ")\n"; 01156 01157 out << "@ arma_config::mat_prealloc = " << arma_config::mat_prealloc << " element(s)\n"; 01158 out << "@ arma_config::atlas = " << arma_config::atlas << '\n'; 01159 out << "@ arma_config::lapack = " << arma_config::lapack << '\n'; 01160 out << "@ arma_config::blas = " << arma_config::blas << '\n'; 01161 out << "@ arma_config::boost = " << arma_config::boost << '\n'; 01162 out << "@ arma_config::boost_date = " << arma_config::boost_date << '\n'; 01163 out << "@ arma_config::good_comp = " << arma_config::good_comp << '\n'; 01164 out << "@ arma_config::extra_code = " << arma_config::extra_code << '\n'; 01165 out << "@ sizeof(void*) = " << sizeof(void*) << '\n'; 01166 out << "@ sizeof(uword) = " << sizeof(uword) << '\n'; 01167 out << "@ sizeof(int) = " << sizeof(int) << '\n'; 01168 out << "@ sizeof(long) = " << sizeof(long) << '\n'; 01169 out << "@ sizeof(blas_int) = " << sizeof(blas_int) << '\n'; 01170 out << "@ little_endian = " << little_endian << '\n'; 01171 out << "@ ---" << std::endl; 01172 } 01173 01174 }; 01175 01176 static arma_first_extra_debug_message arma_first_extra_debug_message_run; 01177 } 01178 01179 #endif 01180 01181 01182