00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 template<typename T1>
00026 inline
00027 void
00028 arma_stop(const T1& x)
00029 {
00030 std::cerr.flush();
00031 std::cout.flush();
00032
00033 std::cout << '\n';
00034 std::cout << "run-time error: " << x << '\n';
00035 std::cout << '\n';
00036 std::cout.flush();
00037
00038 throw std::runtime_error("");
00039 }
00040
00041
00042
00043
00044
00045
00046
00047 inline
00048 void
00049 arma_print()
00050 {
00051 std::cout << std::endl;
00052 }
00053
00054
00055 template<typename T1>
00056 inline
00057 void
00058 arma_print(const T1& x)
00059 {
00060 std::cout << x << std::endl;
00061 }
00062
00063
00064
00065 template<typename T1, typename T2>
00066 inline
00067 void
00068 arma_print(const T1& x, const T2& y)
00069 {
00070 std::cout << x << y << std::endl;
00071 }
00072
00073
00074
00075 #ifdef ARMA_USE_BOOST_FORMAT
00076 template<typename T1>
00077 inline
00078 void
00079 arma_print(const arma_boost::basic_format<T1>& x)
00080 {
00081 std::cout << x << std::endl;
00082 }
00083 #else
00084 template<typename T1, typename T2>
00085 inline
00086 void
00087 arma_print(const arma_boost::basic_format<T1,T2>& x)
00088 {
00089 std::cout << x << std::endl;
00090 }
00091 #endif
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 inline
00102 void
00103 arma_sigprint(const char* x)
00104 {
00105 std::cout << "@ " << x;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114 inline
00115 void
00116 arma_bktprint()
00117 {
00118 std::cout << std::endl;
00119 }
00120
00121
00122 template<typename T1>
00123 inline
00124 void
00125 arma_bktprint(const T1& x)
00126 {
00127 std::cout << " [" << x << ']' << std::endl;
00128 }
00129
00130
00131
00132 template<typename T1, typename T2>
00133 inline
00134 void
00135 arma_bktprint(const T1& x, const T2& y)
00136 {
00137 std::cout << " [" << x << y << ']' << std::endl;
00138 }
00139
00140
00141
00142 #ifdef ARMA_USE_BOOST_FORMAT
00143 template<typename T1>
00144 inline
00145 void
00146 arma_bktprint(const arma_boost::basic_format<T1>& x)
00147 {
00148 std::cout << " [" << x << ']' << std::endl;
00149 }
00150 #else
00151 template<typename T1, typename T2>
00152 inline
00153 void
00154 arma_bktprint(const arma_boost::basic_format<T1,T2>& x)
00155 {
00156 std::cout << " [" << x << ']' << std::endl;
00157 }
00158 #endif
00159
00160
00161
00162
00163
00164
00165
00166 inline
00167 void
00168 arma_thisprint(void* this_ptr)
00169 {
00170 std::cout << " [this = " << this_ptr << ']' << std::endl;
00171 }
00172
00173
00174
00175
00176
00177
00178
00179 template<typename T1>
00180 inline
00181 void
00182 arma_hot
00183 arma_warn(const bool state, const T1& x)
00184 {
00185 if(state==true)
00186 {
00187 arma_print(x);
00188 }
00189 }
00190
00191
00192 template<typename T1, typename T2>
00193 inline
00194 void
00195 arma_hot
00196 arma_warn(const bool state, const T1& x, const T2& y)
00197 {
00198 if(state==true)
00199 {
00200 arma_print(x,y);
00201 }
00202 }
00203
00204
00205 #ifdef ARMA_USE_BOOST_FORMAT
00206 template<typename T1>
00207 inline
00208 void
00209 arma_hot
00210 arma_warn(const bool state, const arma_boost::basic_format<T1>& x)
00211 {
00212 if(state==true)
00213 arma_print(x);
00214 }
00215 #else
00216 template<typename T1, typename T2>
00217 inline
00218 void
00219 arma_hot
00220 arma_warn(const bool state, const arma_boost::basic_format<T1,T2>& x)
00221 {
00222 if(state==true)
00223 arma_print(x);
00224 }
00225 #endif
00226
00227
00228
00229
00230
00231
00232
00233 template<typename T1>
00234 inline
00235 void
00236 arma_hot
00237 arma_check(const bool state, const T1& x)
00238 {
00239 if(state==true)
00240 {
00241 arma_stop(x);
00242 }
00243 }
00244
00245
00246 template<typename T1, typename T2>
00247 inline
00248 void
00249 arma_hot
00250 arma_check(const bool state, const T1& x, const T2& y)
00251 {
00252 if(state==true)
00253 {
00254 arma_stop( std::string(x) + std::string(y) );
00255 }
00256 }
00257
00258
00259 #ifdef ARMA_USE_BOOST_FORMAT
00260 template<typename T1>
00261 inline
00262 void
00263 arma_hot
00264 arma_check(const bool state, const arma_boost::basic_format<T1>& x)
00265 {
00266 if(state==true)
00267 {
00268 arma_stop(str(x));
00269 }
00270 }
00271 #else
00272 template<typename T1, typename T2>
00273 inline
00274 void
00275 arma_hot
00276 arma_check(const bool state, const arma_boost::basic_format<T1,T2>& x)
00277 {
00278 if(state==true)
00279 {
00280 arma_stop(str(x));
00281 }
00282 }
00283 #endif
00284
00285
00286
00287
00288
00289
00290
00291
00292 inline
00293 std::string
00294 arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_rows, const u32 B_n_cols, const char* x)
00295 {
00296 std::stringstream tmp;
00297
00298 tmp << x << ": incompatible matrix dimensions: (" << A_n_rows << ',' << A_n_cols << ") and (" << B_n_rows << ',' << B_n_cols << ')';
00299
00300 return tmp.str();
00301 }
00302
00303
00304
00305 inline
00306 void
00307 arma_hot
00308 arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_rows, const u32 B_n_cols, const char* x)
00309 {
00310 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
00311 {
00312 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
00313 }
00314 }
00315
00316
00317
00318
00319 template<typename eT1, typename eT2>
00320 inline
00321 void
00322 arma_hot
00323 arma_assert_same_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x)
00324 {
00325 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00326 {
00327 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00328 }
00329 }
00330
00331
00332
00333
00334 template<typename eT1, typename eT2>
00335 inline
00336 void
00337 arma_hot
00338 arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char* x)
00339 {
00340 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00341 {
00342 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00343 }
00344 }
00345
00346
00347
00348 template<typename eT1, typename eT2>
00349 inline
00350 void
00351 arma_hot
00352 arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const char* x)
00353 {
00354 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00355 {
00356 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00357 }
00358 }
00359
00360
00361
00362 template<typename eT1, typename eT2>
00363 inline
00364 void
00365 arma_hot
00366 arma_assert_same_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x)
00367 {
00368 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00369 {
00370 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00371 }
00372 }
00373
00374
00375
00376 template<typename eT1, typename eT2>
00377 inline
00378 void
00379 arma_hot
00380 arma_assert_same_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x)
00381 {
00382 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00383 {
00384 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00385 }
00386 }
00387
00388
00389
00390 template<typename eT1, typename eT2>
00391 inline
00392 void
00393 arma_hot
00394 arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, const char* x)
00395 {
00396 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00397 {
00398 arma_stop ( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00399 }
00400 }
00401
00402
00403
00404 template<typename eT1, typename eT2>
00405 inline
00406 void
00407 arma_hot
00408 arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x)
00409 {
00410 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00411 {
00412 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00413 }
00414 }
00415
00416
00417
00418 template<typename eT1, typename eT2>
00419 inline
00420 void
00421 arma_hot
00422 arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const char* x)
00423 {
00424 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00425 {
00426 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00427 }
00428 }
00429
00430
00431
00432 template<typename eT1, typename eT2>
00433 inline
00434 void
00435 arma_hot
00436 arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const char* x)
00437 {
00438 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) )
00439 {
00440 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00441 }
00442 }
00443
00444
00445
00446
00447
00448
00449
00450
00451 inline
00452 std::string
00453 arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, const char* x)
00454 {
00455 std::stringstream tmp;
00456
00457 tmp << x << ": incompatible cube dimensions: (" << A_n_rows << ',' << A_n_cols << ',' << A_n_slices << ") and (" << B_n_rows << ',' << B_n_cols << ',' << B_n_slices << ')';
00458
00459 return tmp.str();
00460 }
00461
00462
00463
00464 inline
00465 void
00466 arma_hot
00467 arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, const char* x)
00468 {
00469 if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices) )
00470 {
00471 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) );
00472 }
00473 }
00474
00475
00476
00477
00478 template<typename eT1, typename eT2>
00479 inline
00480 void
00481 arma_hot
00482 arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x)
00483 {
00484 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
00485 {
00486 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) );
00487 }
00488 }
00489
00490
00491
00492 template<typename eT1, typename eT2>
00493 inline
00494 void
00495 arma_hot
00496 arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const char* x)
00497 {
00498 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
00499 {
00500 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) );
00501 }
00502 }
00503
00504
00505
00506 template<typename eT1, typename eT2>
00507 inline
00508 void
00509 arma_hot
00510 arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const char* x)
00511 {
00512 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
00513 {
00514 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) );
00515 }
00516 }
00517
00518
00519
00520 template<typename eT1, typename eT2>
00521 inline
00522 void
00523 arma_hot
00524 arma_assert_same_size(const subview_cube<eT1>& A, const subview_cube<eT2>& B, const char* x)
00525 {
00526 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices))
00527 {
00528 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) );
00529 }
00530 }
00531
00532
00533
00534
00535 template<typename eT1, typename eT2>
00536 inline
00537 void
00538 arma_hot
00539 arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, const char* x)
00540 {
00541 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices))
00542 {
00543 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) );
00544 }
00545 }
00546
00547
00548
00549
00550
00551
00552
00553
00554 template<typename eT1, typename eT2>
00555 inline
00556 void
00557 arma_hot
00558 arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x)
00559 {
00560 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) )
00561 {
00562 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) );
00563 }
00564 }
00565
00566
00567
00568 template<typename eT1, typename eT2>
00569 inline
00570 void
00571 arma_hot
00572 arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x)
00573 {
00574 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) )
00575 {
00576 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) );
00577 }
00578 }
00579
00580
00581
00582 template<typename eT1, typename eT2>
00583 inline
00584 void
00585 arma_hot
00586 arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const char* x)
00587 {
00588 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) )
00589 {
00590 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) );
00591 }
00592 }
00593
00594
00595
00596 template<typename eT1, typename eT2>
00597 inline
00598 void
00599 arma_hot
00600 arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const char* x)
00601 {
00602 if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) )
00603 {
00604 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) );
00605 }
00606 }
00607
00608
00609
00610
00611
00612
00613
00614
00615 inline
00616 void
00617 arma_hot
00618 arma_assert_mul_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_rows, const u32 B_n_cols, const char* x)
00619 {
00620 if(A_n_cols != B_n_rows)
00621 {
00622 arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
00623 }
00624 }
00625
00626
00627
00628
00629 template<typename eT1, typename eT2>
00630 inline
00631 void
00632 arma_hot
00633 arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x)
00634 {
00635 if(A.n_cols != B.n_rows)
00636 {
00637 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00638 }
00639 }
00640
00641
00642
00643
00644 template<typename eT1, typename eT2>
00645 inline
00646 void
00647 arma_hot
00648 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)
00649 {
00650 const u32 final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows;
00651 const u32 final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols;
00652
00653 if(final_A_n_cols != final_B_n_rows)
00654 {
00655 const u32 final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols;
00656 const u32 final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows;
00657
00658 arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) );
00659 }
00660 }
00661
00662
00663
00664 template<typename eT1, typename eT2>
00665 inline
00666 void
00667 arma_hot
00668 arma_assert_mul_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x)
00669 {
00670 if(A.n_cols != B.n_rows)
00671 {
00672 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00673 }
00674 }
00675
00676
00677
00678 template<typename eT1, typename eT2>
00679 inline
00680 void
00681 arma_hot
00682 arma_assert_mul_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x)
00683 {
00684 if(A.n_cols != B.n_rows)
00685 {
00686 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00687 }
00688 }
00689
00690
00691
00692 template<typename eT1, typename eT2>
00693 inline
00694 void
00695 arma_hot
00696 arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const char* x)
00697 {
00698 if(A.n_cols != B.n_rows)
00699 {
00700 arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) );
00701 }
00702 }
00703
00704
00705
00706
00707
00708
00709
00710 #define ARMA_STRING1(x) #x
00711 #define ARMA_STRING2(x) ARMA_STRING1(x)
00712 #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__)
00713
00714
00715 #if defined (__GNUG__)
00716 #define ARMA_FNSIG __PRETTY_FUNCTION__
00717 #elif defined (_MSC_VER)
00718 #define ARMA_FNSIG __FUNCSIG__
00719 #elif defined (ARMA_USE_BOOST)
00720 #define ARMA_FNSIG BOOST_CURRENT_FUNCTION
00721 #else
00722 #define ARMA_FNSIG "(unknown)"
00723 #endif
00724
00725
00726
00727 #if !defined(ARMA_NO_DEBUG) && !defined(NDEBUG)
00728
00729 #define arma_debug_print arma_print
00730 #define arma_debug_warn arma_warn
00731 #define arma_debug_check arma_check
00732 #define arma_debug_assert_same_size arma_assert_same_size
00733 #define arma_debug_assert_mul_size arma_assert_mul_size
00734
00735 #else
00736
00737 #undef ARMA_EXTRA_DEBUG
00738
00739 #define arma_debug_print true ? (void)0 : arma_print
00740 #define arma_debug_warn true ? (void)0 : arma_warn
00741 #define arma_debug_check true ? (void)0 : arma_check
00742 #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_size
00743 #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_size
00744
00745 #endif
00746
00747
00748 #if defined(ARMA_EXTRA_DEBUG)
00749
00750 #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_bktprint
00751 #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_thisprint
00752 #define arma_extra_debug_print arma_print
00753 #define arma_extra_debug_warn arma_warn
00754 #define arma_extra_debug_check arma_check
00755
00756 #else
00757
00758 #define arma_extra_debug_sigprint true ? (void)0 : arma_bktprint
00759 #define arma_extra_debug_sigprint_this true ? (void)0 : arma_thisprint
00760 #define arma_extra_debug_print true ? (void)0 : arma_print
00761 #define arma_extra_debug_warn true ? (void)0 : arma_warn
00762 #define arma_extra_debug_check true ? (void)0 : arma_check
00763
00764 #endif
00765
00766
00767
00768
00769 #if defined(ARMA_EXTRA_DEBUG)
00770
00771 namespace junk
00772 {
00773 class arma_first_extra_debug_message
00774 {
00775 public:
00776
00777 inline
00778 arma_first_extra_debug_message()
00779 {
00780 std::cout << "@ ---" << '\n';
00781 std::cout << "@ Armadillo " << arma_version::major << '.' << arma_version::minor << '.' << arma_version::patch << '\n';
00782 std::cout << "@ arma_config::atlas = " << arma_config::atlas << '\n';
00783 std::cout << "@ arma_config::lapack = " << arma_config::lapack << '\n';
00784 std::cout << "@ arma_config::blas = " << arma_config::blas << '\n';
00785 std::cout << "@ arma_config::boost = " << arma_config::boost << '\n';
00786 std::cout << "@ arma_config::boost_date = " << arma_config::boost_date << '\n';
00787 std::cout << "@ arma_config::good_comp = " << arma_config::good_comp << '\n';
00788 std::cout << "@ sizeof(int) = " << sizeof(int) << '\n';
00789 std::cout << "@ sizeof(int*) = " << sizeof(int*) << '\n';
00790 std::cout << "@ sizeof(long) = " << sizeof(long) << '\n';
00791 std::cout << "@ ---" << std::endl;
00792 }
00793
00794 };
00795
00796 static arma_first_extra_debug_message arma_first_extra_debug_message_run;
00797 }
00798
00799 #endif
00800
00801
00802