matrix/SubMatrix_Base.cxx

00001 // Copyright (C) 2009 Vivien Mallet
00002 //
00003 // This file is part of the linear-algebra library Seldon,
00004 // http://seldon.sourceforge.net/.
00005 //
00006 // Seldon is free software; you can redistribute it and/or modify it under the
00007 // terms of the GNU Lesser General Public License as published by the Free
00008 // Software Foundation; either version 2.1 of the License, or (at your option)
00009 // any later version.
00010 //
00011 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00014 // more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public License
00017 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00018 
00019 
00020 #ifndef SELDON_FILE_SUBMATRIX_BASE_CXX
00021 
00022 
00023 #include "SubMatrix_Base.hxx"
00024 
00025 
00026 namespace Seldon
00027 {
00028 
00029 
00031   // SUBMATRIX_BASE //
00033 
00034 
00035   /***************
00036    * CONSTRUCTOR *
00037    ***************/
00038 
00039 
00041   template <class T, class Prop, class M, class Allocator>
00042   inline SubMatrix_Base<T, Prop, M, Allocator>
00043   ::SubMatrix_Base(M& A, Vector<int>& row_list, Vector<int>& column_list):
00044     Matrix_Base<T, Allocator>(row_list.GetLength(), column_list.GetLength()),
00045     matrix_(&A), row_list_(row_list), column_list_(column_list)
00046   {
00047   }
00048 
00049 
00050   /**************
00051    * DESTRUCTOR *
00052    **************/
00053 
00054 
00056   template <class T, class Prop, class M, class Allocator>
00057   inline SubMatrix_Base<T, Prop, M, Allocator>::~SubMatrix_Base()
00058   {
00059   }
00060 
00061 
00062   /************************
00063    * ACCESS AND AFFECTION *
00064    ************************/
00065 
00066 
00068 
00074   template <class T, class Prop, class M, class Allocator>
00075   inline typename SubMatrix_Base<T, Prop, M, Allocator>::access_type
00076   SubMatrix_Base<T, Prop, M, Allocator>::operator() (int i, int j)
00077   {
00078     return (*this->matrix_)(this->row_list_(i), this->column_list_(j));
00079   }
00080 
00081 
00083 
00089   template <class T, class Prop, class M, class Allocator>
00090   inline typename SubMatrix_Base<T, Prop, M, Allocator>::const_access_type
00091   SubMatrix_Base<T, Prop, M, Allocator>::operator() (int i, int j) const
00092   {
00093     return (*this->matrix_)(this->row_list_(i), this->column_list_(j));
00094   }
00095 
00096 
00098 
00104   template <class T, class Prop, class M, class Allocator>
00105   inline typename SubMatrix_Base<T, Prop, M, Allocator>::entry_type&
00106   SubMatrix_Base<T, Prop, M, Allocator>::Val(int i, int j)
00107   {
00108     return this->matrix_->Val(this->row_list_(i), this->column_list_(j));
00109   }
00110 
00111 
00113 
00119   template <class T, class Prop, class M, class Allocator>
00120   inline const typename SubMatrix_Base<T, Prop, M, Allocator>::entry_type&
00121   SubMatrix_Base<T, Prop, M, Allocator>::Val(int i, int j) const
00122   {
00123     return this->matrix_->Val(this->row_list_(i), this->column_list_(j));
00124   }
00125 
00126 
00127   /*****************
00128    * BASIC METHODS *
00129    *****************/
00130 
00131 
00133 
00136   template <class T, class Prop, class M, class Allocator>
00137   inline int SubMatrix_Base<T, Prop, M, Allocator>::GetM() const
00138   {
00139     return row_list_.GetLength();
00140   }
00141 
00142 
00144 
00147   template <class T, class Prop, class M, class Allocator>
00148   inline int SubMatrix_Base<T, Prop, M, Allocator>::GetN() const
00149   {
00150     return column_list_.GetLength();
00151   }
00152 
00153 
00155 
00159   template <class T, class Prop, class M, class Allocator>
00160   inline int SubMatrix_Base<T, Prop, M, Allocator>
00161   ::GetM(const SeldonTranspose& status) const
00162   {
00163     if (status.NoTrans())
00164       return row_list_.GetLength();
00165     else
00166       return column_list_.GetLength();
00167   }
00168 
00169 
00171 
00175   template <class T, class Prop, class M, class Allocator>
00176   inline int SubMatrix_Base<T, Prop, M, Allocator>
00177   ::GetN(const SeldonTranspose& status) const
00178   {
00179     if (status.NoTrans())
00180       return column_list_.GetLength();
00181     else
00182       return row_list_.GetLength();
00183   }
00184 
00185 
00187 
00191   template <class T, class Prop, class M, class Allocator>
00192   void SubMatrix_Base<T, Prop, M, Allocator>::Print() const
00193   {
00194     for (int i = 0; i < this->GetM(); i++)
00195       {
00196         for (int j = 0; j < this->GetN(); j++)
00197           cout << (*this)(i, j) << "\t";
00198         cout << endl;
00199       }
00200   }
00201 
00202 
00203 } // namespace Seldon.
00204 
00205 
00206 #define SELDON_FILE_SUBMATRIX_BASE_CXX
00207 #endif