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

Rectmat.hh

Go to the documentation of this file.
00001 #ifndef RECTMAT_TMPL_HEADER
00002 #define RECTMAT_TMPL_HEADER
00003 
00004 // ==== HEADER Rectmat.hh ====
00005 
00011 // 8-Dec-2000. Andras Aszodi
00012 
00013 // ---- COMPATIBILITY NOTES ----
00014 
00015 // Exception support is assumed.
00016 // This module depends on the Standard Template Library.
00017  
00018 // ---- COMPILER COMMAND LINE MACROS ----
00019 
00020 // Define the macro INCLUDE_TMPL_DEFS if your compiler
00021 // does not support automatic template source inclusion.
00022 
00023 // ---- MODULE HEADERS ----
00024 
00025 #include "Vector.hh"
00026 #include "Basemat.hh"
00027 #include "Squarexc.hh"
00028 
00029 // ==== CLASSES ====
00030 
00031 namespace RazorBack {
00032 
00038 template <class T_>
00039 class Rectmat_: public Basemat_<T_>
00040 {
00041     // data
00042     private:
00043     
00044     // Layout information:-
00045     // The matrix elements are stored in row major order.
00046     //
00047     // 00 01 02
00048     // 10 11 12 --> 00 01 02 10 11 12 20 21 22
00049     // 20 21 22
00050     //
00051     size_t R, C;        // number of rows and columns
00052     
00053     // methods
00054     public:
00055     
00057     explicit Rectmat_(size_t Row=3, size_t Col=3)
00058     {
00059         if (!Row) Row=3; if (!Col) Col=3;
00060         R=Row; C=Col;
00061         Matstorage_<T_> *Newmat=new Matstorage_<T_>(Row*Col);
00062         replace_storage(Newmat);        // alloc storage
00063     }
00064     
00066     Rectmat_(const Rectmat_<T_>& Rm):
00067             Basemat_<T_>(Rm), R(Rm.rno()), C(Rm.cno()) {}
00068     
00073     Rectmat_(const T_ *Arr, size_t Row, size_t Col):
00074             R(Row), C(Col)
00075     {
00076         Matstorage_<T_> *Newmat=new Matstorage_<T_>(R*C);
00077         replace_storage(Newmat);
00078         for (register unsigned int i=0; i<R*C; i++)
00079             elems(i)=Arr[i];    // direct copy assuming same layout
00080     }
00081     
00083     virtual ~Rectmat_() {}
00084     
00086     
00088     virtual size_t rno() const { return R; }
00089     virtual size_t cno() const { return C; }
00090     
00096     virtual typename vector<T_>::const_iterator operator[](size_t Idx) const
00097         { return (elems().begin()+Idx*cno()); }
00098     virtual typename vector<T_>::iterator operator[](size_t Idx)
00099         { clone(); return (elems().begin()+Idx*cno()); }
00100     virtual const T_& operator()(size_t Ridx, size_t Cidx) const;
00101     virtual T_& operator()(size_t Ridx, size_t Cidx);
00102     
00110     void size(size_t Rno, size_t Cno);
00111 
00118     virtual Vector_<T_> row(size_t Idx) const;
00119     virtual void row(const Vector_<T_>& Vec, size_t Idx);
00120 
00127     virtual Vector_<T_> col(size_t Idx) const;
00128     virtual void col(const Vector_<T_>& Vec, size_t Idx);
00129 
00131     
00132     Rectmat_<T_> operator*(const T_& Factor) const;
00133     Rectmat_<T_> operator/(const T_& Div) const;
00134     
00136     
00141     Rectmat_<T_>& operator+=(const Rectmat_<T_>& Mat);
00142     Rectmat_<T_> operator+(const Rectmat_<T_>& Mat) const;
00143     Rectmat_<T_>& operator-=(const Rectmat_<T_>& Mat);
00144     Rectmat_<T_> operator-(const Rectmat_<T_>& Mat) const;
00145 
00150     Rectmat_<T_> operator*(const Rectmat_<T_>& Mat) const;
00151     Vector_<T_> operator*(const Vector_<T_>& Vec) const;
00152 
00154     
00156     Rectmat_<T_> get_transpose() const;
00157 
00162     Rectmat_<T_>& transpose_inplace();
00163 
00165     
00172     virtual Vector_<T_> diag() const;
00173     virtual void diag(const Vector_<T_>& Vec);
00174 
00180     virtual void diag_matrix(const T_& Dval);
00181 
00186     virtual T_ trace() const;
00187 
00189     virtual void read_matrix(istream& In);
00190     
00192     protected:
00193     
00194     void print_rows(ostream& Out, size_t Rw, size_t Jbeg, 
00195         size_t Items, size_t Width, size_t Prec) const;
00196     
00197 };
00198 // END OF CLASS Rectmat_
00199 
00200 // ---- OUT-OF-CLASS FUNCTIONS ----
00201 
00202 // These were originally friend templates but EGCS 1.1.2
00203 // did not like them. 12-Jul-1999.
00204 
00208 template <class T_>
00209 Rectmat_<T_> operator*(const T_& Factor, const Rectmat_<T_>& Bm);
00210 
00211 // ---- TYPEDEFS ----
00212 
00213 // Float and double matrices (for convenience)
00214 typedef Rectmat_<double> Rmatdbl_;
00215 typedef Rectmat_<float> Rmatflt_;
00216 
00217 } // RazorBack
00218 
00219 #ifdef INCLUDE_TMPL_DEFS
00220 #include "Rectmat.cc"
00221 #endif
00222 
00223 // ==== END OF TEMPLATE HEADER Rectmat.hh ====
00224 
00225 #endif      // RECTMAT_TMPL_HEADER

Generated at Wed Aug 21 09:33:22 2002 for The Razorback C++ Library: Linear Algebra by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001