Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
cmat.h
1 /*
2 This file is distributed as part of the BIAS library (Basic ImageAlgorithmS)
3 but it has not been developed by the authors of BIAS.
4 
5 For copyright, author and license information see below.
6 */
7 
8 
9 /*
10 *
11 * Template Numerical Toolkit (TNT): Linear Algebra Module
12 *
13 * Mathematical and Computational Sciences Division
14 * National Institute of Technology,
15 * Gaithersburg, MD USA
16 *
17 *
18 * This software was developed at the National Institute of Standards and
19 * Technology (NIST) by employees of the Federal Government in the course
20 * of their official duties. Pursuant to title 17 Section 105 of the
21 * United States Code, this software is not subject to copyright protection
22 * and is in the public domain. The Template Numerical Toolkit (TNT) is
23 * an experimental system. NIST assumes no responsibility whatsoever for
24 * its use by other parties, and makes no guarantees, expressed or implied,
25 * about its quality, reliability, or any other characteristic.
26 *
27 * BETA VERSION INCOMPLETE AND SUBJECT TO CHANGE
28 * see http://math.nist.gov/tnt for latest updates.
29 *
30 */
31 
32 
33 
34 // C compatible matrix: row-oriented, 0-based [i][j] and 1-based (i,j) indexing
35 //
36 
37 #ifndef CMAT_H
38 #define CMAT_H
39 
40 #include "subscript.h"
41 #include "vec.h"
42 #include <cstdlib>
43 #include <cassert>
44 #include <iostream>
45 #include <iomanip>
46 #include <sstream>
47 #include <limits>
48 #include <cstring>
49 #include <cstdio>
50 
51 #ifdef TNT_USE_REGIONS
52 # include "region2d.h"
53 #endif
54 
55 #include <Base/Math/Utils.hh>
56 #include <Base/Debug/Error.hh>
57 
58 #ifdef BUILD_ALLOW_NON_INTEGRAL_MATRIX_ELEMENTS
59 #include <Base/Math/Polynom.hh>
60 #endif
61 
62 namespace TNT
63 {
64 
65  template <class T>
66  class Matrix
67  {
68 
69 
70  public:
71 
73  typedef T value_type;
74  typedef T element_type;
75  typedef T* pointer;
76  typedef T* iterator;
77  typedef T& reference;
78  typedef const T* const_iterator;
79  typedef const T& const_reference;
80 
81  Subscript lbound() const { return 1;}
82 
83  protected:
86  Subscript mn_; // total size
87  T* v_;
88  T** row_;
89  T* vm1_ ; // these point to the same data, but are 1-based
90  T** rowm1_;
91 
92  // internal helper function to create the array
93  // of row pointers
94 
96  {
97  mn_ = M*N;
98  m_ = M;
99  n_ = N;
100 
101  v_ = new T[mn_];
102  row_ = new T*[M];
103  rowm1_ = new T*[M];
104 
105  BIASASSERT(v_ != NULL);
106  BIASASSERT(row_ != NULL);
107  BIASASSERT(rowm1_ != NULL);
108 
109  T* p = v_;
110  vm1_ = v_ - 1;
111  for (Subscript i=0; i<M; i++)
112  {
113  row_[i] = p;
114  rowm1_[i] = p-1;
115  p += N ;
116 
117  }
118 
119  rowm1_ -- ; // compensate for 1-based offset
120  }
121 
122  void copy(const T* v)
123  {
124  Subscript N = m_ * n_;
125 #ifdef BUILD_ALLOW_NON_INTEGRAL_MATRIX_ELEMENTS
126  Subscript i;
127 
128  #ifdef TNT_UNROLL_LOOPS
129  Subscript Nmod4 = N & 3;
130  Subscript N4 = N - Nmod4;
131 
132  for (i=0; i<N4; i+=4)
133  {
134  v_[i] = v[i];
135  v_[i+1] = v[i+1];
136  v_[i+2] = v[i+2];
137  v_[i+3] = v[i+3];
138  }
139 
140  for (i=N4; i< N; i++)
141  v_[i] = v[i];
142  #else
143 
144  for (i=0; i< N; i++)
145  v_[i] = v[i];
146  #endif
147 #else
148  memcpy((void*) v_, (void*) v, sizeof(T)*N);
149 #endif
150  }
151 
152  void set(const T& val)
153  {
154  Subscript N = m_ * n_;
155  Subscript i;
156 
157 #ifdef TNT_UNROLL_LOOPS
158  Subscript Nmod4 = N & 3;
159  Subscript N4 = N - Nmod4;
160 
161  for (i=0; i<N4; i+=4)
162  {
163  v_[i] = val;
164  v_[i+1] = val;
165  v_[i+2] = val;
166  v_[i+3] = val;
167  }
168 
169  for (i=N4; i< N; i++)
170  v_[i] = val;
171 #else
172 
173  for (i=0; i< N; i++)
174  v_[i] = val;
175 
176 #endif
177  }
178 
179 
180 
181  void destroy()
182  {
183  /* do nothing, if no memory has been previously allocated */
184  if (v_ == NULL)
185  return ;
186 
187  /* if we are here, then matrix was previously allocated */
188  if (v_ != NULL) {
189  delete [] (v_); v_ = NULL;
190  }
191  if (row_ != NULL) {
192  delete [] (row_); row_ = NULL;
193  }
194 
195  /* return rowm1_ back to original value */
196  rowm1_ ++;
197  if (rowm1_ != NULL ) { delete [] (rowm1_); rowm1_ = NULL; }
198 
199  m_= mn_=n_ =0;
200  }
201 
202 
203  public:
204 
205  // Autocast operator causes collision with [] operator in WIN32,
206  // because subscription M[] is also possible via cast and
207  // [] operator on resulting array (streckel)
208  //operator T**(){ return row_; }
209  //operator T**() const { return row_; }
210 
211 
212  Subscript size() const { return mn_; }
213 
214  // constructors
215 
216  Matrix() : m_(0), n_(0), mn_(0), v_(NULL), row_(NULL), vm1_(NULL), rowm1_(NULL) {};
217 
218 
219  Matrix(const Matrix<T> &A)
220  {
221  initialize(A.m_, A.n_);
222  copy(A.v_);
223  }
224 
225  Matrix(Subscript M, Subscript N, const T& value = T())
226  {
227  initialize(M,N);
228  set(value);
229  }
230 
231  Matrix(Subscript M, Subscript N, const T* v)
232  {
233  initialize(M,N);
234  copy(v);
235  }
236 
237  //Matrix(Subscript M, Subscript N, const char *s)
238  //{
239  // initialize(M,N);
240  // std::istringstream ins(s);
241  // Subscript i, j;
242  // for (i=0; i<M; i++)
243  // for (j=0; j<N; j++)
244  // ins >> row_[i][j];
245  //}
246 
247  /// replacement for above JW
248  Matrix(Subscript M, Subscript N, const std::string & s)
249  {
250  initialize(M,N);
251  std::istringstream ins(s);
252  Subscript i, j;
253  for (i=0; i<M; i++)
254  for (j=0; j<N; j++)
255  ins >> row_[i][j];
256  }
257 
258 
259  // destructor
260  //
261  virtual ~Matrix()
262  {
263  destroy();
264  }
265 
266 
267  // reallocating
268  //
270  {
271  if (num_rows() == M && num_cols() == N)
272  return *this;
273 
274  destroy();
275  initialize(M,N);
276 
277  return *this;
278  }
279 
280 
281 
282 
283  // assignments
284  //
286  {
287  if (v_ == A.v_)
288  return *this;
289 
290  if (m_ == A.m_ && n_ == A.n_) // no need to re-alloc
291  copy(A.v_);
292 
293  else
294  {
295  destroy();
296  initialize(A.m_, A.n_);
297  copy(A.v_);
298  }
299 
300  return *this;
301  }
302 
303  Matrix<T>& operator=(const T& scalar)
304  {
305  set(scalar);
306  return *this;
307  }
308 
309 
311  {
312 #ifdef TNT_BOUNDS_CHECK
313  BIASASSERT( d >= 1);
314  BIASASSERT( d <= 2);
315 #endif
316  return (d==1) ? m_ : ((d==2) ? n_ : 0);
317  }
318 
319  Subscript num_rows() const { return m_; }
320  Subscript num_cols() const { return n_; }
321 
322 
323 
324 
325  inline T* operator[](Subscript i)
326  {
327 #ifdef TNT_BOUNDS_CHECK
328  BIASASSERT(0<=i);
329  BIASASSERT(i < m_) ;
330 #endif
331  return row_[i];
332  }
333 
334  inline const T* operator[](Subscript i) const
335  {
336 #ifdef TNT_BOUNDS_CHECK
337  BIASASSERT(0<=i);
338  BIASASSERT(i < m_) ;
339 #endif
340  return row_[i];
341  }
342 
344  {
345 #ifdef TNT_BOUNDS_CHECK
346  BIASASSERT(1<=i);
347  BIASASSERT(i <= mn_) ;
348 #endif
349  return vm1_[i];
350  }
351 
353  {
354 #ifdef TNT_BOUNDS_CHECK
355  BIASASSERT(1<=i);
356  BIASASSERT(i <= mn_) ;
357 #endif
358  return vm1_[i];
359  }
360 
361 
362 
364  {
365 #ifdef TNT_BOUNDS_CHECK
366  BIASASSERT(1<=i);
367  BIASASSERT(i <= m_) ;
368  BIASASSERT(1<=j);
369  BIASASSERT(j <= n_);
370 #endif
371  return rowm1_[i][j];
372  }
373 
374 
375 
377  {
378 #ifdef TNT_BOUNDS_CHECK
379  BIASASSERT(1<=i);
380  BIASASSERT(i <= m_) ;
381  BIASASSERT(1<=j);
382  BIASASSERT(j <= n_);
383 #endif
384  return rowm1_[i][j];
385  }
386 
387 
388 
389 #ifdef TNT_USE_REGIONS
390 
391  typedef Region2D<Matrix<T> > Region;
392 
393 
394  Region operator()(const Index1D &I, const Index1D &J)
395  {
396  return Region(*this, I,J);
397  }
398 
399 
400  typedef const_Region2D< Matrix<T> > const_Region;
401  const_Region operator()(const Index1D &I, const Index1D &J) const
402  {
403  return const_Region(*this, I,J);
404  }
405 #endif
406 
407  /** @author Sandro Esquivel */
408  inline
409  std::ostream&
410  PrintPretty(std::ostream &s,
411  const std::string &name = "",
412  const int width = 8,
413  const bool alignLeft = true) const;
414 
415  /** @author Ingo Schiller */
416  inline
417  std::ostream&
418  Print(std::ostream &s,
419  const int width,
420  const int precision,
421  bool scientific=true) const;
422 
423  /** @author Jan Woetzel */
424  inline
425  std::ostream&
426  Print(std::ostream &s,
427  const bool intCastOutput=false,
428  const bool binaryOutput=false,
429  const bool forceFullPrecision=false ) const;
430 
431 
432  /** @author Jan Woetzel */
433  inline
434  std::istream&
435  Read(std::istream &s,
436  const bool intCastInput=false,
437  const bool binaryInput=false );
438 
439  }; // ------------------ class ------------------------
440 
441 
442 
443 
444  /* *************************** I/O ********************************/
445 
446  /** @relates Matrix
447  @author Sandro Esquivel
448  */
449  template <class T>
450  inline std::ostream& Matrix<T>::
451  PrintPretty(std::ostream &s, const std::string &name,
452  const int width, const bool alignLeft) const
453  {
454  const int m = this->num_rows();
455  const int n = this->num_cols();
456  const int w = width + 8;
457  std::ios_base::fmtflags oldFlags = s.flags(); // store flags
458  std::string leftspace = "";
459  if (!name.empty()) {
460  s << std::endl << name << " =";
461  leftspace = name + " ";
462  for (unsigned int i = 0; i < name.size(); i++)
463  leftspace.at(i) = ' ';
464  } else {
465  s << std::endl;
466  }
467  char chars[128];
468  for (int i = 0; i < m; i++) {
469  if (i > 0)
470  s << leftspace;
471  s << " [ ";
472  for (int j = 0; j < n; j++) {
473 #if WIN32
474  sprintf_s(chars, "% .8g", (double)(*this)[i][j]);
475 #else
476  sprintf(chars, "% .8g", (double)(*this)[i][j]);
477 #endif
478  std::string str(chars);
479  if (alignLeft) s << str;
480  for (int k = 0; k < w - (int)str.size(); k++)
481  s << " ";
482  if (!alignLeft) s << str;
483  }
484  s << " ]" << std::endl;
485  }
486  s.flags(oldFlags); // restore flags
487  return s;
488  }
489 
490  /** @relates Matrix
491  @author Ingo Schiller */
492 
493  template <class T>
494  inline
495  std::ostream&
496  Matrix<T>::Print(std::ostream &s,
497  const int width,
498  const int precision,
499  bool scientific) const
500  {
501  int M=this->num_rows();
502  int N=this->num_cols();
503 
504  std::ios_base::fmtflags oldFlags = s.flags(); // push
505 
506  s<<std::setw(width);
507  s<<std::setprecision(precision);
508  // header with dimensions
509  s<<M<<" "<<N<<"\n";
510 
511  if(scientific) s<<std::scientific;
512 
513  // s.setf(std::ios_base::left, std::ios_base::adjustfield);
514  for (int i=0; i<M; i++)
515  {
516  for (int j=0; j<N; j++)
517  {
518  s<<std::setw( width );
519  s<<std::setprecision( precision );
520  s<<(*this)[i][j];
521  s<<" ";
522  }
523  s<<"\n";
524  }
525  s.flags(oldFlags); // pop
526  return s;
527  }
528 
529  /** @relates Matrix
530  @author Jan Woetzel */
531 
532  template <class T>
533  inline
534  std::ostream&
535  Matrix<T>::Print(std::ostream &s,
536  const bool intCastOutput,
537  const bool binaryOutput,
538  const bool forceFullPrecision) const
539  {
540  int M=this->num_rows();
541  int N=this->num_cols();
542 
543  std::ios_base::fmtflags oldFlags = s.flags(); // push
544 
545  s<<std::setprecision(std::numeric_limits<int>::digits10 +1 );
546  // header with dimensions
547  s<<M<<" "<<N;
548 
549  unsigned int dig(0), w(0);
550 
551  if (BIAS::IsConsoleStream(s) && (!forceFullPrecision)){
552  // cout or cerr uses shorter human redable format with less precision
553  dig = std::numeric_limits<T>::digits10;
554  w=dig+1;
555  } else {
556  dig = BIAS::DecimalsToStore<T>();
557  w=dig+8;
558  // binary or ascii output?
559  if (binaryOutput){
560  s<< " b";
561  BIASERR("not implemented");
562  BIASBREAK;
563  //s<<std::binary;
564  } else {
565  s<<std::scientific;
566  }
567  }
568  s<<"\n"; //<< header line done
569 
570  //#ifdef TNT_BOUNDS_CHECK
571  BIASASSERT(dig>0);
572  BIASASSERT(w>0);
573  //#endif
574 
575  // s.setf(std::ios_base::left, std::ios_base::adjustfield);
576  for (int i=0; i<M; i++)
577  {
578  for (int j=0; j<N; j++)
579  {
580  s<<std::setw( w );
581  s<<std::setprecision( dig );
582 #ifndef BUILD_ALLOW_NON_INTEGRAL_MATRIX_ELEMENTS
583  if (intCastOutput){
584  s<<(int)((*this)[i][j]);
585  } else
586 #endif
587  {
588  s<<(*this)[i][j];
589  }
590  s<<" ";
591  }
592  s<<"\n";
593  }
594 
595  s.flags(oldFlags); // pop
596 
597  return s;
598  }
599 
600 
601  /// JW
602  template <class T>
603  inline
604  std::istream&
605  Matrix<T>::Read(std::istream &s,
606  const bool intCastInput,
607  const bool binaryInput)
608  {
609  if (binaryInput){
610  BIASERR("not implemented");
611  BIASBREAK;
612  }
613  int M=0, N=0;
614  s>>M>>N;
615  if (M<0 || N<0) {
616  BIASERR("could not read from stream. wrong format?");
617  BIASBREAK;
618  s.setstate(std::ios::badbit | std::ios::failbit);
619  return s;
620  }
621  if ( !(M==this->num_rows() && N==this->num_cols() ))
622  {
623  this->newsize(M,N);
624  }
625 
626 #ifndef BUILD_ALLOW_NON_INTEGRAL_MATRIX_ELEMENTS
627  if (intCastInput){
628 
629  // << was doing cast to int, e.g. for char
630  int tmp (0);
631  for (int i=0; i<M; i++){
632  for (int j=0; j<N; j++){
633  s>>tmp;
634  //#ifdef TNT_BOUNDS_CHECK
635  BIASASSERT((long)tmp>=(long)std::numeric_limits<T>::min() );
636  BIASASSERT((long)tmp<=(long)std::numeric_limits<T>::max() );
637  //#endif
638  this->row_[i][j] = (T)tmp;
639  }
640  }
641 
642  } else
643 #endif
644  {
645 
646  // no cast required
647  for (int i=0; i<M; i++){
648  for (int j=0; j<N; j++)
649  {
650  //s >> ((this)[i][j]);
651  s>>this->row_[i][j];
652  }
653  }
654 
655  }
656  return s;
657  }
658 
659 
660 
661  /** @relates Matrix @author Jan Woetzel */
662  inline
663  std::ostream& operator<<(std::ostream &s, const Matrix<char> &A)
664  {
665  return A.Print(s, true); // cast to int
666  }
667 
668  /** @relates Matrix @author Jan Woetzel */
669  inline
670  std::ostream& operator<<(std::ostream &s, const Matrix<unsigned char> &A)
671  {
672  return A.Print(s, true ); // cast to int
673  }
674 
675 #ifdef BUILD_ALLOW_NON_INTEGRAL_MATRIX_ELEMENTS
676  inline
677  std::ostream& operator<<(std::ostream &s, const Matrix<BIAS::Polynom> &A)
678  {
679  int M=A.num_rows();
680  int N=A.num_cols();
681 
682  s<<M<<" "<<N << "\n";
683  for (int i=0; i<M; i++) {
684  for (int j=0; j<N; j++) {
685  s << i << "," << j << " -> " << A[i][j] << "\n";
686  }
687  }
688  return s;
689  }
690 #endif
691 
692  /** @relates Matrix @author Jan Woetzel */
693  template <class T>
694  inline
695  std::ostream& operator<<(std::ostream &s, const Matrix<T> &A)
696  {
697  return A.Print(s);
698  }
699 
700 
701  /** @relates Matrix @author Jan Woetzel */
702  inline
703  std::istream& operator>>(std::istream &s, Matrix<unsigned char> &A)
704  {
705  return A.Read(s, true); // cast to int
706  }
707 
708 
709  /** @relates Matrix @author Jan Woetzel */
710  inline
711  std::istream& operator>>(std::istream &s, Matrix<char> &A)
712  {
713  return A.Read(s, true); // cast to int
714  }
715 
716  /** @relates Matrix @author Jan Woetzel */
717  template <class T>
718  inline
719  std::istream& operator>>(std::istream &s, Matrix<T> &A)
720  {
721  return A.Read(s);
722  }
723 
724 
725  // *******************[ basic matrix algorithms ]***************************
726 
727  /** @relates Matrix
728  */
729  template <class T>
731  const Matrix<T> &B)
732  {
733  Subscript M = A.num_rows();
734  Subscript N = A.num_cols();
735 
736  BIASASSERT(M==B.num_rows());
737  BIASASSERT(N==B.num_cols());
738 
739  Matrix<T> tmp(M,N);
740  Subscript i,j;
741 
742  for (i=0; i<M; i++)
743  for (j=0; j<N; j++)
744  tmp[i][j] = A[i][j] + B[i][j];
745 
746  return tmp;
747  }
748 
749  /** @relates Matrix
750  */
751  template <class T>
753  const Matrix<T> &B)
754  {
755  Subscript M = A.num_rows();
756  Subscript N = A.num_cols();
757 
758  BIASASSERT(M==B.num_rows());
759  BIASASSERT(N==B.num_cols());
760 
761  Matrix<T> tmp(M,N);
762  Subscript i,j;
763 
764  for (i=0; i<M; i++)
765  for (j=0; j<N; j++)
766  tmp[i][j] = A[i][j] - B[i][j];
767 
768  return tmp;
769  }
770 
771  template <class T>
773  const Matrix<T> &B)
774  {
775  Subscript M = A.num_rows();
776  Subscript N = A.num_cols();
777 
778  BIASASSERT(M==B.num_rows());
779  BIASASSERT(N==B.num_cols());
780 
781  Matrix<T> tmp(M,N);
782  Subscript i,j;
783 
784  for (i=0; i<M; i++)
785  for (j=0; j<N; j++)
786  tmp[i][j] = A[i][j] * B[i][j];
787 
788  return tmp;
789  }
790 
791 
792  template <class T>
794  {
795  Subscript M = A.num_rows();
796  Subscript N = A.num_cols();
797 
798  Matrix<T> S(N,M);
799  Subscript i, j;
800 
801  for (i=0; i<M; i++)
802  for (j=0; j<N; j++)
803  S[j][i] = A[i][j];
804 
805  return S;
806  }
807 
808 
809 
810  template <class T>
811  inline Matrix<T> matmult(const Matrix<T> &A,
812  const Matrix<T> &B)
813  {
814 
815 #ifdef TNT_BOUNDS_CHECK
816  BIASASSERT(A.num_cols() == B.num_rows());
817 #endif
818 
819  Subscript M = A.num_rows();
820  Subscript N = A.num_cols();
821  Subscript K = B.num_cols();
822 
823  Matrix<T> tmp(M,K);
824  T sum;
825 
826  for (Subscript i=0; i<M; i++)
827  for (Subscript k=0; k<K; k++)
828  {
829  sum = 0;
830  for (Subscript j=0; j<N; j++)
831  sum = sum + A[i][j] * B[j][k];
832 
833  tmp[i][k] = sum;
834  }
835 
836  return tmp;
837  }
838 
839  /** @relates Matrix
840  */
841  template <class T>
842  inline Matrix<T> operator*(const Matrix<T> &A,
843  const Matrix<T> &B)
844  {
845  return matmult(A,B);
846  }
847 
848  template <class T>
849  inline int matmult(Matrix<T>& C, const Matrix<T> &A,
850  const Matrix<T> &B)
851  {
852 
853  BIASASSERT(A.num_cols() == B.num_rows());
854 
855  Subscript M = A.num_rows();
856  Subscript N = A.num_cols();
857  Subscript K = B.num_cols();
858 
859  C.newsize(M,K);
860 
861  T sum;
862 
863  const T* row_i;
864  const T* col_k;
865 
866  for (Subscript i=0; i<M; i++)
867  for (Subscript k=0; k<K; k++)
868  {
869  row_i = &(A[i][0]);
870  col_k = &(B[0][k]);
871  sum = 0;
872  for (Subscript j=0; j<N; j++)
873  {
874  sum += *row_i * *col_k;
875  row_i++;
876  col_k += K;
877  }
878  C[i][k] = sum;
879  }
880 
881  return 0;
882  }
883 
884 
885  template <class T>
886  Vector<T> matmult(const Matrix<T> &A, const Vector<T> &x)
887  {
888 
889 #ifdef TNT_BOUNDS_CHECK
890  BIASASSERT(A.num_cols() == x.dim());
891 #endif
892 
893  Subscript M = A.num_rows();
894  Subscript N = A.num_cols();
895 
896  Vector<T> tmp(M);
897  T sum;
898 
899  for (Subscript i=0; i<M; i++)
900  {
901  sum = 0;
902  const T* rowi = A[i];
903  for (Subscript j=0; j<N; j++)
904  sum = sum + rowi[j] * x[j];
905 
906  tmp[i] = sum;
907  }
908 
909  return tmp;
910  }
911 
912 
913  /** @relates Matrix */
914  template <class T>
915  inline Vector<T> operator*(const Matrix<T> &A, const Vector<T> &x)
916  {
917  return matmult(A,x);
918  }
919 
920 } // namespace TNT
921 
922 #endif
923 // CMAT_H
Matrix< T > & operator=(const Matrix< T > &A)
Definition: cmat.h:285
Matrix< T > transpose(const Matrix< T > &A)
Definition: cmat.h:793
std::ostream & PrintPretty(std::ostream &s, const std::string &name="", const int width=8, const bool alignLeft=true) const
Subscript num_cols() const
Definition: cmat.h:320
void set(const T &val)
Definition: cmat.h:152
std::istream & operator>>(std::istream &s, Matrix< T > &A)
Definition: cmat.h:719
T * vm1_
Definition: cmat.h:89
void destroy()
Definition: cmat.h:181
Subscript mn_
Definition: cmat.h:86
Matrix< T > operator*(const Matrix< T > &A, const Matrix< T > &B)
Definition: cmat.h:842
T & reference
Definition: cmat.h:77
bool IsConsoleStream(const std::ostream &os)
Helper returning true on console ostreams like cerr, cout Useful to distinguish between console (cout...
Definition: Utils.hh:54
Matrix< T > & newsize(Subscript M, Subscript N)
Definition: cmat.h:269
Matrix< T > operator-(const Matrix< T > &A, const Matrix< T > &B)
Definition: cmat.h:752
const T * const_iterator
Definition: cmat.h:78
Matrix< T > operator+(const Matrix< T > &A, const Matrix< T > &B)
Definition: cmat.h:730
Vector< T > operator*(const Matrix< T > &A, const Vector< T > &x)
Definition: cmat.h:915
TNT_SUBSCRIPT_TYPE Subscript
Definition: subscript.h:55
Matrix< T > mult_element(const Matrix< T > &A, const Matrix< T > &B)
Definition: cmat.h:772
Subscript m_
Definition: cmat.h:84
reference operator()(Subscript i, Subscript j)
Definition: cmat.h:363
Subscript dim() const
Definition: vec.h:257
T * v_
Definition: cmat.h:87
void initialize(Subscript M, Subscript N)
Definition: cmat.h:95
T element_type
Definition: cmat.h:74
std::istream & Read(std::istream &s, const bool intCastInput=false, const bool binaryInput=false)
JW.
Definition: cmat.h:605
std::ostream & Print(std::ostream &s, const int width, const int precision, bool scientific=true) const
Matrix< T > matmult(const Matrix< T > &A, const Matrix< T > &B)
Definition: cmat.h:811
T * iterator
Definition: cmat.h:76
Subscript size_type
Definition: cmat.h:72
Subscript n_
Definition: cmat.h:85
T * pointer
Definition: cmat.h:75
void copy(const T *v)
Definition: cmat.h:122
Subscript lbound() const
Definition: cmat.h:81
Matrix(const Matrix< T > &A)
Definition: cmat.h:219
Matrix()
Definition: cmat.h:216
std::istream & operator>>(std::istream &s, Matrix< char > &A)
Definition: cmat.h:711
T ** row_
Definition: cmat.h:88
reference operator()(Subscript i)
Definition: cmat.h:343
T ** rowm1_
Definition: cmat.h:90
Matrix< T > & operator=(const T &scalar)
Definition: cmat.h:303
Subscript size() const
Definition: cmat.h:212
Matrix(Subscript M, Subscript N, const std::string &s)
replacement for above JW
Definition: cmat.h:248
T value_type
Definition: cmat.h:73
const T * operator[](Subscript i) const
Definition: cmat.h:334
Subscript num_rows() const
Definition: cmat.h:319
T * operator[](Subscript i)
Definition: cmat.h:325
Matrix(Subscript M, Subscript N, const T *v)
Definition: cmat.h:231
const_reference operator()(Subscript i) const
Definition: cmat.h:352
virtual ~Matrix()
Definition: cmat.h:261
Subscript dim(Subscript d) const
Definition: cmat.h:310
const T & const_reference
Definition: cmat.h:79
std::istream & operator>>(std::istream &s, Matrix< unsigned char > &A)
Definition: cmat.h:703