Tools.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Helper functions for linear algebra component.
5  *
6  *
7  *
8  * \author O.Krause M.Thuma
9  * \date 20102011
10  *
11  *
12  * \par Copyright 1995-2017 Shark Development Team
13  *
14  * <BR><HR>
15  * This file is part of Shark.
16  * <http://shark-ml.org/>
17  *
18  * Shark is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Lesser General Public License as published
20  * by the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * Shark is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU Lesser General Public License for more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License
29  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
30  *
31  */
32 #ifndef SHARK_LINALG_TOOLS_H
33 #define SHARK_LINALG_TOOLS_H
34 
35 namespace remora{
36 
37 ///\brief partitions the matrix in 4 blocks defined by one splitting point (i,j).
38 ///
39 /// the blocks are defined using the intervals [0,...,i), [i,...,mat.size1()]
40 /// and [0,...,j), [j,...,mat.size2()]
41 template<class Matrix>
42 class Blocking{
43 public:
44 
45  Blocking(Matrix& matrix,std::size_t i, std::size_t j)
46  : m_upperLeft(subrange(matrix,0,i,0,j))
47  , m_upperRight(subrange(matrix,0,i,j,matrix.size2()))
48  , m_lowerLeft(subrange(matrix,i,matrix.size1(),0,j))
49  , m_lowerRight(subrange(matrix,i,matrix.size1(),j,matrix.size2()))
50  {}
51 
52  /// \brief Returns the lower left block of the matrix.
53  matrix_range<Matrix> const& upperLeft()const{
54  return m_upperLeft;
55  }
56  /// \brief Returns the upper right block of the matrix.
57  matrix_range<Matrix> const& upperRight()const{
58  return m_upperRight;
59  }
60  /// \brief Returns the lower left block of the matrix.
61  matrix_range<Matrix> const& lowerLeft()const{
62  return m_lowerLeft;
63  }
64 
65  /// \brief Returns the lower right block of the matrix.
66  matrix_range<Matrix> const& lowerRight()const{
67  return m_lowerRight;
68  }
69 
70  /// \brief Returns the lower left block of the matrix.
71  matrix_range<Matrix>& upperLeft(){
72  return m_upperLeft;
73  }
74  /// \brief Returns the upper right block of the matrix.
75  matrix_range<Matrix>& upperRight(){
76  return m_upperRight;
77  }
78  /// \brief Returns the lower left block of the matrix.
79  matrix_range<Matrix>& lowerLeft(){
80  return m_lowerLeft;
81  }
82 
83  /// \brief Returns the lower right block of the matrix.
84  matrix_range<Matrix>& lowerRight(){
85  return m_lowerRight;
86  }
87 
88 
89 private:
90  matrix_range<Matrix> m_upperLeft;
91  matrix_range<Matrix> m_upperRight;
92  matrix_range<Matrix> m_lowerLeft;
93  matrix_range<Matrix> m_lowerRight;
94 };
95 
96 }
97 #endif