MathTL
algebra/block_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_BLOCK_MATRIX_H
00011 #define _MATHTL_BLOCK_MATRIX_H
00012 
00013 #include <iostream>
00014 #include <utils/array1d.h>
00015 #include <algebra/vector.h>
00016 #include <algebra/matrix_block.h>
00017 
00018 // matrix norms, for convenience
00019 #include <algebra/matrix_norms.h>
00020 
00021 namespace MathTL
00022 {
00026   template <class C>
00027   class BlockMatrix
00028     : public MatrixBlock<C>
00029   {
00030   public:
00034     typedef typename Vector<C>::size_type size_type;
00035     
00037     explicit BlockMatrix(const size_type n = 0);
00038 
00040     BlockMatrix(const size_type block_rows, const size_type block_columns);
00041 
00043     BlockMatrix(const BlockMatrix<C>&);
00044 
00046     ~BlockMatrix();
00047     
00049     MatrixBlock<C>* clone() const;
00050 
00052     MatrixBlock<C>* clone_transposed() const;
00053 
00055     const size_type row_dimension() const { return rowdim_; }
00056     
00058     const size_type column_dimension() const { return coldim_; }
00059 
00061     const size_type block_rows() const;
00062 
00064     const size_type block_columns() const;
00065 
00067     const size_type block_row_dimension(const size_type block_row) const;
00068     
00070     const size_type block_column_dimension(const size_type block_column) const;
00071     
00073     const MatrixBlock<C>* get_block(const size_type block_row, const size_type block_column) const;
00074 
00081     void set_block(const size_type row, const size_type column, MatrixBlock<C>* block);
00082     
00084     void resize_block_row(const size_type block_row, const size_type rows);
00085 
00087     void resize_block_column(const size_type block_row, const size_type columns);
00088 
00090     bool empty() const;
00091 
00097     void apply(const Vector<C>& x, Vector<C>& Mx) const;
00098 
00104     void apply_transposed(const Vector<C>& x, Vector<C>& Mtx) const;
00105     
00110     void print(std::ostream& os,
00111                const unsigned int tabwidth = 10,
00112                const unsigned int precision = 3) const;
00113 
00114   protected:
00116     Array1D<MatrixBlock<C>*> blocks;
00117 
00119     Array1D<size_type> block_rows_rows;
00120     
00122     Array1D<size_type> block_columns_columns;
00123 
00125     size_type rowdim_;
00126 
00128     size_type coldim_;
00129 
00131     void calculate_size();
00132   };
00133 
00141   template <class C>
00142   BlockMatrix<C> operator * (const BlockMatrix<C>& M, const BlockMatrix<C>& N);
00143 
00147   template <class C>
00148   BlockMatrix<C> transpose(const BlockMatrix<C>& M);
00149 
00153   template <class C>
00154   std::ostream& operator << (std::ostream& os, const BlockMatrix<C>& M);
00155   
00156 }
00157 
00158 // include implementation of inline functions
00159 #include <algebra/block_matrix.cpp>
00160 
00161 #endif
 All Classes Functions Variables Typedefs Enumerations