debug.hpp
Go to the documentation of this file.
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2011 Conrad Sanderson
3 // Copyright (C) 2011 Stanislav Funiak
4 //
5 // This file is part of the Armadillo C++ library.
6 // It is provided without any warranty of fitness
7 // for any purpose. You can redistribute this file
8 // and/or modify it under the terms of the GNU
9 // Lesser General Public License (LGPL) as published
10 // by the Free Software Foundation, either version 3
11 // of the License or (at your option) any later version.
12 // (see http://www.opensource.org/licenses for more info)
13 
14 
17 
18 
19 
20 template<typename T>
21 inline
22 std::ostream&
23 arma_stream_err1(std::ostream* user_stream)
24  {
25  static std::ostream* stream_err1 = &(std::cout);
26 
27  if(user_stream != NULL)
28  {
29  stream_err1 = user_stream;
30  }
31 
32  return *stream_err1;
33  }
34 
35 
36 
37 template<typename T>
38 inline
39 std::ostream&
40 arma_stream_err2(std::ostream* user_stream)
41  {
42  static std::ostream* stream_err2 = &(std::cout);
43 
44  if(user_stream != NULL)
45  {
46  stream_err2 = user_stream;
47  }
48 
49  return *stream_err2;
50  }
51 
52 
53 
54 inline
55 void
56 set_stream_err1(std::ostream& user_stream)
57  {
58  arma_stream_err1<char>(&user_stream);
59  }
60 
61 
62 
63 inline
64 void
65 set_stream_err2(std::ostream& user_stream)
66  {
67  arma_stream_err2<char>(&user_stream);
68  }
69 
70 
71 
72 inline
73 std::ostream&
75  {
76  return arma_stream_err1<char>(NULL);
77  }
78 
79 
80 
81 inline
82 std::ostream&
84  {
85  return arma_stream_err2<char>(NULL);
86  }
87 
88 
89 
90 //
91 // arma_stop
92 
94 template<typename T1>
95 inline
96 void
98 arma_stop(const T1& x)
99  {
100  #if defined(ARMA_PRINT_LOGIC_ERRORS)
101  {
102  std::ostream& out = get_stream_err1();
103 
104  out.flush();
105 
106  out << '\n';
107  out << "error: " << x << '\n';
108  out << '\n';
109  out.flush();
110  }
111  #else
112  {
113  arma_ignore(x);
114  }
115  #endif
116 
117  throw std::logic_error("");
118  }
119 
120 
121 
122 template<typename T1>
123 inline
124 void
125 arma_cold
127  {
128  std::ostream& out = get_stream_err1();
129 
130  out.flush();
131 
132  out << '\n';
133  out << "error: " << x << '\n';
134  out << '\n';
135  out.flush();
136 
137  throw std::bad_alloc();
138  }
139 
140 
141 
142 //
143 // arma_bad
144 
146 template<typename T1>
147 inline
148 void
149 arma_cold
150 arma_bad(const T1& x, const bool hurl = true)
151  {
152  #if defined(ARMA_PRINT_RUNTIME_ERRORS)
153  {
154  std::ostream& out = get_stream_err2();
155 
156  out.flush();
157 
158  out << '\n';
159  out << "error: " << x << '\n';
160  out << '\n';
161  out.flush();
162  }
163  #else
164  {
165  arma_ignore(x);
166  }
167  #endif
168 
169  if(hurl == true)
170  {
171  throw std::runtime_error("");
172  }
173  }
174 
175 
176 
177 //
178 // arma_print
179 
180 
181 inline
182 void
183 arma_cold
185  {
186  get_stream_err1() << std::endl;
187  }
188 
189 
190 template<typename T1>
191 inline
192 void
193 arma_cold
194 arma_print(const T1& x)
195  {
196  get_stream_err1() << x << std::endl;
197  }
198 
199 
200 
201 template<typename T1, typename T2>
202 inline
203 void
204 arma_cold
205 arma_print(const T1& x, const T2& y)
206  {
207  get_stream_err1() << x << y << std::endl;
208  }
209 
210 
211 
212 template<typename T1, typename T2, typename T3>
213 inline
214 void
215 arma_cold
216 arma_print(const T1& x, const T2& y, const T3& z)
217  {
218  get_stream_err1() << x << y << z << std::endl;
219  }
220 
221 
222 
223 
224 
225 
226 //
227 // arma_sigprint
228 
233 inline
234 void
235 arma_sigprint(const char* x)
236  {
237  get_stream_err1() << "@ " << x;
238  }
239 
240 
241 
242 //
243 // arma_bktprint
244 
245 
246 inline
247 void
249  {
250  get_stream_err1() << std::endl;
251  }
252 
253 
254 template<typename T1>
255 inline
256 void
257 arma_bktprint(const T1& x)
258  {
259  get_stream_err1() << " [" << x << ']' << std::endl;
260  }
261 
262 
263 
264 template<typename T1, typename T2>
265 inline
266 void
267 arma_bktprint(const T1& x, const T2& y)
268  {
269  get_stream_err1() << " [" << x << y << ']' << std::endl;
270  }
271 
272 
273 
274 
275 
276 
277 //
278 // arma_thisprint
279 
280 inline
281 void
282 arma_thisprint(const void* this_ptr)
283  {
284  get_stream_err1() << " [this = " << this_ptr << ']' << std::endl;
285  }
286 
287 
288 
289 //
290 // arma_warn
291 
292 
294 template<typename T1>
295 inline
296 void
297 arma_cold
298 arma_warn(const bool state, const T1& x)
299  {
300  if(state==true)
301  {
302  get_stream_err2() << x << std::endl;
303  }
304  }
305 
306 
307 template<typename T1, typename T2>
308 inline
309 void
310 arma_cold
311 arma_warn(const bool state, const T1& x, const T2& y)
312  {
313  if(state==true)
314  {
315  get_stream_err2() << x << y << std::endl;
316  }
317  }
318 
319 
320 template<typename T1, typename T2, typename T3>
321 inline
322 void
323 arma_cold
324 arma_warn(const bool state, const T1& x, const T2& y, const T3& z)
325  {
326  if(state==true)
327  {
328  get_stream_err2() << x << y << z << std::endl;
329  }
330  }
331 
332 
333 
334 //
335 // arma_check
336 
338 template<typename T1>
339 inline
340 void
341 arma_hot
342 arma_check(const bool state, const T1& x)
343  {
344  if(state==true)
345  {
347  }
348  }
349 
350 
351 template<typename T1, typename T2>
352 inline
353 void
354 arma_hot
355 arma_check(const bool state, const T1& x, const T2& y)
356  {
357  if(state==true)
358  {
359  arma_stop( std::string(x) + std::string(y) );
360  }
361  }
362 
363 
364 template<typename T1>
365 inline
366 void
367 arma_hot
368 arma_check_bad_alloc(const bool state, const T1& x)
369  {
370  if(state==true)
371  {
373  }
374  }
375 
376 
377 
378 //
379 // arma_set_error
380 
381 
383 void
384 arma_hot
385 arma_set_error(bool& err_state, char*& err_msg, const bool expression, const char* message)
386  {
387  if(expression == true)
388  {
389  err_state = true;
390  err_msg = const_cast<char*>(message);
391  }
392  }
393 
394 
395 
396 
397 //
398 // functions for generating strings indicating size errors
399 
400 inline
401 std::string
402 arma_cold
403 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)
404  {
405  std::stringstream tmp;
406 
407  tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_n_cols << " and " << B_n_rows << 'x' << B_n_cols;
408 
409  return tmp.str();
410  }
411 
412 
413 
414 inline
415 arma_cold
416 std::string
417 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)
418  {
419  std::stringstream tmp;
420 
421  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;
422 
423  return tmp.str();
424  }
425 
426 
427 
428 template<typename eT>
429 inline
430 arma_cold
431 std::string
432 arma_incompat_size_string(const subview_cube<eT>& Q, const Mat<eT>& A, const char* x)
433  {
434  std::stringstream tmp;
435 
436  tmp << x
437  << ": interpreting matrix as cube with dimenensions: "
438  << A.n_rows << 'x' << A.n_cols << 'x' << 1
439  << " or "
440  << A.n_rows << 'x' << 1 << 'x' << A.n_cols
441  << " or "
442  << 1 << 'x' << A.n_rows << 'x' << A.n_cols
443  << " is incompatible with cube dimensions: "
444  << Q.n_rows << 'x' << Q.n_cols << 'x' << Q.n_slices;
445 
446  return tmp.str();
447  }
448 
449 
450 
451 //
452 // functions for checking whether two matrices have the same dimensions
453 
454 
455 
456 inline
457 void
458 arma_hot
459 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)
460  {
461  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
462  {
463  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
464  }
465  }
466 
467 
468 
470 template<typename eT1, typename eT2>
471 inline
472 void
473 arma_hot
474 arma_assert_same_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x)
475  {
476  const uword A_n_rows = A.n_rows;
477  const uword A_n_cols = A.n_cols;
478 
479  const uword B_n_rows = B.n_rows;
480  const uword B_n_cols = B.n_cols;
481 
482  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
483  {
484  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
485  }
486  }
487 
488 
489 
491 template<typename eT1, typename eT2>
492 inline
493 void
494 arma_hot
495 arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char* x)
496  {
497  const uword A_n_rows = A.get_n_rows();
498  const uword A_n_cols = A.get_n_cols();
499 
500  const uword B_n_rows = B.get_n_rows();
501  const uword B_n_cols = B.get_n_cols();
502 
503  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
504  {
505  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
506  }
507  }
508 
509 
510 
511 template<typename eT1, typename eT2>
512 inline
513 void
514 arma_hot
515 arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const char* x)
516  {
517  const uword A_n_rows = A.n_rows;
518  const uword A_n_cols = A.n_cols;
519 
520  const uword B_n_rows = B.n_rows;
521  const uword B_n_cols = B.n_cols;
522 
523  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
524  {
525  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
526  }
527  }
528 
529 
530 
531 template<typename eT1, typename eT2>
532 inline
533 void
534 arma_hot
535 arma_assert_same_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x)
536  {
537  const uword A_n_rows = A.n_rows;
538  const uword A_n_cols = A.n_cols;
539 
540  const uword B_n_rows = B.n_rows;
541  const uword B_n_cols = B.n_cols;
542 
543  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
544  {
545  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
546  }
547  }
548 
549 
550 
551 template<typename eT1, typename eT2>
552 inline
553 void
554 arma_hot
555 arma_assert_same_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x)
556  {
557  const uword A_n_rows = A.n_rows;
558  const uword A_n_cols = A.n_cols;
559 
560  const uword B_n_rows = B.n_rows;
561  const uword B_n_cols = B.n_cols;
562 
563  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
564  {
565  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
566  }
567  }
568 
569 
570 
571 template<typename eT1, typename eT2>
572 inline
573 void
574 arma_hot
575 arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, const char* x)
576  {
577  const uword A_n_rows = A.n_rows;
578  const uword A_n_cols = A.n_cols;
579 
580  const uword B_n_rows = B.get_n_rows();
581  const uword B_n_cols = B.get_n_cols();
582 
583  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
584  {
585  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
586  }
587  }
588 
589 
590 
591 template<typename eT1, typename eT2>
592 inline
593 void
594 arma_hot
595 arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x)
596  {
597  const uword A_n_rows = A.get_n_rows();
598  const uword A_n_cols = A.get_n_cols();
599 
600  const uword B_n_rows = B.n_rows;
601  const uword B_n_cols = B.n_cols;
602 
603  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
604  {
605  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
606  }
607  }
608 
609 
610 
611 template<typename eT1, typename eT2>
612 inline
613 void
614 arma_hot
615 arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const char* x)
616  {
617  const uword A_n_rows = A.get_n_rows();
618  const uword A_n_cols = A.get_n_cols();
619 
620  const uword B_n_rows = B.n_rows;
621  const uword B_n_cols = B.n_cols;
622 
623  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
624  {
625  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
626  }
627  }
628 
629 
630 
631 template<typename eT1, typename eT2>
632 inline
633 void
634 arma_hot
635 arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const char* x)
636  {
637  const uword A_n_rows = A.n_rows;
638  const uword A_n_cols = A.n_cols;
639 
640  const uword B_n_rows = B.get_n_rows();
641  const uword B_n_cols = B.get_n_cols();
642 
643  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
644  {
645  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
646  }
647  }
648 
649 
650 
651 //
652 // functions for checking whether two cubes have the same dimensions
653 
654 
655 
656 inline
657 void
658 arma_hot
659 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)
660  {
661  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices) )
662  {
663  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) );
664  }
665  }
666 
667 
668 
670 template<typename eT1, typename eT2>
671 inline
672 void
673 arma_hot
674 arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x)
675  {
676  if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
677  {
679  }
680  }
681 
682 
683 
684 template<typename eT1, typename eT2>
685 inline
686 void
687 arma_hot
688 arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const char* x)
689  {
690  if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
691  {
693  }
694  }
695 
696 
697 
698 template<typename eT1, typename eT2>
699 inline
700 void
701 arma_hot
702 arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const char* x)
703  {
704  if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) )
705  {
707  }
708  }
709 
710 
711 
712 template<typename eT1, typename eT2>
713 inline
714 void
715 arma_hot
717  {
718  if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices))
719  {
721  }
722  }
723 
724 
725 
727 template<typename eT1, typename eT2>
728 inline
729 void
730 arma_hot
731 arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, const char* x)
732  {
733  const uword A_n_rows = A.get_n_rows();
734  const uword A_n_cols = A.get_n_cols();
735  const uword A_n_slices = A.get_n_slices();
736 
737  const uword B_n_rows = B.get_n_rows();
738  const uword B_n_cols = B.get_n_cols();
739  const uword B_n_slices = B.get_n_slices();
740 
741  if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices))
742  {
743  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) );
744  }
745  }
746 
747 
748 
749 //
750 // functions for checking whether a cube or subcube can be interpreted as a matrix (i.e. single slice)
751 
752 
753 
754 template<typename eT1, typename eT2>
755 inline
756 void
757 arma_hot
758 arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x)
759  {
760  if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) )
761  {
763  }
764  }
765 
766 
767 
768 template<typename eT1, typename eT2>
769 inline
770 void
771 arma_hot
772 arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x)
773  {
774  if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) )
775  {
777  }
778  }
779 
780 
781 
782 template<typename eT1, typename eT2>
783 inline
784 void
785 arma_hot
786 arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const char* x)
787  {
788  if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) )
789  {
791  }
792  }
793 
794 
795 
796 template<typename eT1, typename eT2>
797 inline
798 void
799 arma_hot
800 arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const char* x)
801  {
802  if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) )
803  {
805  }
806  }
807 
808 
809 
810 template<typename eT, typename T1>
811 inline
812 void
813 arma_assert_cube_as_mat(const Mat<eT>& M, const T1& Q, const char* x, const bool check_compat_size)
814  {
815  const uword Q_n_rows = Q.n_rows;
816  const uword Q_n_cols = Q.n_cols;
817  const uword Q_n_slices = Q.n_slices;
818 
819  const uword M_vec_state = M.vec_state;
820 
821  if(M_vec_state == 0)
822  {
823  if( ( (Q_n_rows == 1) || (Q_n_cols == 1) || (Q_n_slices == 1) ) == false )
824  {
825  std::stringstream tmp;
826 
827  tmp << x
828  << ": can't interpret cube with dimensions "
829  << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
830  << " as a matrix; one of the dimensions must be 1";
831 
832  arma_stop( tmp.str() );
833  }
834  }
835  else
836  {
837  if(Q_n_slices == 1)
838  {
839  if( (M_vec_state == 1) && (Q_n_cols != 1) )
840  {
841  std::stringstream tmp;
842 
843  tmp << x
844  << ": can't interpret cube with dimensions "
845  << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
846  << " as a column vector";
847 
848  arma_stop( tmp.str() );
849  }
850 
851  if( (M_vec_state == 2) && (Q_n_rows != 1) )
852  {
853  std::stringstream tmp;
854 
855  tmp << x
856  << ": can't interpret cube with dimensions "
857  << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
858  << " as a row vector";
859 
860  arma_stop( tmp.str() );
861  }
862  }
863  else
864  {
865  if( (Q_n_cols != 1) && (Q_n_rows != 1) )
866  {
867  std::stringstream tmp;
868 
869  tmp << x
870  << ": can't interpret cube with dimensions "
871  << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
872  << " as a vector";
873 
874  arma_stop( tmp.str() );
875  }
876  }
877  }
878 
879 
880  if(check_compat_size == true)
881  {
882  const uword M_n_rows = M.n_rows;
883  const uword M_n_cols = M.n_cols;
884 
885  if(M_vec_state == 0)
886  {
887  if(
888  (
889  ( (Q_n_rows == M_n_rows) && (Q_n_cols == M_n_cols) )
890  ||
891  ( (Q_n_rows == M_n_rows) && (Q_n_slices == M_n_cols) )
892  ||
893  ( (Q_n_cols == M_n_rows) && (Q_n_slices == M_n_cols) )
894  )
895  == false
896  )
897  {
898  std::stringstream tmp;
899 
900  tmp << x
901  << ": can't interpret cube with dimenensions "
902  << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
903  << " as a matrix with dimensions "
904  << M_n_rows << 'x' << M_n_cols;
905 
906  arma_stop( tmp.str() );
907  }
908  }
909  else
910  {
911  if(Q_n_slices == 1)
912  {
913  if( (M_vec_state == 1) && (Q_n_rows != M_n_rows) )
914  {
915  std::stringstream tmp;
916 
917  tmp << x
918  << ": can't interpret cube with dimensions "
919  << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
920  << " as a column vector with dimensions "
921  << M_n_rows << 'x' << M_n_cols;
922 
923  arma_stop( tmp.str() );
924  }
925 
926  if( (M_vec_state == 2) && (Q_n_cols != M_n_cols) )
927  {
928  std::stringstream tmp;
929 
930  tmp << x
931  << ": can't interpret cube with dimensions "
932  << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
933  << " as a row vector with dimensions "
934  << M_n_rows << 'x' << M_n_cols;
935 
936  arma_stop( tmp.str() );
937  }
938  }
939  else
940  {
941  if( ( (M_n_cols == Q_n_slices) || (M_n_rows == Q_n_slices) ) == false )
942  {
943  std::stringstream tmp;
944 
945  tmp << x
946  << ": can't interpret cube with dimensions "
947  << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices
948  << " as a vector with dimensions "
949  << M_n_rows << 'x' << M_n_cols;
950 
951  arma_stop( tmp.str() );
952  }
953  }
954  }
955  }
956  }
957 
958 
959 
960 //
961 // functions for checking whether two matrices have dimensions that are compatible with the matrix multiply operation
962 
963 
964 
965 inline
966 void
967 arma_hot
968 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)
969  {
970  if(A_n_cols != B_n_rows)
971  {
972  arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) );
973  }
974  }
975 
976 
977 
979 template<typename eT1, typename eT2>
980 inline
981 void
982 arma_hot
983 arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x)
984  {
985  const uword A_n_cols = A.n_cols;
986  const uword B_n_rows = B.n_rows;
987 
988  if(A_n_cols != B_n_rows)
989  {
990  arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_cols, x) );
991  }
992  }
993 
994 
995 
997 template<typename eT1, typename eT2>
998 inline
999 void
1000 arma_hot
1001 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)
1002  {
1003  const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows;
1004  const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols;
1005 
1006  if(final_A_n_cols != final_B_n_rows)
1007  {
1008  const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols;
1009  const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows;
1010 
1011  arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) );
1012  }
1013  }
1014 
1015 
1016 
1017 template<typename eT1, typename eT2>
1018 inline
1019 void
1020 arma_hot
1021 arma_assert_mul_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x)
1022  {
1023  if(A.n_cols != B.n_rows)
1024  {
1026  }
1027  }
1028 
1029 
1030 
1031 template<typename eT1, typename eT2>
1032 inline
1033 void
1034 arma_hot
1035 arma_assert_mul_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x)
1036  {
1037  if(A.n_cols != B.n_rows)
1038  {
1040  }
1041  }
1042 
1043 
1044 
1045 template<typename eT1, typename eT2>
1046 inline
1047 void
1048 arma_hot
1049 arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const char* x)
1050  {
1051  if(A.n_cols != B.n_rows)
1052  {
1054  }
1055  }
1056 
1057 
1058 
1059 //
1060 // macros
1061 
1062 
1063 #define ARMA_STRING1(x) #x
1064 #define ARMA_STRING2(x) ARMA_STRING1(x)
1065 #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__)
1066 
1067 
1068 #if defined (__GNUG__)
1069  #define ARMA_FNSIG __PRETTY_FUNCTION__
1070 #elif defined (_MSC_VER)
1071  #define ARMA_FNSIG __FUNCSIG__
1072 #elif defined (ARMA_USE_BOOST)
1073  #define ARMA_FNSIG BOOST_CURRENT_FUNCTION
1074 #else
1075  #define ARMA_FNSIG "(unknown)"
1076 #endif
1077 
1078 
1079 
1080 #if !defined(ARMA_NO_DEBUG) && !defined(NDEBUG)
1081 
1082  #define arma_debug_print arma_print
1083  #define arma_debug_warn arma_warn
1084  #define arma_debug_check arma_check
1085  #define arma_debug_set_error arma_set_error
1086  #define arma_debug_assert_same_size arma_assert_same_size
1087  #define arma_debug_assert_mul_size arma_assert_mul_size
1088  #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat
1089 
1090 #else
1091 
1092  #undef ARMA_EXTRA_DEBUG
1093 
1094  #define arma_debug_print true ? (void)0 : arma_print
1095  #define arma_debug_warn true ? (void)0 : arma_warn
1096  #define arma_debug_check true ? (void)0 : arma_check
1097  #define arma_debug_set_error true ? (void)0 : arma_set_error
1098  #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_size
1099  #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_size
1100  #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_debug_assert_cube_as_mat
1101 
1102 #endif
1103 
1104 
1105 
1106 #if defined(ARMA_EXTRA_DEBUG)
1107 
1108  #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_bktprint
1109  #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_thisprint
1110  #define arma_extra_debug_print arma_print
1111  #define arma_extra_debug_warn arma_warn
1112  #define arma_extra_debug_check arma_check
1113 
1114 #else
1115 
1116  #define arma_extra_debug_sigprint true ? (void)0 : arma_bktprint
1117  #define arma_extra_debug_sigprint_this true ? (void)0 : arma_thisprint
1118  #define arma_extra_debug_print true ? (void)0 : arma_print
1119  #define arma_extra_debug_warn true ? (void)0 : arma_warn
1120  #define arma_extra_debug_check true ? (void)0 : arma_check
1121 
1122 #endif
1123 
1124 
1125 
1126 
1127 #if defined(ARMA_EXTRA_DEBUG)
1128 
1129  namespace junk
1130  {
1131  class arma_first_extra_debug_message
1132  {
1133  public:
1134 
1135  inline
1136  arma_cold
1137  arma_first_extra_debug_message()
1138  {
1139  union
1140  {
1141  unsigned short a;
1142  unsigned char b[sizeof(unsigned short)];
1143  } endian_test;
1144 
1145  endian_test.a = 1;
1146 
1147  const bool little_endian = (endian_test.b[0] == 1);
1148  const char* nickname = ARMA_VERSION_NAME;
1149 
1150  std::ostream& out = get_stream_err1();
1151 
1152  out << "@ ---" << '\n';
1153  out << "@ Armadillo "
1155  << " (" << nickname << ")\n";
1156 
1157  out << "@ arma_config::mat_prealloc = " << arma_config::mat_prealloc << " element(s)\n";
1158  out << "@ arma_config::atlas = " << arma_config::atlas << '\n';
1159  out << "@ arma_config::lapack = " << arma_config::lapack << '\n';
1160  out << "@ arma_config::blas = " << arma_config::blas << '\n';
1161  out << "@ arma_config::boost = " << arma_config::boost << '\n';
1162  out << "@ arma_config::boost_date = " << arma_config::boost_date << '\n';
1163  out << "@ arma_config::good_comp = " << arma_config::good_comp << '\n';
1164  out << "@ arma_config::extra_code = " << arma_config::extra_code << '\n';
1165  out << "@ sizeof(void*) = " << sizeof(void*) << '\n';
1166  out << "@ sizeof(uword) = " << sizeof(uword) << '\n';
1167  out << "@ sizeof(int) = " << sizeof(int) << '\n';
1168  out << "@ sizeof(long) = " << sizeof(long) << '\n';
1169  out << "@ sizeof(blas_int) = " << sizeof(blas_int) << '\n';
1170  out << "@ little_endian = " << little_endian << '\n';
1171  out << "@ ---" << std::endl;
1172  }
1173 
1174  };
1175 
1176  static arma_first_extra_debug_message arma_first_extra_debug_message_run;
1177  }
1178 
1179 #endif
1180 
1181 
1182 
int blas_int
void arma_sigprint(const char *x)
Definition: debug.hpp:235
void set_stream_err2(std::ostream &user_stream)
Definition: debug.hpp:65
void set_stream_err1(std::ostream &user_stream)
Definition: debug.hpp:56
static const uword mat_prealloc
Definition: arma_config.hpp:24
void arma_bktprint()
Definition: debug.hpp:248
const uword n_cols
const uword n_rows
void arma_hot arma_check_bad_alloc(const bool state, const T1 &x)
Definition: debug.hpp:368
static const unsigned int major
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
arma_inline void arma_hot arma_set_error(bool &err_state, char *&err_msg, const bool expression, const char *message)
Definition: debug.hpp:385
void arma_cold arma_print()
Definition: debug.hpp:184
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
void arma_assert_cube_as_mat(const Mat< eT > &M, const T1 &Q, const char *x, const bool check_compat_size)
Definition: debug.hpp:813
void arma_hot 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)
Definition: debug.hpp:459
static const bool blas
Definition: arma_config.hpp:44
u32 uword
Definition: typedef.hpp:85
const uword n_slices
const uword n_cols
number of columns in each slice (read-only)
Definition: Cube_bones.hpp:38
static const unsigned int patch
static const bool good_comp
Definition: arma_config.hpp:79
static const unsigned int minor
void arma_hot 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)
Definition: debug.hpp:968
std::ostream & get_stream_err1()
Definition: debug.hpp:74
std::ostream & get_stream_err2()
Definition: debug.hpp:83
std::string arma_cold 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)
Definition: debug.hpp:403
#define arma_ignore(variable)
Dense cube class.
Definition: Cube_bones.hpp:30
std::ostream & arma_stream_err2(std::ostream *user_stream)
Definition: debug.hpp:40
void arma_cold arma_stop(const T1 &x)
print a message to get_stream_err1() and/or throw a logic_error exception
Definition: debug.hpp:98
#define ARMA_VERSION_NAME
std::ostream & arma_stream_err1(std::ostream *user_stream)
Definition: debug.hpp:23
void arma_cold arma_bad(const T1 &x, const bool hurl=true)
print a message to get_stream_err2() and/or throw a run-time error exception
Definition: debug.hpp:150
void arma_cold arma_warn(const bool state, const T1 &x)
print a message to the warn stream
Definition: debug.hpp:298
static const bool boost_date
Definition: arma_config.hpp:58
void arma_cold arma_stop_bad_alloc(const T1 &x)
Definition: debug.hpp:126
Dense matrix class.
#define arma_inline
void arma_thisprint(const void *this_ptr)
Definition: debug.hpp:282
const uword n_cols
static const bool atlas
Definition: arma_config.hpp:30
static const bool boost
Definition: arma_config.hpp:51
static const bool lapack
Definition: arma_config.hpp:37
const uword n_rows
static const T1 & str_wrapper(const T1 &x, const typename string_only< T1 >::result *junk=0)
const uhword vec_state
0: matrix layout; 1: column vector layout; 2: row vector layout
Definition: Mat_bones.hpp:32
#define arma_hot
static const bool extra_code
Definition: arma_config.hpp:92
#define arma_cold
void arma_hot arma_check(const bool state, const T1 &x)
if state is true, abort program
Definition: debug.hpp:342
const uword n_slices
number of slices in the cube (read-only)
Definition: Cube_bones.hpp:40
const uword n_rows
number of rows in each slice (read-only)
Definition: Cube_bones.hpp:37


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:57