SubMatrix_BaseInline.cxx
1 // Copyright (C) 2009 Vivien Mallet
2 //
3 // This file is part of the linear-algebra library Seldon,
4 // http://seldon.sourceforge.net/.
5 //
6 // Seldon is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your option)
9 // any later version.
10 //
11 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 // more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with Seldon. If not, see http://www.gnu.org/licenses/.
18 
19 
20 #ifndef SELDON_FILE_SUBMATRIX_BASE_INLINE_CXX
21 
22 
23 #include "SubMatrix_Base.hxx"
24 
25 
26 namespace Seldon
27 {
28 
29 
31  // SUBMATRIX_BASE //
33 
34 
35  /***************
36  * CONSTRUCTOR *
37  ***************/
38 
39 
41  template <class T, class Prop, class M, class Allocator>
43  ::SubMatrix_Base(M& A, Vector<int>& row_list, Vector<int>& column_list):
44  Matrix_Base<T, Allocator>(row_list.GetLength(), column_list.GetLength()),
45  matrix_(&A), row_list_(row_list), column_list_(column_list)
46  {
47  }
48 
49 
50  /**************
51  * DESTRUCTOR *
52  **************/
53 
54 
56  template <class T, class Prop, class M, class Allocator>
58  {
59  }
60 
61 
62  /************************
63  * ACCESS AND AFFECTION *
64  ************************/
65 
66 
68 
74  template <class T, class Prop, class M, class Allocator>
75  inline typename SubMatrix_Base<T, Prop, M, Allocator>::access_type
77  {
78  return (*this->matrix_)(this->row_list_(i), this->column_list_(j));
79  }
80 
81 
83 
89  template <class T, class Prop, class M, class Allocator>
90  inline typename SubMatrix_Base<T, Prop, M, Allocator>::const_access_type
92  {
93  return (*this->matrix_)(this->row_list_(i), this->column_list_(j));
94  }
95 
96 
98 
104  template <class T, class Prop, class M, class Allocator>
105  inline typename SubMatrix_Base<T, Prop, M, Allocator>::entry_type&
107  {
108  return this->matrix_->Val(this->row_list_(i), this->column_list_(j));
109  }
110 
111 
113 
119  template <class T, class Prop, class M, class Allocator>
120  inline const typename SubMatrix_Base<T, Prop, M, Allocator>::entry_type&
122  {
123  return this->matrix_->Val(this->row_list_(i), this->column_list_(j));
124  }
125 
126 
127  /*****************
128  * BASIC METHODS *
129  *****************/
130 
131 
133 
136  template <class T, class Prop, class M, class Allocator>
138  {
139  return row_list_.GetLength();
140  }
141 
142 
144 
147  template <class T, class Prop, class M, class Allocator>
149  {
150  return column_list_.GetLength();
151  }
152 
153 
155 
159  template <class T, class Prop, class M, class Allocator>
161  ::GetM(const SeldonTranspose& status) const
162  {
163  if (status.NoTrans())
164  return row_list_.GetLength();
165  else
166  return column_list_.GetLength();
167  }
168 
169 
171 
175  template <class T, class Prop, class M, class Allocator>
177  ::GetN(const SeldonTranspose& status) const
178  {
179  if (status.NoTrans())
180  return column_list_.GetLength();
181  else
182  return row_list_.GetLength();
183  }
184 
185 
187 
191  template <class T, class Prop, class M, class Allocator>
193  {
194  for (int i = 0; i < this->GetM(); i++)
195  {
196  for (int j = 0; j < this->GetN(); j++)
197  cout << (*this)(i, j) << "\t";
198  cout << endl;
199  }
200  }
201 
202 
203 } // namespace Seldon.
204 
205 
206 #define SELDON_FILE_SUBMATRIX_BASE_INLINE_CXX
207 #endif
Seldon::SubMatrix_Base::~SubMatrix_Base
~SubMatrix_Base()
Destructor.
Definition: SubMatrix_BaseInline.cxx:57
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::SubMatrix_Base::operator()
access_type operator()(int i, int j)
Access operator.
Definition: SubMatrix_BaseInline.cxx:76
Seldon::Vector< int >
Seldon::SubMatrix_Base::GetM
int GetM() const
Returns the number of rows.
Definition: SubMatrix_BaseInline.cxx:137
Seldon::SubMatrix_Base::Print
void Print() const
Prints a matrix on screen.
Definition: SubMatrix_BaseInline.cxx:192
Seldon::SubMatrix_Base::GetN
int GetN() const
Returns the number of columns.
Definition: SubMatrix_BaseInline.cxx:148
Seldon::SubMatrix_Base::SubMatrix_Base
SubMatrix_Base(M &A, Vector< int > &row_list, Vector< int > &column_list)
Main constructor.
Definition: SubMatrix_BaseInline.cxx:43
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::SubMatrix_Base::Val
entry_type & Val(int i, int j)
Access operator.
Definition: SubMatrix_BaseInline.cxx:106