Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

/home/r0/dav/atlas.dir/atlas3/sources/utilities/matrix.h

Go to the documentation of this file.
00001 /*!
00002 \file
00003   This is matrix.h
00004 */
00005 /*
00006   Copyright (C) 2004,2005 Fokko du Cloux
00007   part of the Atlas of Reductive Lie Groups
00008 
00009   See file main.cpp for full copyright notice
00010 */
00011 
00012 #ifndef MATRIX_H  /* guard against multiple inclusions */
00013 #define MATRIX_H
00014 
00015 #include <vector>
00016 
00017 #include "matrix_fwd.h"
00018 
00019 #include "setutils.h"
00020 #include "tags.h"
00021 
00022 namespace atlas {
00023 
00024 /******** function definitions ***********************************************/
00025 
00026 namespace matrix {
00027 
00028 template<typename C>
00029   void columnVectors(std::vector<std::vector<C> >& b,
00030                      const Matrix<C>& m);
00031 
00032 template<typename C>
00033 Matrix<C>& conjugate(Matrix<C>&, const Matrix<C>&);
00034 
00035 template<typename C>
00036 void extractBlock(Matrix<C>&, const Matrix<C>&, size_t, size_t, size_t,
00037                   size_t);
00038 
00039 template<typename C>
00040 void extractMatrix(Matrix<C>&, const Matrix<C>&,
00041                    const std::vector<size_t>&, const std::vector<size_t>&);
00042 
00043 template<typename C>
00044   void identityMatrix(Matrix<C>&, size_t);
00045 
00046 template<typename C>
00047   void initBasis(std::vector<std::vector<C> >&, size_t);
00048 
00049 template<typename C>
00050 Matrix<C>& invConjugate(Matrix<C>&, const Matrix<C>&);
00051 
00052 }
00053 
00054 /******** type definitions ***************************************************/
00055 
00056 namespace matrix {
00057 
00058 template<typename C> class Matrix {
00059   /*!
00060   We implement a matrix simply as a vector of elements, concatenating the
00061   rows.
00062   */
00063  public:
00064 
00065   typedef std::pair<size_t,size_t> index_pair;
00066 
00067  private:
00068 
00069   std::vector<C> d_data;
00070   size_t d_rows;
00071   size_t d_columns;
00072 
00073  public:
00074 
00075 // iterators
00076   typedef typename std::vector<C>::iterator iterator;
00077   typedef typename std::vector<C>::const_iterator const_iterator;
00078 
00079   iterator begin() {
00080     return d_data.begin();
00081   }
00082 
00083   iterator end() {
00084     return d_data.end();
00085   }
00086 
00087   const_iterator begin() const {
00088     return d_data.begin();
00089   }
00090 
00091   const_iterator end() const {
00092     return d_data.end();
00093   }
00094 
00095 // constructors and destructors
00096   Matrix()
00097     {}
00098 
00099   Matrix(size_t m, size_t n)
00100     :d_data(m*n),d_rows(m),d_columns(n)
00101     {}
00102 
00103   Matrix(size_t m, size_t n, const C& c)
00104     :d_data(m*n,c),d_rows(m),d_columns(n)
00105     {}
00106 
00107   explicit Matrix(size_t n)
00108     :d_data(n*n),d_rows(n),d_columns(n)
00109     {}
00110 
00111   explicit Matrix(const std::vector<std::vector<C> >&);
00112 
00113   Matrix(const Matrix<C> &, const std::vector<std::vector<C> >&);
00114 
00115   Matrix(const Matrix<C> &, size_t, size_t, size_t, size_t);
00116 
00117   template<typename I> Matrix(const Matrix<C>&, const I&, const I&);
00118 
00119   template<typename I> Matrix(const I&, const I&, tags::IteratorTag);
00120 
00121   virtual ~Matrix()
00122     {}
00123 
00124 // accessors
00125   const C& operator() (size_t i, size_t j) const {
00126     return d_data[i*d_columns+j];
00127   }
00128 
00129   bool operator== (const Matrix<C>&) const;
00130 
00131   index_pair absMinPos(size_t i_min = 0, size_t j_min = 0) const;
00132 
00133   void apply(std::vector<C>&, const std::vector<C>&) const;
00134 
00135   template<typename I, typename O> void apply(const I&, const I&, O) const;
00136 
00137   void column(std::vector<C>&, size_t) const;
00138 
00139   size_t columnSize() const {
00140     return d_rows;
00141   }
00142 
00143   bool divisible(C) const;
00144 
00145   Matrix<C> inverse() const
00146   {
00147     Matrix<C> result(*this); result.invert(); return result;
00148   }
00149 
00150   Matrix<C> inverse(C& d) const
00151   {
00152     Matrix<C> result(*this); result.invert(d); return result;
00153   }
00154 
00155   bool isEmpty() const {
00156     return d_data.size() == 0;
00157   }
00158 
00159   bool isZero(size_t i_min = 0, size_t j_min = 0) const;
00160 
00161   size_t numRows() const {
00162     return d_rows;
00163   }
00164 
00165   size_t numColumns() const {
00166     return d_columns;
00167   }
00168 
00169   void row(std::vector<C>&, size_t) const;
00170 
00171   size_t rowSize() const {
00172     return d_columns;
00173   }
00174 
00175   Matrix<C> transposed() const
00176   {
00177     Matrix<C> result(*this); result.transpose(); return result;
00178   }
00179 
00180   Matrix<C> negative_transposed() const
00181   {
00182     Matrix<C> result(*this); result.negate(); result.transpose();
00183     return result;
00184   }
00185 
00186 // manipulators
00187   C& operator() (size_t i, size_t j) {
00188     return d_data[i*d_columns+j];
00189   }
00190 
00191   Matrix<C>& operator+= (const Matrix<C>&);
00192 
00193   Matrix<C>& operator-= (const Matrix<C>&);
00194 
00195   Matrix<C>& operator*= (const Matrix<C>&);
00196 
00197   Matrix<C> operator* (const Matrix<C>&) const;
00198 
00199   Matrix<C>& leftMult (const Matrix<C>& p) { return *this=p * *this; }
00200 
00201   Matrix<C>& operator/= (const C& c);
00202 
00203   void changeColumnSign(size_t);
00204 
00205   void changeRowSign(size_t);
00206 
00207   void columnOperation(size_t, size_t, const C&);
00208 
00209   void copy(const Matrix<C>&, size_t r = 0, size_t c = 0);
00210 
00211   void copyColumn(const Matrix<C>&, size_t, size_t);
00212 
00213   void copyRow(const Matrix<C>&, size_t, size_t);
00214 
00215   void eraseColumn(size_t);
00216 
00217   void eraseRow(size_t);
00218 
00219   void invert();
00220 
00221   void invert(C& d);
00222 
00223   void permute(const setutils::Permutation& a);
00224 
00225   void negate();
00226 
00227   void reset() {
00228     d_data.assign(d_data.size(),0);
00229   }
00230 
00231   void resize(size_t, size_t);
00232 
00233   void resize(size_t, size_t, const C&);
00234 
00235   void rowOperation(size_t, size_t, const C&);
00236 
00237   void swap(Matrix&);
00238 
00239   void swapColumns(size_t, size_t);
00240 
00241   void swapRows(size_t, size_t);
00242 
00243   void transpose();
00244 };
00245 
00246 }
00247 
00248 }
00249 
00250 #include "matrix_def.h"
00251 
00252 #endif

Generated on Wed Mar 26 16:49:40 2008 for atlas by  doxygen 1.3.9.1