KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
m_matrix.h
Go to the documentation of this file.
1 /* ======================================================================== *
2  | |
3  | Copyright (c) 2007-2010, by members of University of Arizona Computer |
4  | Vision group (the authors) including |
5  | Kyle Simek, Andrew Predoehl, Ernesto Brau, Luca Del Pero |
6  | |
7  | For use outside the University of Arizona Computer Vision group please |
8  | contact Kobus Barnard. |
9  | |
10  * ======================================================================== */
11 
12 /* $Id: m_matrix.h 18931 2015-04-22 21:50:53Z cdawson $ */
13 
14 #ifndef MATRIX_WRAP_H
15 #define MATRIX_WRAP_H
16 
38 #include "m/m_matrix.h"
39 #include "m/m_mat_basic.h"
40 #include "m/m_mat_io.h"
41 #include "m_cpp/m_serialization.h"
42 #include "m_cpp/m_vector.h"
43 #include "m_cpp/m_concept.h"
44 #include "l_cpp/l_exception.h"
45 
46 #include <iosfwd>
47 
48 #ifdef KJB_HAVE_BST_SERIAL
49 #include <boost/serialization/access.hpp>
50 #endif
51 
52 #ifdef TEST
53 #include <boost/concept_check.hpp>
54 #endif /*TEST */
55 
56 
57 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
58 
59 
60 namespace kjb {
61 
72 class Matrix;
73 class Int_matrix;
74 class Index_range;
75 template <class Matrix_type>
77 
80 
83 
94 class Matrix
95 {
96 #ifdef KJB_HAVE_BST_SERIAL
97  friend class boost::serialization::access;
98 #endif
99  friend bool operator<( const Matrix& op1, const Matrix& op2 );
100 
101 public:
102 
103  /* Class users: to make your code as maintanable as possible, use the
104  * *_type typedefs below instead of directly referencing the specific
105  * type.
106  */
107 
108  typedef double Value_type;
110  typedef int Size_type;
111  typedef kjb_c::Matrix Impl_type;
112  typedef Matrix Mat_type;
113  typedef Vector Vec_type;
115 
116 private:
117 
118  Impl_type* m_matrix;
119 
129  void compute_row_col(
130  int index,
131  int* row,
132  int* col
133  ) const
134  {
135  // Test program was HERE.
136  *row = index / get_num_cols();
137  *col = index - *row * get_num_cols();
138  }
139 
148  void compute_row_col_carefully(
149  int index,
150  int* row,
151  int* col
152  ) const
153  {
154  if ( 0 == get_num_cols() )
155  {
156  // Test program was HERE.
157  *row = *col = 0;
158  }
159  else
160  {
161  // Test program was HERE.
162  compute_row_col( index, row, col );
163  }
164  }
165 
166  void throw_bad_bounds( int row_ix, int col_ix ) const;
167 
168 public:
169 
170  /* ------------------------------------------------------------------
171  * CONSTRUCTORS
172  * ------------------------------------------------------------------ */
173 
178  : m_matrix( 0 )
179  {
180  // Test program was HERE.
181  ETX( kjb_c::get_target_matrix( &m_matrix, 0, 0 ) );
182  }
183 
184  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
185 
189  Matrix(int rows, int cols)
190  : m_matrix( 0 )
191  {
192  // Test program was HERE.
193  ETX( kjb_c::get_target_matrix( &m_matrix, rows, cols ) );
194  }
195 
196  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
197 
202  Matrix(unsigned rows, unsigned cols)
203  : m_matrix( 0 )
204  {
205  // Test program was HERE.
206  Matrix m( static_cast<int>( rows ), static_cast<int>( cols ) );
207  swap( m );
208  }
209 
210  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
211 
216  Matrix(unsigned rows, unsigned cols, Value_type val)
217  : m_matrix( 0 )
218  {
219  // Test program was HERE.
220  Matrix m( static_cast<int>( rows ), static_cast<int>( cols ), val );
221  swap( m );
222  }
223 
224  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
225 
230  Matrix(unsigned long rows, unsigned long cols)
231  : m_matrix( 0 )
232  {
233  // Test program was HERE.
234  Matrix m( static_cast<int>( rows ), static_cast<int>( cols ) );
235  swap( m );
236  }
237 
238  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
239 
244  Matrix(unsigned long rows, unsigned long cols, Value_type val)
245  : m_matrix( 0 )
246  {
247  // Test program was HERE.
248  Matrix m( static_cast<int>( rows ), static_cast<int>( cols ), val );
249  swap( m );
250  }
251 
252  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
253 
257  Matrix(int rows, int cols, Value_type num)
258  : m_matrix( 0 )
259  {
260  // Test program was HERE.
261  ETX( kjb_c::get_initialized_matrix( &m_matrix, rows, cols, num ) );
262  }
263 
264  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
265 
272  Matrix(int rows, int cols, const Value_type* data);
273 
274  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
275 
279  Matrix ( const Vec_type& );
280 
281  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
282 
286  Matrix ( const Int_matrix& );
287 
288  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
289 
293  Matrix ( const Matrix_view& );
294 
295  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
296 
300  Matrix ( const Const_matrix_view& );
301 
302  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
303 
325  Matrix(Impl_type* mat_ptr)
326  : m_matrix( mat_ptr )
327  {
328  if ( 0 == mat_ptr )
329  {
330  // Test program was HERE.
331  ETX( kjb_c::get_target_matrix( &m_matrix, 0, 0 ) );
332  }
333  //else
334  //{
335  // // Test program was HERE.
336  //}
337  }
338 
339  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
340 
350  explicit Matrix(const Impl_type& mat_ref)
351  : m_matrix( 0 )
352  {
353  // Test program was HERE.
354  ETX( kjb_c::copy_matrix( &m_matrix, &mat_ref ) );
355  }
356 
357  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
358 
363  Matrix(const std::string& file_name);
364 
365  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
366 
370  Matrix(const Matrix& mat_ref)
371  : m_matrix( 0 )
372  {
373  // Test program was HERE.
374  ETX( kjb_c::copy_matrix( &m_matrix, mat_ref.m_matrix ) );
375  }
376 
377  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
378 
379 #ifdef KJB_HAVE_CXX11
380 
383  Matrix(Matrix&& mat_ref)
384  : m_matrix( nullptr )
385  {
386  m_matrix = mat_ref.m_matrix;
387  mat_ref.m_matrix = 0;
388  }
389 #endif /* KJB_HAVE_CXX11 */
390 
391  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
392 
393 
395  {
396  // Test program was HERE.
397  kjb_c::free_matrix( m_matrix );
398  }
399 
400  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
401 
402 
403 
411  /*Matrix& init_identity( int rank )
412  {
413  // Test program was HERE.
414  ETX( kjb_c::get_identity_matrix( &m_matrix, rank ) );
415  return *this;
416  }*/
417 
418  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
419 
420  //Matrix& init_euler_zxz(float phi, float theta, float psi, bool homogeneous = false) ;
421 
422  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
423 
430  Matrix& zero_out( int num_rows, int num_cols );
431 
432  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
433 
440  Matrix& zero_out( int rows );
441 
442  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
443 
449  Matrix& zero_out();
450 
451  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
452 
459 
460  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
461 
467  /*Matrix& init_zero(int num_rows)
468  {
469  // Test program was HERE.
470  return zero_out( num_rows );
471  }*/
472 
473 
474  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
475 
476 
477  /* ------------------------------------------------------------------
478  * ASSIGNMENT OPERATORS
479  * ------------------------------------------------------------------ */
480 
492  Matrix& operator=(const Impl_type& mat_ref);
493 
494  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
495 
501  Matrix& operator=(const Matrix& src)
502  {
503  // Test program was HERE.
504  // call assignment operator for kjb_c::Matrix
505  return operator=( *src.m_matrix );
506  }
507 
508  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
509 
510 #ifdef KJB_HAVE_CXX11
511 
514  Matrix& operator=(Matrix&& other)
515  {
516  if(this == &other)
517  return *this;
518 
519  kjb_c::free_matrix( m_matrix );
520  m_matrix = other.m_matrix;
521  other.m_matrix = 0;
522  return *this;
523  }
524 #endif /* KJB_HAVE_CXX11 */
525 
526 
527  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
528 
532  void swap( Matrix& other )
533  {
534  // Test program was HERE.
535  std::swap( m_matrix, other.m_matrix );
536  }
537 
538  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
539 
543  int get_num_rows() const
544  {
545  // Test program was HERE.
546  return m_matrix -> num_rows;
547  }
548 
549  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
550 
554  int get_num_cols() const
555  {
556  // Test program was HERE.
557  return m_matrix -> num_cols;
558  }
559 
560  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
561 
566  int get_length() const // rows * cols
567  {
568  // Test program was HERE.
569  return get_num_rows() * get_num_cols();
570  }
571 
572  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
573 
579  int size() const // rows * cols
580  {
581  // Test program was HERE.
582  return get_length();
583  }
584 
585  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
586 
592  {
593  return m_matrix;
594  }
595 
596  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
597 
601  const Impl_type* get_c_matrix() const
602  {
603  // Test program was HERE.
604  return m_matrix;
605  }
606 
607  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
608 
612  Matrix& resize(int new_rows, int new_cols, Value_type pad = Value_type(0));
613 
614  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
615 
619  Matrix& realloc(int new_rows, int new_cols)
620  {
621  ETX(kjb_c::get_target_matrix(&m_matrix, new_rows, new_cols));
622 
623  return *this;
624  }
625 
626  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
627 
631  Matrix& reserve(int new_rows, int new_cols)
632  {
633  int old_rows = m_matrix->num_rows;
634  int old_cols = m_matrix->num_cols;
635  this->resize(
636  std::max(new_rows, old_rows),
637  std::max(new_cols, old_cols));
638  this->resize(old_rows, old_cols);
639 
640  return *this;
641  }
642 
643  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
644 
650  Matrix transpose() const;
651 
652  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
653 
660  Matrix inverse() const;
661 
662  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
663 
668  double abs_of_determinant() const;
669 
670  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
671 
675  double trace() const;
676 
677  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
678 
683  Vec_type get_diagonal() const;
684 
685  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
686 
691  Int_matrix floor() const;
692 
693  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
694 
699  Int_matrix ceil() const;
700 
701  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
702 
706  Int_matrix threshold(double t) const;
707 
708  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
709 
717  void check_bounds( int row, int col ) const
718  {
719  if( row < 0 || get_num_rows() <= row
720  || col < 0 || get_num_cols() <= col )
721  {
722  // Test program was HERE.
723  throw_bad_bounds( row, col );
724  }
725  //else
726  //{
727  // // Test program was HERE.
728  //}
729  }
730 
731  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
732 
740  {
741  // Test program was HERE.
742  return operator()( i );
743  }
744 
745  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
746 
753  const Value_type& operator[](int i) const
754  {
755  // Test program was HERE.
756  return operator()( i );
757  }
758 
759  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
760 
768  {
769  // Test program was HERE.
770  return m_matrix->elements[0][i];
771  }
772 
773  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
774 
781  const Value_type& operator()(int i) const
782  {
783  // Test program was HERE.
784  return m_matrix->elements[0][i];
785  }
786 
787  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
788 
797  Value_type& operator()(int row, int col)
798  {
799  // Test program was HERE.
800  return m_matrix -> elements[ row ][ col ];
801  }
802 
803  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
804 
813  const Value_type& operator()(int row, int col) const
814  {
815  // Test program was HERE.
816  return m_matrix -> elements[ row ][ col ];
817  }
818 
819  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
820 
833  Matrix_view operator()(const Index_range& rows, const Index_range& cols);
834 
835  Const_matrix_view operator()(const Index_range& rows, const Index_range& cols) const;
836 
838 
840 
841  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
842 
847  Value_type& at(int i);
848 
849  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
850 
855  const Value_type& at(int i) const;
856 
857  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
858 
862  Value_type& at(int row, int col);
863 
864  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
865 
869  const Value_type& at(int row, int col) const;
870 
871  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
872 
877  Matrix& replace(int row, int col, const Matrix& A);
878 
879  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
880 
885  Matrix& vertcat(const Matrix& A);
886 
887  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
888 
895  Matrix& horzcat(const Matrix& A);
896 
897  /* ------------------------------------------------------------------
898  * EXTRACTION ROUTINES
899  * ------------------------------------------------------------------ */
900 
905  Vec_type get_row(int row) const;
906 
907  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
908 
913  Vec_type get_col(int col) const;
914 
915  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
916 
920  template<typename OutputIterator>
921  OutputIterator get_all_rows(OutputIterator result) const;
922 
923  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
924 
928  template<typename OutputIterator>
929  OutputIterator get_all_cols(OutputIterator result) const;
930 
931  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
932 
936  template <class Generic_vector>
937  void set_row(int row, const Generic_vector& v);
938 
939  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
940 
944  template <class Iterator>
945  void set_row(int row, Iterator begin, Iterator end);
946 
947  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
948 
953  template <class Generic_vector>
954  void set_col(int col, const Generic_vector& v);
955 
956  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
957 
961  template <class Iterator>
962  void set_col(int col, Iterator begin, Iterator end);
963 
964  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
965 
966  /*
967  * @brief fill all elements of a row
968  */
969  void fill_row(int row, Value_type x);
970 
971  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
972 
973  /*
974  * @brief fill all elements of a column
975  */
976  void fill_col(int col, Value_type x);
977 
978  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
979 
980 
987  Matrix submatrix(int row, int col, int num_rows, int num_cols) const
988  {
989  Matrix result;
990  ETX(copy_matrix_block(&result.m_matrix, m_matrix, row, col, num_rows, num_cols));
991  return result;
992  }
993 
994  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
995 
1006  int read(const char* filename = 0)
1007  {
1008  // Test program was HERE.
1009  return kjb_c::read_matrix( &m_matrix, filename );
1010  }
1011 
1012  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1013 
1021  int write( const char* filename = 0 ) const
1022  {
1023  // Test program was HERE.
1024  return kjb_c::write_matrix_full_precision( m_matrix, filename );
1025  }
1026 
1027  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1028 
1036  int write_raw( const char* filename = 0 ) const
1037  {
1038  // Test program was HERE.
1039  return kjb_c::write_raw_matrix( m_matrix, filename );
1040  }
1041 
1042  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1043 
1044  /* ------------------------------------------------------------------
1045  * ARITHMETIC OPERATORS
1046  * Modifying arithmetic operators. That is, operators that modify
1047  * this matrix when applied. The non-modifying arithmetic operators
1048  * are non-member functions (and are below).
1049  * ------------------------------------------------------------------ */
1050 
1059  Matrix& operator*=(const Matrix& op2)
1060  {
1061  ETX(kjb_c::multiply_matrices(&m_matrix, m_matrix, op2.m_matrix));
1062  return *this;
1063 
1064  }
1065 
1066  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1067 
1076  Matrix& multiply(const Matrix& op2)
1077  {
1078  // Test program was HERE.
1079  return operator*=( op2 );
1080  }
1081 
1082  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1083 
1088  {
1089  // Test program was HERE.
1090  ETX(kjb_c::ow_multiply_matrix_by_scalar(m_matrix, op2));
1091  return *this;
1092  }
1093 
1094  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1095 
1100  {
1101  // Test program was HERE.
1102  return operator*=( op2 );
1103  }
1104 
1105  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1106 
1115  {
1116  if( 0 == op2 )
1117  {
1118  // Test program was HERE.
1120  }
1121  //else
1122  //{
1123  // // Test program was HERE.
1124  //}
1125  return operator*=( 1.0 / op2 );
1126  }
1127 
1128  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1129 
1138  {
1139  // Test program was HERE.
1140  return operator/=( op2 );
1141  }
1142 
1143  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1144 
1147  {
1148  ETX(kjb_c::ow_scale_matrix_rows_by_sums(m_matrix));
1149  return *this;
1150  }
1151 
1152  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1153 
1158  {
1159  // if this is omitted, dimension mismatch might not be caught
1160  // int ow_add_matrices, if dimensions are an integer
1161  // multiple of one another
1162  if( op2.get_num_rows() != get_num_rows() ||
1163  op2.get_num_cols() != get_num_cols())
1165 
1166  // Test program was HERE.
1167  ETX(kjb_c::ow_add_matrices(m_matrix, op2.m_matrix));
1168  return *this;
1169  }
1170 
1171  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1172 
1176  Matrix& operator+= (double x);
1177 
1178  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1179 
1183  Matrix& add(const Matrix& op2)
1184  {
1185  // Test program was HERE.
1186  return operator+=( op2 );
1187  }
1188 
1189  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1190 
1195  {
1196  // if this is omitted, dimension mismatch might not be caught
1197  // int ow_subtract_matrices, if dimensions are an integer
1198  // multiple of one another
1199  if( op2.get_num_rows() != get_num_rows() ||
1200  op2.get_num_cols() != get_num_cols())
1202 
1203  // Test program was HERE.
1204  ETX(kjb_c::ow_subtract_matrices(m_matrix, op2.m_matrix));
1205  return *this;
1206  }
1207 
1208  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1209 
1214  Matrix& shift_rows_by(const Vector& v);
1215 
1220  Matrix& shift_columns_by(const Vector& v);
1221 
1226  Matrix& ew_multiply_rows_by(const Vector& v);
1227 
1232  Matrix& ew_multiply_by(const Matrix& m);
1233 
1234  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1235 
1239  Matrix& operator-= (double x);
1240 
1241  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1242 
1246  Matrix& subtract(const Matrix& op2)
1247  {
1248  // Test program was HERE.
1249  return operator-=( op2 );
1250  }
1251 
1252  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1253 
1259  {
1260  // Test program was HERE.
1261  return operator*=( Value_type(-1) );
1262  }
1263 
1264  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1265 
1272  Mat_type& mapcar( Mapper );
1273 
1274  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1275 
1276 
1277  // GRAPHICS FUNCTIONS
1278 
1281  (
1282  float phi,
1283  float theta,
1284  float psi
1285  );
1286 
1287  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1288 
1291  (
1292  float phi,
1293  float theta,
1294  float psi
1295  );
1296 
1297  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1298 
1300  (
1301  float phi,
1302  float theta,
1303  float psi
1304  );
1305 
1306  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1307 
1309  (
1310  float phi,
1311  float theta,
1312  float psi
1313  );
1314 
1315  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1316 
1318  (
1319  double phi,
1320  double x,
1321  double y,
1322  double z
1323  ) ;
1324 
1325 
1326  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1327 
1329  (
1330  double phi
1331  ) ;
1332 
1333  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1334 
1336  (
1337  double phi,
1338  double x,
1339  double y,
1340  double z
1341  ) ;
1342 
1343  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1344 
1346  (
1347  double phi
1348  ) ;
1349 
1350  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1351 
1353  (
1354  double phi,
1355  const Vector& vec
1356  ) ;
1357 
1358  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1359 
1361  (
1362  double phi,
1363  const Vector& vec
1364  ) ;
1365 
1366  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1367 
1369  (
1370  double phi,
1371  const Vector& vec
1372  ) ;
1373 
1374  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1375 
1377  (
1378  double phi,
1379  const Vector& vec
1380  ) ;
1381 
1382  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1383 
1385  (
1386  double phi,
1387  double x,
1388  double y,
1389  double z
1390  ) ;
1391 
1392  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1394  (
1395  double phi
1396  ) ;
1397 
1398  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1399 
1401  (
1402  double phi,
1403  double x,
1404  double y,
1405  double z
1406  ) ;
1407 
1408  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1409 
1411  (
1412  double phi
1413  ) ;
1414 
1415  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1416 
1418  (
1419  double phi,
1420  const Vector& vec
1421  ) ;
1422 
1423  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1424 
1426  (
1427  double phi,
1428  const Vector& vec
1429  ) ;
1430 
1431  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1432 
1434  (
1435  double phi,
1436  const Vector& vec
1437  ) ;
1438 
1439  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1440 
1442  (
1443  double phi,
1444  const Vector& vec
1445  ) ;
1446 
1447  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1448 
1450  (
1451  double x,
1452  double y,
1453  double z
1454  ) ;
1455 
1456  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1457 
1459  (
1460  double x,
1461  double y,
1462  double z
1463  ) ;
1464 
1465  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1466 
1468  (
1469  const Vector& vec
1470  ) ;
1471 
1472  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1473 
1475  (
1476  const Vector& vec
1477  ) ;
1478 
1479  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1480 
1482  (
1483  const Vector& vec
1484  ) ;
1485 
1486  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1487 
1489  (
1490  const Vector& vec
1491  ) ;
1492 
1493  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1494 
1496  (
1497  double x,
1498  double y,
1499  double z
1500  ) ;
1501 
1502  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1503 
1505  (
1506  double x,
1507  double y,
1508  double z
1509  ) ;
1510 
1511  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1512 
1514  (
1515  const Vector& vec
1516  ) ;
1517 
1518  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1519 
1521  (
1522  const Vector& vec
1523  ) ;
1524 
1525  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1526 
1528  (
1529  const Vector& vec
1530  ) ;
1531 
1532  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1533 
1535  (
1536  const Vector& vec
1537  ) ;
1538 
1539  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1540 
1542  (
1543  double x,
1544  double y,
1545  double z
1546  ) ;
1547 
1548  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1549 
1551  (
1552  double x,
1553  double y,
1554  double z
1555  ) ;
1556 
1557  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1558 
1560  (
1561  const Vector& vec
1562  ) ;
1563 
1564  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1565 
1567  (
1568  const Vector& vec
1569  ) ;
1570 
1571  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1572 
1574  (
1575  const Vector& vec
1576  ) ;
1577 
1578  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1579 
1581  (
1582  const Vector& vec
1583  ) ;
1584 
1585 
1586  int display(const char* title = NULL) const;
1587 
1588 
1589  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1590 
1593  {
1594  Matrix m(*this);
1595  return m.mapcar(f);
1596  }
1597 
1598 
1599  /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1600 
1601  Vec_type filter(bool (*f)(Value_type));
1602 
1603 
1609  Value_type (*f)(Value_type x, Value_type y),
1610  Value_type init = 0.0
1611  ) const;
1612 
1613 
1616  void ow_add_scalar(Value_type c);
1617 
1619  void ow_add_row_vector(const Vec_type v);
1620 
1622  void ow_add_col_vector(const Vec_type v);
1623 
1625  void ow_multiply_col_vector_ew(const Vec_type v);
1626 
1628  void ow_multiply_row_vector_ew(const Vec_type v);
1629 
1631  void ow_vertical_flip();
1632 
1634  void ow_horizontal_flip();
1635 
1636 private:
1638  template <class View_type>
1639  void init_from_view_(const View_type& mat_view);
1640 
1641  template<class Archive>
1642  void serialize(Archive &ar, const unsigned int version)
1643  {
1644  return kjb_serialize(ar, *this, version);
1645  }
1646 };
1647 
1648 
1649 /* ------------------------------------------------------------------
1650  * TEMPLATE MEMBERS
1651  * ------------------------------------------------------------------ */
1652 
1653 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1654 
1655 template<typename OutputIterator>
1656 OutputIterator Matrix::get_all_rows(OutputIterator result) const
1657 {
1658  for(int i = 0; i < get_num_rows(); i++)
1659  {
1660  *result++ = get_row(i);
1661  }
1662 
1663  return result;
1664 }
1665 
1666 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1667 
1668 template<typename OutputIterator>
1669 OutputIterator Matrix::get_all_cols(OutputIterator result) const
1670 {
1671  for(int i = 0; i < get_num_cols(); i++)
1672  {
1673  *result++ = get_col(i);
1674  }
1675 
1676  return result;
1677 }
1678 
1679 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1680 
1681 template <class Generic_vector>
1682 void Matrix::set_row( int row, const Generic_vector& v )
1683 {
1684  // Test program was HERE.
1685  using namespace boost;
1686 #ifdef TEST
1687  BOOST_CONCEPT_ASSERT((kjb::SimpleVector<Generic_vector>));
1688 
1689  typedef typename Generic_vector::value_type Vector_value_type;
1690  BOOST_CONCEPT_ASSERT((Convertible<Vector_value_type, Value_type>));
1691 #endif /*TEST */
1692 
1693  set_row(row, v.begin(), v.end());
1694 }
1695 
1696 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1697 
1698 template <class Iterator>
1699 void Matrix::set_row( int row, Iterator begin, Iterator end )
1700 {
1701  Iterator it = begin;
1702  for ( int col = 0; col < get_num_cols(); ++col )
1703  {
1704  if(it == end)
1705  {
1706  // range too short
1708  }
1709 
1710  operator()(row, col) = *it;
1711  it++;
1712  }
1713 
1714  if(it != end)
1715  {
1716  // range too long
1718  }
1719 }
1720 
1721 
1722 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1723 
1724 
1725 template <class Generic_vector>
1726 void Matrix::set_col(int col, const Generic_vector& v)
1727 {
1728  // Test program was HERE.
1729  using namespace boost;
1730 #ifdef TEST
1731  BOOST_CONCEPT_ASSERT((kjb::SimpleVector<Generic_vector>));
1732 
1733  typedef typename Generic_vector::value_type Vector_value_type;
1734  BOOST_CONCEPT_ASSERT((Convertible<Vector_value_type, Value_type>));
1735 #endif /*TEST */
1736 
1737  set_col(col, v.begin(), v.end());
1738 }
1739 
1740 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1741 
1742 template <class Iterator>
1743 void Matrix::set_col(int col, Iterator begin, Iterator end)
1744 {
1745  Iterator it = begin;
1746  for ( int row = 0; row < get_num_rows(); ++row )
1747  {
1748  if(it == end)
1749  {
1750  // range is too short
1752  }
1753 
1754  operator()(row, col) = *it;
1755  it++;
1756  }
1757 
1758  if(it != end)
1759  {
1760  // range is too short
1762  }
1763 
1764 }
1765 
1766 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1767 
1768 template <class View_type>
1769 void Matrix::init_from_view_(const View_type& mat_view)
1770 {
1771  Matrix result(mat_view.get_num_rows(), mat_view.get_num_cols() );
1772  for( int row = 0; row < mat_view.get_num_rows(); ++row )
1773  {
1774  for( int col = 0; col < mat_view.get_num_cols(); ++col )
1775  {
1776  result( row, col ) = mat_view( row, col );
1777  }
1778  }
1779  swap( result );
1780 }
1781 
1782 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1783 
1784 /* ------------------------------------------------------------------
1785  * "NAMED CONSTRUCTORS"
1786  * The "named constructor" idiom is when we use functions to create
1787  * objects. The benefit is that the names indicate the purpose of the
1788  * method. The following functions act as named constructors.
1789  * ------------------------------------------------------------------ */
1790 
1794 inline
1796 {
1797  // Test program was HERE.
1798  kjb_c::Matrix* result = 0;
1799  ETX( kjb_c::get_identity_matrix( &result, rank ) );
1800  return Matrix(result);
1801 }
1802 
1803 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1804 
1809 inline
1810 Matrix create_identity_matrix( int num_rows, int num_cols )
1811 {
1812  Matrix M = create_identity_matrix(num_rows);
1813  M.resize(num_rows, num_cols, 0.0);
1814  return M;
1815 }
1816 
1817 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1818 
1822 inline
1823 Matrix create_zero_matrix( int rows, int columns )
1824 {
1825  // Test program was HERE.
1826  kjb_c::Matrix* result = 0;
1827  ETX( kjb_c::get_zero_matrix( &result, rows, columns ) );
1828  return Matrix(result);
1829 }
1830 
1831 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1832 
1836 inline
1838 {
1839  // Test program was HERE.
1840  return create_zero_matrix( size, size );
1841 }
1842 
1843 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1844 
1852 inline
1853 Matrix create_random_matrix( int num_rows, int num_cols )
1854 {
1855  kjb_c::Matrix* c_mat = NULL;
1856  c_mat = kjb_c::create_random_matrix(num_rows, num_cols);
1857  return Matrix(c_mat);
1858 }
1859 
1860 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1861 
1869 Matrix create_gauss_random_matrix( int num_rows, int num_cols );
1870 
1871 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1872 
1877 
1878 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1879 
1883 Matrix create_diagonal_matrix(const Matrix::Vec_type& diagonal, size_t n);
1884 
1885 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1886 
1891 inline
1893 {
1894  kjb_c::Matrix* result = 0;
1895  kjb_c::get_identity_matrix(&result, size);
1896  kjb_c::ow_multiply_matrix_by_scalar(result, a);
1897  return Matrix(result);
1898 }
1899 
1900 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1901 
1905 Matrix create_row_matrix( const Vector& );
1906 
1907 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1908 
1912 Matrix create_column_matrix( const Vector& );
1913 
1914 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1915 
1916 /* ------------------------------------------------------------------
1917  * ARITHMETIC OPERATORS
1918  * Non-modifying arithmetic operators. That is, operators that do not
1919  * modify this matrix when applied. The modifying arithmetic operators
1920  * are member functions.
1921  * ------------------------------------------------------------------ */
1922 
1928 inline
1929 Matrix operator*(const Matrix& op1, const Matrix& op2)
1930 {
1931  // Test program was HERE.
1932  return Matrix(op1) *= op2;
1933 }
1934 
1935 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1936 
1941 inline
1943 {
1944  // Test program was HERE.
1945  return Matrix(op1) *= op2;
1946 }
1947 
1948 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1949 
1953 inline
1955 {
1956  // Test program was HERE.
1957  return op2 * op1;
1958 }
1959 
1960 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1961 
1962 
1969 inline
1971 {
1972  return Matrix(op1) /= op2;
1973 }
1974 
1975 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1976 
1980 inline
1981 Matrix operator+ (const Matrix& op1, const Matrix& op2)
1982 {
1983  // Test program was HERE.
1984  return Matrix(op1) += op2;
1985 }
1986 
1987 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
1988 
1992 inline
1993 Matrix operator+ (const Matrix& op1, double op2)
1994 {
1995  // Test program was HERE.
1996  return Matrix(op1) += op2;
1997 }
1998 
1999 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2000 
2004 inline
2005 Matrix operator- (const Matrix& op1, const Matrix& op2)
2006 {
2007  // Test program was HERE.
2008  return Matrix(op1) -= op2;
2009 }
2010 
2011 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2012 
2017 inline
2018 Matrix shift_rows_by(const Matrix& op1, const Vector& op2)
2019 {
2020  // Test program was HERE.
2021  return Matrix(op1).shift_rows_by(op2);
2022 }
2023 
2028 inline
2029 Matrix shift_columns_by(const Matrix& op1, const Vector& op2)
2030 {
2031  // Test program was HERE.
2032  return Matrix(op1).shift_columns_by(op2);
2033 }
2034 
2039 inline
2040 Matrix ew_multiply_rows_by(const Matrix& op1, const Vector& op2)
2041 {
2042  // Test program was HERE.
2043  return Matrix(op1).ew_multiply_rows_by(op2);
2044 }
2045 
2051 inline Matrix ew_multiply(const Matrix& op1, const Matrix& op2)
2052 {
2053  return Matrix(op1).ew_multiply_by(op2);
2054 }
2055 
2056 
2057 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2058 
2062 inline
2063 Matrix operator- (const Matrix& op1, double op2)
2064 {
2065  // Test program was HERE.
2066  return Matrix(op1) -= op2;
2067 }
2068 
2069 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2070 
2074 inline
2076 {
2077  // Test program was HERE.
2078  return op1 * (-1.0);
2079 }
2080 
2081 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2082 
2083 /* ------------------------------------------------------------------
2084  * COMPARISON OPERATORS
2085  * Comparison operators -- i.e., == and !=.
2086  * ------------------------------------------------------------------ */
2087 
2092 bool operator==(const Matrix& op1, const Matrix::Impl_type& op2);
2093 
2094 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2095 
2100 inline
2101 bool operator==(const Matrix& op1, const Matrix& op2)
2102 {
2103  // Test program was HERE.
2104  return op1 == *op2.get_c_matrix();
2105 }
2106 
2107 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2108 
2113 inline
2114 bool operator!=(const Matrix& op1, const Matrix::Impl_type& op2)
2115 {
2116  // Test program was HERE.
2117  return !(op1 == op2);
2118 }
2119 
2120 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2121 
2126 inline
2127 bool operator!=(const Matrix& op1, const Matrix& op2)
2128 {
2129  // Test program was HERE.
2130  return !(op1 == op2);
2131 }
2132 
2133 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2134 
2139 inline
2140 bool operator==( const Matrix::Impl_type& op1, const Matrix& op2 )
2141 {
2142  // Test program was HERE.
2143  return op2 == op1;
2144 }
2145 
2146 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2147 
2152 inline
2153 bool operator!=( const Matrix::Impl_type& op1, const Matrix& op2 )
2154 {
2155  // Test program was HERE.
2156  return op2 != op1;
2157 }
2158 
2159 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2160 
2164 inline
2165 bool operator<( const Matrix& op1, const Matrix& op2 )
2166 {
2167  return std::lexicographical_compare(
2168  &op1.m_matrix->elements[0][0],
2169  &op1.m_matrix->elements[0][0] + op1.get_length(),
2170  &op2.m_matrix->elements[0][0],
2171  &op2.m_matrix->elements[0][0] + op1.get_length());
2172 }
2173 
2174 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2175 
2176 /* ------------------------------------------------------------------
2177  * OTHER STUFF
2178  * Other stuff =)
2179  * ------------------------------------------------------------------ */
2180 
2184 Matrix matrix_inverse( const Matrix& op1 );
2185 
2186 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2187 
2191 inline
2193 {
2194  kjb_c::Matrix* kjb_matrix = 0;
2195  ETX( kjb_c::get_matrix_transpose( &kjb_matrix, op1.get_c_matrix() ) );
2196  return Matrix(kjb_matrix);
2197 }
2198 
2199 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2200 
2201 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2202 
2206 inline
2207 Matrix abs(const Matrix& mat)
2208 {
2209  // Test program was HERE.
2210  kjb_c::Matrix* result = 0;
2211  ETX( kjb_c::get_abs_of_matrix( &result, mat.get_c_matrix() ) );
2212  return Matrix(result);
2213 }
2214 
2218 inline
2219 double sum_squared_elements(const Matrix& mat)
2220 {
2221  // Test program was HERE.
2222  kjb_c::Matrix* result = 0;
2223  ETX( kjb_c::multiply_matrices_ew( &result, mat.get_c_matrix(), mat.get_c_matrix() ) );
2224  double res = kjb_c::sum_matrix_elements(result);
2225  kjb_c::free_matrix(result);
2226 
2227  return res;
2228 }
2229 
2230 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2231 
2241 Matrix::Value_type max_abs_difference( const Matrix& op1, const Matrix& op2 );
2242 
2243 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2244 
2248 inline
2250 {
2251  // Test program was HERE.
2252  return kjb_c::min_matrix_element(mat.get_c_matrix());
2253 }
2254 
2255 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2256 
2260 inline
2262 {
2263  // Test program was HERE.
2264  return kjb_c::max_matrix_element(mat.get_c_matrix());
2265 }
2266 
2267 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2268 
2275 std::ostream& operator<<(std::ostream& out, const Matrix& m);
2276 
2277 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2278 
2286 double det(const Matrix& mat);
2287 
2288 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2289 
2293 inline Matrix outer_product(const Vector& v1, const Vector& v2)
2294 {
2295  // these are copied in as row vectors
2296  Matrix m1(v1);
2297  Matrix m2(v2);
2298 
2299  return m1 * m2.transpose();
2300 }
2301 
2302 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2303 
2313 
2314 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2315 
2325 
2326 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2327 
2334 Int_matrix create_int_matrix_from_matrix_floor( const Matrix& );
2335 
2336 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2337 
2341 Int_matrix floor( const Matrix& m);
2342 
2343 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2344 
2351 Int_matrix create_int_matrix_from_matrix_ceil( const Matrix& );
2352 
2359 
2366 
2372 
2378 Matrix tile_matrix(Matrix trixy,unsigned m,unsigned n);
2379 
2380 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2381 
2392 Matrix tile_matrix(int tehnum,unsigned m,unsigned n);
2393 
2394 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
2395 
2399 inline void swap(Matrix& m1, Matrix& m2) { m1.swap(m2); }
2400 
2401 } //namespace kjb
2402 
2403 #endif
2404 
Matrix & multiply(Value_type op2)
Multiply this matrix by a scalar, in place.
Definition: m_matrix.h:1099
Int_matrix create_row_matrix(const Int_matrix::Vec_type &vec)
Construct a one-row matrix by deep-copying a vector.
Definition: l_int_matrix.cpp:105
friend bool operator<(const Matrix &op1, const Matrix &op2)
Returns true if a is lexicographically less-than b.
Definition: m_matrix.h:2165
Int_matrix ceil() const
Return the ceil(3) of each element of the matrix.
Definition: m_matrix.cpp:423
Matrix & multiply(const Matrix &op2)
Compute product of this matrix (on the left) and another, and replace this matrix with the result...
Definition: m_matrix.h:1076
#define ETX(a)
Definition: l_exception.h:67
Int_matrix::Value_type max(const Int_matrix &mat)
Return the maximum value in this matrix.
Definition: l_int_matrix.h:1397
void fill_row(int row, Value_type x)
Definition: m_matrix.cpp:628
void convert_to_3d_rotation_matrix(double phi, double x, double y, double z)
Definition: m_matrix.cpp:978
Matrix inverse() const
Invert this matrix.
Definition: m_matrix.cpp:404
static Matrix create_3d_scaling_matrix(double x, double y, double z)
Definition: m_matrix.cpp:1410
static Matrix create_3d_homo_scaling_matrix(double x, double y, double z)
Definition: m_matrix.cpp:1551
Matrix(unsigned long rows, unsigned long cols, Value_type val)
Ctor builds a matrix of specified number of rows and columns.
Definition: m_matrix.h:244
void set_col(int col, const Generic_vector &v)
Replace a column of the matrix with the given vector. "vector" can be any collection of values conver...
Definition: m_matrix.h:1726
Definition: m_concept.h:30
Matrix submatrix(int row, int col, int num_rows, int num_cols) const
Get the submatrix given by the parameters; i.e., get A(row, col, row + num_rows, col + num_cols)...
Definition: m_matrix.h:987
static Matrix create_3d_homo_rotation_matrix(double phi, double x, double y, double z)
Definition: m_matrix.cpp:1238
Matrix & operator/=(Value_type op2)
Divide each entry in the matrix by a scalar value.
Definition: m_matrix.h:1114
Int_matrix threshold(double t) const
Convert to a binary matrix; zero if value is below threshold, one if value is greater than or equal t...
Definition: m_matrix.cpp:439
Object thrown when an argument is of the wrong size or dimensions.
Definition: l_exception.h:426
const Generic_matrix_view< const Matrix > Const_matrix_view
Definition: m_matrix.h:79
void convert_to_3d_homo_scaling_matrix_from_vector(const Vector &vec)
Definition: m_matrix.cpp:1573
double Value_type
data type of the elements
Definition: m_matrix.h:108
void ow_add_col_vector(const Vec_type v)
add a column vector to each column of a matrix, in place
Definition: m_matrix.cpp:1856
Matrix(unsigned long rows, unsigned long cols)
Ctor builds a matrix of specified number of rows and columns.
Definition: m_matrix.h:230
This class implements matrices, in the linear-algebra sense, restricted to integer-valued elements...
Definition: l_int_matrix.h:71
int get_num_rows() const
Return the number of rows in the matrix.
Definition: m_matrix.h:543
int Size_type
size type of the elements
Definition: m_matrix.h:110
Impl_type *& get_underlying_representation_with_guilt()
Get pointer to the underlying kjb_c::Matrix C struct.
Definition: m_matrix.h:591
Matrix & realloc(int new_rows, int new_cols)
resize this matrix, losing previous data. Faster than resize(), because data copy is skipped...
Definition: m_matrix.h:619
void ow_vertical_flip()
flip the matrix vertically (swap last, first row, etc.)
Definition: m_matrix.cpp:1877
Int_matrix::Value_type max_abs_difference(const Int_matrix &op1, const Int_matrix &op2)
Find the largest difference between two matrices.
Definition: l_int_matrix.h:1364
theta
Definition: APPgetLargeConnectedEdges.m:108
Int_matrix create_diagonal_matrix(const Int_matrix::Vec_type &diagonal)
Construct a one-row matrix by deep-copying a vector.
Definition: l_int_matrix.cpp:118
double trace() const
Gets trace of this matrix.
Definition: m_matrix.cpp:667
void convert_to_3d_homo_rotation_matrix(double phi, double x, double y, double z)
Definition: m_matrix.cpp:1180
Matrix logical_and(Matrix a, Matrix b)
returns a matrix with 1s and 0s. 1 if both matricies have a non zero value in that position...
Definition: m_matrix.cpp:2086
double det(const Matrix &mat)
Definition: m_matrix.cpp:1931
Matrix & reserve(int new_rows, int new_cols)
allocate sufficient storage to hold the given dimensions, but leave actual matrix size unchanged...
Definition: m_matrix.h:631
Value_type & at(int i)
Access matrix like a one-dimensional array, using row-major ordering, and returning an lvalue...
Definition: m_matrix.cpp:232
Image operator-(const Image &im1, const Image &im2)
Subtract two images.
Definition: i_image.h:843
#define KJB_THROW(ex)
Definition: l_exception.h:46
Matrix outer_product(const Vector &v1, const Vector &v2)
Definition: m_matrix.h:2293
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Int_matrix create_column_matrix(const Int_matrix::Vec_type &vec)
Construct a one-column matrix by deep-copying a vector.
Definition: l_int_matrix.cpp:127
Value_type value_type
data type of the elements
Definition: m_matrix.h:109
Matrix & negate()
Transform this matrix into the additive inverse of its former value, in place.
Definition: m_matrix.h:1258
void ow_add_scalar(Value_type c)
add a scalar value to each element of a matrix, in place
Definition: m_matrix.cpp:1842
Matrix & operator=(const Impl_type &mat_ref)
Clone of square version of zero_out(int)
Definition: m_matrix.cpp:189
void set_row(int row, const Generic_vector &v)
Replace a row of the matrix with the given vector.
Definition: m_matrix.h:1682
Matrix(Impl_type *mat_ptr)
Conversion ctor: claim ownership of an existing matrix pointer (i.e., make a shallow copy)...
Definition: m_matrix.h:325
void convert_to_3d_homo_scaling_matrix(double x, double y, double z)
Definition: m_matrix.cpp:1522
void ow_add_row_vector(const Vec_type v)
add a row vector to each row of a matrix, in place
Definition: m_matrix.cpp:1849
void convert_to_3d_homo_translation_matrix_from_vector(const Vector &vec)
Definition: m_matrix.cpp:1706
Matrix(int rows, int cols, Value_type num)
Ctor builds a matrix of specified size, all entries set to num.
Definition: m_matrix.h:257
const Value_type & operator[](int i) const
Subscript matrix like a one-dimensional C array, e.g., A[10], using row-major ordering, and returning an rvalue.
Definition: m_matrix.h:753
Image operator+(const Image &op1, const Image &op2)
Add two images.
Definition: i_image.h:834
Value_type & operator()(int row, int col)
Access matrix like a Fortran or MATLAB two-dimensional array, e.g., A(2,4), and return an lvalue...
Definition: m_matrix.h:797
double abs_of_determinant() const
Gets the absolute value of the determinant of this matrix.
Definition: m_matrix.cpp:413
Matrix create_gauss_random_matrix(int num_rows, int num_cols)
Definition: m_matrix.cpp:344
Value_type & operator[](int i)
Subscript matrix like a one-dimensional C array, e.g., A[10], using row-major ordering, and returning an lvalue.
Definition: m_matrix.h:739
void kjb_serialize(Archive &ar, KJB_readable_writable &obj, const unsigned int version)
Definition: l_serialization.h:170
int write_raw(const char *filename=0) const
Writes the matrix contents to a file specified by name.
Definition: m_matrix.h:1036
~Matrix()
Definition: m_matrix.h:394
Matrix & limit_values(Value_type low, Value_type high)
Make sure all values in this matrix are between the two given values.
Definition: m_matrix.cpp:298
Generic_vector_view< Matrix > Matrix_vector_view
Definition: m_matrix.h:81
Matrix map(Value_type(*f)(Value_type)) const
Definition: m_matrix.h:1592
Matrix matrix_inverse(const Matrix &op1)
Invert this matrix.
Definition: m_matrix.cpp:730
static Matrix create_3d_homo_scaling_matrix_from_vector(const Vector &vec)
Definition: m_matrix.cpp:1615
Matrix Mat_type
the associated matrix type
Definition: m_matrix.h:112
static Matrix create_2d_rotation_matrix(double phi)
Definition: m_matrix.cpp:1059
int get_num_cols() const
Return the number of columns in the matrix.
Definition: m_matrix.h:554
Int_matrix create_int_matrix_from_matrix_ceil(const Matrix &mat)
Construct a matrix with elements equal to the ceiling, ceil() of a given floating-point Matrix...
Definition: m_matrix.cpp:1992
Vector Vec_type
the associated vector type
Definition: m_matrix.h:113
Int_matrix matrix_transpose(const Int_matrix &op1)
Test for any difference between two matrices.
Definition: l_int_matrix.h:1331
static Matrix create_euler_homo_rotation_matrix(float phi, float theta, float psi)
Definition: m_matrix.cpp:952
Matrix & operator=(const Matrix &src)
Assign contents from a kjb::Matrix, a C++ object.
Definition: m_matrix.h:501
Matrix & replace(int row, int col, const Matrix &A)
Replace a submatrix of this matrix with the given matrix.
Definition: m_matrix.cpp:757
void ow_horizontal_flip()
flip the matrix horizontally (swap left, right columns, etc.)
Definition: m_matrix.cpp:1884
kjb_c::Pixel abs(const kjb_c::Pixel &p)
Take the channel-wise absolute value of a kjb_c::Pixel.
Definition: i_pixel.h:354
static Matrix create_3d_scaling_matrix_from_vector(const Vector &vec)
Definition: m_matrix.cpp:1481
Definition: m_mat_view.h:55
Value_type(* Mapper)(Value_type)
element transformer fun
Definition: m_matrix.h:114
x
Definition: APPgetLargeConnectedEdges.m:100
const Value_type & operator()(int row, int col) const
Access matrix like a Fortran or MATLAB two-dimensional array, e.g., A(2,4), and return an rvalue...
Definition: m_matrix.h:813
void convert_to_euler_rotation_matrix(float phi, float theta, float psi)
Creates an euler rotation matrix without reallocating memory, when possible.
Definition: m_matrix.cpp:880
Matrix(const Impl_type &mat_ref)
Ctor copies contents (i.e., a deep copy) of an existing C-struct matrix.
Definition: m_matrix.h:350
Matrix create_zero_matrix(int rows, int columns)
Construct a zero matrix of specified size.
Definition: m_matrix.h:1823
Matrix & add(const Matrix &op2)
Add, in place, a matrix to this matrix.
Definition: m_matrix.h:1183
int size() const
Return the number of elements in the matrix. (alias of get_length)
Definition: m_matrix.h:579
static Matrix create_2d_homo_rotation_matrix(double phi)
Definition: m_matrix.cpp:1263
Vec_type filter(bool(*f)(Value_type))
Definition: m_matrix.cpp:1796
Matrix::Vec_type sum_matrix_rows(const Matrix &m)
Compute the matrix's sum down (a.k.a. columnar sum), like MATLAB.
Definition: m_matrix.cpp:1982
void convert_to_3d_rotation_matrix_from_vector(double phi, const Vector &vec)
Definition: m_matrix.cpp:1083
int display(const char *title=NULL) const
Definition: m_matrix.cpp:1785
void ow_multiply_col_vector_ew(const Vec_type v)
multiply a column vector by each column of a matrix, elementwise, in place
Definition: m_matrix.cpp:1863
Value_type reduce(Value_type(*f)(Value_type x, Value_type y), Value_type init=0.0) const
call function f using every element of the matrix as an input
Definition: m_matrix.cpp:1819
Matrix::Value_type max(const Matrix &mat)
Return the maximum value in this matrix.
Definition: m_matrix.h:2261
Matrix::Vec_type sum_matrix_cols(const Matrix &m)
Compute the matrix's sum across columns (a.k.a. row-wise sum)
Definition: m_matrix.cpp:1972
static Matrix create_euler_rotation_matrix(float phi, float theta, float psi)
Creates an euler rotation matrix and stores it into an instance of claa Matrix.
Definition: m_matrix.cpp:904
Matrix create_identity_matrix(int rank)
Construct an identity matrix of specified rank.
Definition: m_matrix.h:1795
Matrix & zero_out()
Clobber contents of matrix with zeroes.
Definition: m_matrix.cpp:292
Matrix & subtract(const Matrix &op2)
Subtract another matrix from this matrix, in place.
Definition: m_matrix.h:1246
Matrix(const Matrix &mat_ref)
Copy ctor.
Definition: m_matrix.h:370
Indexable ew_multiply(const Indexable &I, const Indexable &J)
Multiply the elements of two Indexable things. Must be indexed via operator() and assignable...
Definition: l_ew.h:43
Mat_type & mapcar(Mapper)
Transform the elements of a matrix.
Definition: m_matrix.cpp:739
std::ofstream & operator<<(std::ofstream &out, const Quaternion &q)
Definition: turntable_camera.cpp:77
Image operator/(const Image &op1, double op2)
Scale an image in channel space, yielding a new image.
Definition: i_image.h:825
Matrix(int rows, int cols)
Ctor builds a matrix of specified number of rows and columns.
Definition: m_matrix.h:189
Vec_type get_diagonal() const
Retrieves the diagonal of this matrix; returned as a vector.
Definition: m_matrix.cpp:652
bool operator!=(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for any difference between two matrices.
Definition: l_int_matrix.h:1274
Value_type & operator()(int i)
MATLAB-style one-dimensional subscript of matrix, e.g., A(10), using row-major ordering, and returning an lvalue.
Definition: m_matrix.h:767
Int_matrix floor() const
Return the floor(3) of each element of the matrix.
Definition: m_matrix.cpp:431
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
Matrix & divide(Value_type op2)
Divide each entry in the matrix by a scalar value.
Definition: m_matrix.h:1137
bool operator==(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for exact equality between two matrices.
Definition: l_int_matrix.cpp:218
Object thrown when an division is attempted with a zero divisor.
Definition: l_exception.h:450
Vec_type get_row(int row) const
Return a specified row of this matrix, in the form of a Vector.
Definition: m_matrix.cpp:604
Matrix & resize(int new_rows, int new_cols, Value_type pad=Value_type(0))
Resize this matrix, retaining previous values. Space is reused if possible. Otherwise requires a new ...
Definition: m_matrix.cpp:457
Matrix & operator+=(const Matrix &op2)
Add, in place, a matrix to this matrix.
Definition: m_matrix.h:1157
Definition: l_index.h:65
int read(const char *filename=0)
Reads the matrix contents from a file specified by name.
Definition: m_matrix.h:1006
Matrix transpose() const
Transpose this matrix.
Definition: m_matrix.cpp:395
Int_matrix::Value_type min(const Int_matrix &mat)
Return the minimum value in this matrix.
Definition: l_int_matrix.h:1385
Matrix & shift_rows_by(const Vector &v)
Shift each row by a vector, in place.
Definition: m_matrix.cpp:836
int write(const char *filename=0) const
Writes the matrix contents to a file specified by name.
Definition: m_matrix.h:1021
OutputIterator get_all_cols(OutputIterator result) const
Return all columns of this matrix into the provided iterator.
Definition: m_matrix.h:1669
static Matrix create_3d_homo_translation_matrix(double x, double y, double z)
Definition: m_matrix.cpp:1683
Matrix & vertcat(const Matrix &A)
Concat this matrix with another vertically. (named after the equivalent Matlab function) ...
Definition: m_matrix.cpp:774
void convert_to_euler_homo_rotation_matrix(float phi, float theta, float psi)
Definition: m_matrix.cpp:929
void convert_to_3d_scaling_matrix_from_vector(const Vector &vec)
Definition: m_matrix.cpp:1434
Definition: m_vec_view.h:56
Vec_type get_col(int col) const
Return a specified column of this matrix, in the form of a Vector.
Definition: m_matrix.cpp:613
Matrix & ew_multiply_rows_by(const Vector &v)
elementwise multiply each row by a vector, in place
Definition: m_matrix.cpp:852
const Impl_type * get_c_matrix() const
Get const pointer to the underlying kjb_c::Matrix C struct.
Definition: m_matrix.h:601
static Matrix create_3d_homo_rotation_matrix_from_vector(double phi, const Vector &vec)
Definition: m_matrix.cpp:1337
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
Definition: nr.cpp:237
Matrix()
Default ctor builds a matrix of zero rows, zero columns.
Definition: m_matrix.h:177
void convert_to_2d_homo_rotation_matrix(double phi)
Definition: m_matrix.cpp:1208
void convert_to_3d_scaling_matrix(double x, double y, double z)
Definition: m_matrix.cpp:1381
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
void convert_to_2d_rotation_matrix(double phi)
Definition: m_matrix.cpp:1006
Matrix & shift_columns_by(const Vector &v)
Shift each column by a vector, in place.
Definition: m_matrix.cpp:844
const Value_type & operator()(int i) const
MATLAB-style one-dimensional subscript of matrix, e.g., A(10), using row-major ordering, and returning an rvalue.
Definition: m_matrix.h:781
Matrix & scale_matrix_rows_by_sums()
something luca will document eventually
Definition: m_matrix.h:1146
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Matrix logical_or(Matrix a, Matrix b)
returns a matrix with 1s and 0s. 1 if either has a non zero value in that position, 0 otherwise
Definition: m_matrix.cpp:2032
static Matrix create_3d_rotation_matrix(double phi, double x, double y, double z)
Definition: m_matrix.cpp:1034
for m
Definition: APPgetLargeConnectedEdges.m:64
Matrix & operator-=(const Matrix &op2)
Subtract another matrix from this matrix, in place.
Definition: m_matrix.h:1194
Support for error handling exception classes in libKJB.
void swap(Matrix &other)
Swap the representations of two matrices.
Definition: m_matrix.h:532
Matrix tile_matrix(Matrix orig, unsigned m, unsigned n)
Construct a tiling of the given matrix.
Definition: m_matrix.cpp:2128
int get_length() const
Return the number of elements in the matrix.
Definition: m_matrix.h:566
kjb_c::Matrix Impl_type
the underlying implementation
Definition: m_matrix.h:111
double sum_squared_elements(const Matrix &mat)
Compute the sum of squared elements.
Definition: m_matrix.h:2219
OutputIterator get_all_rows(OutputIterator result) const
Return all rows of this matrix into the provided iterator.
Definition: m_matrix.h:1656
Int_matrix create_int_matrix_from_matrix_floor(const Matrix &mat)
Construct an Int_matrix with elements equal to the floor() of a given floating-point Matrix...
Definition: m_matrix.cpp:2009
Matrix & horzcat(const Matrix &A)
Concat this matrix with another horizontally. (named after the equivalent Matlab function) Because of...
Definition: m_matrix.cpp:796
void fill_col(int col, Value_type x)
Definition: m_matrix.cpp:640
static Matrix create_3d_rotation_matrix_from_vector(double phi, const Vector &vec)
Definition: m_matrix.cpp:1134
Gsl_Vector operator*(double scalar, const Gsl_Vector &vector)
multiply scalar and vector, scalar written on the left side
Definition: gsl_vector.h:661
void convert_to_3d_homo_translation_matrix(double x, double y, double z)
Definition: m_matrix.cpp:1654
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void check_bounds(int row, int col) const
Test whether the given row and column indices are valid.
Definition: m_matrix.h:717
Matrix(unsigned rows, unsigned cols, Value_type val)
Ctor builds a matrix of specified number of rows and columns.
Definition: m_matrix.h:216
void convert_to_3d_homo_rotation_matrix_from_vector(double phi, const Vector &vec)
Definition: m_matrix.cpp:1286
Matrix & operator*=(const Matrix &op2)
Compute product of this matrix (on the left) and another, and replace this matrix with the result...
Definition: m_matrix.h:1059
Matrix & ew_multiply_by(const Matrix &m)
elementwise multiply by another matrix
Definition: m_matrix.cpp:860
const Generic_vector_view< const Matrix > Const_matrix_vector_view
Definition: m_matrix.h:82
Matrix create_random_matrix(int num_rows, int num_cols)
Definition: m_matrix.h:1853
Generic_matrix_view< Matrix > Matrix_view
Definition: m_matrix.h:76
static Matrix create_3d_homo_translation_matrix_from_vector(const Vector &vec)
Definition: m_matrix.cpp:1753
void ow_multiply_row_vector_ew(const Vec_type v)
multiply a row vector by each row of a matrix, elementwise, in place
Definition: m_matrix.cpp:1870
Matrix(unsigned rows, unsigned cols)
Ctor builds a matrix of specified number of rows and columns.
Definition: m_matrix.h:202
Matrix logical_not(Matrix a)
returns a matrix with 1s and 0s. 1 if the value is 0, and 0 otherwise.
Definition: m_matrix.cpp:2108