MathTL
algebra/matrix.h
00001 // -*- c++ -*-
00002 
00003 // +--------------------------------------------------------------------+
00004 // | This file is part of MathTL - the Mathematical Template Library    |
00005 // |                                                                    |
00006 // | Copyright (c) 2002-2009                                            |
00007 // | Thorsten Raasch, Manuel Werner                                     |
00008 // +--------------------------------------------------------------------+
00009 
00010 #ifndef _MATHTL_MATRIX_H
00011 #define _MATHTL_MATRIX_H
00012 
00013 #include <iostream>
00014 #include <algebra/vector.h>
00015 #include <algebra/matrix_block.h>
00016 #include <algebra/symmetric_matrix.h>
00017 #include <algebra/triangular_matrix.h>
00018 #include <algebra/kronecker_matrix.h>
00019 
00020 // matrix norms, for convenience
00021 #include <algebra/matrix_norms.h>
00022 
00023 namespace MathTL
00024 {
00031   template <class C>
00032   class Matrix
00033     : public MatrixBlock<C>
00034   {
00035   public:
00039     typedef typename Vector<C>::size_type size_type;
00040     
00044     explicit Matrix(const size_type n = 0);
00045 
00049     Matrix(const Matrix<C>& M);
00050 
00054     Matrix(const SymmetricMatrix<C>& M);
00055     
00059     Matrix(const LowerTriangularMatrix<C>& M);
00060     
00064     Matrix(const UpperTriangularMatrix<C>& M);
00065     
00069     template <class MATRIX1, class MATRIX2>
00070     Matrix(const KroneckerMatrix<C,MATRIX1,MATRIX2>& M);
00071     
00075     Matrix(const Vector<C>& v);
00076 
00080     Matrix(const size_type row_dimension, const size_type column_dimension);
00081 
00090     Matrix(const size_type row_dimension,
00091            const size_type column_dimension,
00092            const char* str,
00093            const bool byrow = true);
00094 
00096     MatrixBlock<C>* clone() const;
00097 
00099     MatrixBlock<C>* clone_transposed() const;
00100 
00104     const size_type row_dimension() const;
00105 
00109     const size_type column_dimension() const;
00110 
00114     const size_type size() const;
00115     
00119     void resize(const size_type rows, const size_type columns);
00120 
00126     void reshape(const size_type rows);
00127 
00132     void reshape(Vector<C>& v) const;
00133     
00137     void col(Vector<C>& v) const;
00138 
00143     void decol(const Vector<C>& v, const size_type rows);
00144     
00148     void diagonal(const size_type n, const C diag);
00149 
00153     const size_type memory_consumption() const;
00154 
00158     bool empty() const;
00159 
00163     const C operator () (const size_type row, const size_type column) const;
00164 
00168     const C get_entry(const size_type row, const size_type column) const;
00169 
00173     template <class MATRIX>
00174     void get_block(const size_type firstrow, const size_type firstcolumn,
00175                    const size_type rows, const size_type columns,
00176                    MATRIX& M, const bool resizeM = false) const;
00177     
00181     C& operator () (const size_type row, const size_type column);
00182     
00186     void set_entry(const size_type row, const size_type column, const C value);
00187 
00192     template <class MATRIX>
00193     void set_block(const size_type firstrow, const size_type firstcolumn,
00194                    const MATRIX& M,
00195                    const bool reflect = false);
00196 
00200     template <class C2>
00201     bool operator == (const Matrix<C2>& M) const;
00202 
00206     template <class C2>
00207     bool operator != (const Matrix<C2>& M) const;
00208 
00212     Matrix<C>& operator = (const Matrix<C>& M);
00213 
00217     void swap(Matrix<C>& M);
00218 
00222     void reflect(Matrix<C>& M) const;
00223     
00227     void scale(const C s);
00228 
00234     template <class VECTOR>
00235     void apply(const VECTOR& x, VECTOR& Mx) const;
00236 
00238     void apply(const Vector<C>& x, Vector<C>& Mx) const;
00239 
00245     template <class VECTOR>
00246     void apply_transposed(const VECTOR& x, VECTOR& Mtx) const;
00247 
00249     void apply_transposed(const Vector<C>& x, Vector<C>& Mtx) const;
00250     
00255     void compress(const double eta = 1e-16);
00256 
00261     void print(std::ostream& os,
00262                const unsigned int tabwidth = 10,
00263                const unsigned int precision = 3) const;
00264 
00268     void matlab_output(const char *file, const char *Matrixname, const int binary) const;
00269 
00270   protected:
00276     Vector<C> entries_;
00277 
00281     size_type rowdim_;
00282 
00286     size_type coldim_;
00287   };
00288 
00292   template <class C>
00293   void swap(Matrix<C>& M1, Matrix<C>& M2);
00294 
00298   template <class C>
00299   Matrix<C> operator + (const Matrix<C>& M, const Matrix<C>& N);
00300 
00304   template <class C>
00305   Matrix<C> operator - (const Matrix<C>& M, const Matrix<C>& N);
00306 
00310   template <class C>
00311   Matrix<C> operator * (const Matrix<C>& M, const Matrix<C>& N);
00312 
00316   template <class C>
00317   Matrix<C> transpose(const Matrix<C>& M);
00318 
00322   template <class C>
00323   std::ostream& operator << (std::ostream& os, const Matrix<C>& M);
00324 }
00325 
00326 // include implementation of inline functions
00327 #include <algebra/matrix.cpp>
00328 
00329 #endif
 All Classes Functions Variables Typedefs Enumerations