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

Matrix.h

Go to the documentation of this file.
00001 #ifndef ATLFAST_MATRIX_H
00002 #define ATLFAST_MATRIX_H
00003 #include <valarray>
00004 #include "AtlfastUtils/Slice_iter.h"
00005 #include "AtlfastUtils/Cslice_iter.h"
00006 //=================================================
00007 //
00008 // Matrix
00009 //
00010 // Matrix class from Sjoustrup's "the C++ programming language" ch 22.4.6
00011 // This class has been written because of a compiler bug on the
00012 // SUN which prevents std::vector<HepMatrix> due to the misinterpretation
00013 // b the compiler of:  HepMatrix T() const (compiler thinks this is a 
00014 // conversion, wheras it is really makes the Tranpose!!!
00015 //
00016 //
00017 
00018 
00019 namespace Atlfast {
00020   using std::valarray;
00021   using std::slice;
00022 
00023   class Matrix{
00024   private:
00025     valarray<double>* m_v;
00026     size_t m_d1, m_d2;
00027   public:
00028     Matrix(size_t x, size_t y);
00029     Matrix(size_t x, size_t y, double init);
00030     Matrix(const Matrix&);
00031     Matrix& operator=(const Matrix&);
00032     ~Matrix();
00033     
00034     size_t size() const {return m_d1*m_d2;}
00035     size_t dim1() const {return m_d1;}
00036     size_t dim2() const {return m_d2;}
00037     
00038     Slice_iter<double> row(size_t i);
00039     Cslice_iter<double> row(size_t i)const;
00040 
00041     Slice_iter<double> column(size_t i);
00042     Cslice_iter<double> column(size_t i)const;
00043 
00044     double& operator()(size_t x, size_t y);
00045     double operator()(size_t x, size_t y)const;
00046 
00047     Slice_iter<double> operator()(size_t i) {return column(i);}
00048     Cslice_iter<double> operator()(size_t i) const {return column(i);}
00049 
00050     Slice_iter<double> operator[](size_t i) {return column(i);}
00051     Cslice_iter<double> operator[](size_t i) const {return column(i);}
00052 
00053     Matrix& operator*=(double);
00054 
00055     valarray<double>& array() {return *m_v;}
00056 
00057     Matrix sub(int minRow,int maxRow,int minCol,int maxCol) const;
00058     void sub(int minRow, int minCol, Matrix& dest) const;
00059   };
00060 
00061   inline Slice_iter<double> Matrix::row(size_t i){
00062     return Slice_iter<double>(m_v, slice(i,m_d1,m_d2));
00063   }
00064 
00065   inline Cslice_iter<double> Matrix::row(size_t i) const {
00066     return Cslice_iter<double>(m_v, slice(i,m_d1,m_d2));
00067   }
00068 
00069   inline Slice_iter<double> Matrix::column(size_t i){
00070     return Slice_iter<double>(m_v, slice(i*m_d2,m_d2,1));
00071   }
00072 
00073   inline Cslice_iter<double> Matrix::column(size_t i) const {
00074     return Cslice_iter<double>(m_v, slice(i*m_d2,m_d2,1));
00075   }
00076 }//namespace
00077 
00078 #endif
00079 
00080 
00081 
00082 
00083 

Generated on Wed Jan 15 11:00:29 2003 for AtlfastUtils by doxygen1.3-rc1