CMR  1.3.0
matrix_permuted.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/numeric/ublas/matrix_expression.hpp>
4 #include <boost/numeric/ublas/detail/iterator.hpp>
5 
6 #include "permutations.hpp"
7 
8 namespace tu
9 {
10 
15  template <typename M>
16  class matrix_permuted: public boost::numeric::ublas::matrix_expression <matrix_permuted <M> >
17  {
18  public:
20  typedef M matrix_type;
21  typedef typename M::size_type size_type;
22  typedef typename M::difference_type difference_type;
23  typedef typename M::value_type value_type;
24  typedef typename M::const_reference const_reference;
25  typedef typename boost::mpl::if_ <boost::is_const <M>, typename M::const_reference, typename M::reference>::type reference;
26  typedef typename boost::mpl::if_ <boost::is_const <M>, typename M::const_closure_type, typename M::closure_type>::type matrix_closure_type;
30  typedef typename M::orientation_category orientation_category;
31  typedef typename M::storage_category storage_category;
32 
33  private:
34  matrix_type& _data;
35  permutation_type _perm1;
36  permutation_type _perm2;
37 
38  public:
39 
47  _data(matrix), _perm1(matrix.size1()), _perm2(matrix.size2())
48  {
49 
50  }
51 
56  inline size_type size1() const
57  {
58  return _perm1.size();
59  }
60 
65  inline size_type size2() const
66  {
67  return _perm2.size();
68  }
69 
74  inline const permutation_type& perm1() const
75  {
76  return _perm1;
77  }
78 
84  {
85  return _perm1;
86  }
87 
92  inline const permutation_type& perm2() const
93  {
94  return _perm2;
95  }
96 
102  {
103  return _perm2;
104  }
105 
115  {
116  return _data(_perm1(i), _perm2(j));
117  }
118 
128  {
129  return _data(_perm1(i), _perm2(j));
130  }
131 
136  inline matrix_type& data()
137  {
138  return _data;
139  }
140 
145  inline const matrix_type& data() const
146  {
147  return _data;
148  }
149 
150  typedef boost::numeric::ublas::detail::indexed_iterator1 <self_type, typename matrix_type::iterator1::iterator_category> iterator1;
151  typedef boost::numeric::ublas::detail::indexed_iterator2 <self_type, typename matrix_type::iterator2::iterator_category> iterator2;
152  typedef boost::numeric::ublas::detail::indexed_const_iterator1 <self_type, typename matrix_type::const_iterator1::iterator_category>
154  typedef boost::numeric::ublas::detail::indexed_const_iterator2 <self_type, typename matrix_type::const_iterator2::iterator_category>
156  };
157 
167  template <typename MatrixType>
168  inline void matrix_set_value(matrix_permuted <MatrixType>& matrix, size_t row, size_t column, typename MatrixType::value_type value)
169  {
170  matrix(row, column) = value;
171  }
172 
177  template <typename MatrixType>
178  inline void matrix_set_value(matrix_permuted <const MatrixType>& matrix, size_t row, size_t column, typename MatrixType::value_type value)
179  {
180  CMR_UNUSED(matrix);
181  CMR_UNUSED(row);
182  CMR_UNUSED(column);
183  CMR_UNUSED(value);
184  assert (false);
185  }
186 
195  template <typename MatrixType>
196  inline void matrix_permute1(matrix_permuted <MatrixType>& matrix, size_t index1, size_t index2)
197  {
198  matrix.perm1().swap(index1, index2);
199  }
200 
209  template <typename MatrixType>
210  inline void matrix_permute2(matrix_permuted <MatrixType>& matrix, size_t index1, size_t index2)
211  {
212  matrix.perm2().swap(index1, index2);
213  }
214 
223  template <typename MatrixType>
224  inline void matrix_binary_pivot(matrix_permuted <MatrixType>& matrix, size_t i, size_t j)
225  {
226  matrix_binary_pivot(matrix.data(), matrix.perm1()(i), matrix.perm2()(j));
227  }
228 
229  template <typename MatrixType>
231  {
232  return matrix.perm1();
233  }
234 
235  template <typename MatrixType>
237  {
238  return matrix.perm2();
239  }
240 
241  template <typename MatrixType>
243  {
244  return matrix_get_perm2(matrix.data());
245  }
246 
247  template <typename MatrixType>
249  {
250  return matrix_get_perm1(matrix.data());
251  }
252 
253  template <typename MatrixType>
255  {
256  matrix.perm1() = permutation;
257  }
258 
259  template <typename MatrixType>
261  {
262  matrix.perm2() = permutation;
263  }
264 
265  template <typename MatrixType>
267  {
268  matrix_set_perm2(matrix.data(), permutation);
269  }
270 
271  template <typename MatrixType>
273  {
274  matrix_set_perm1(matrix.data(), permutation);
275  }
276 } /* namespace tu */
Definition: matrix_permuted.hpp:17
permutation_type & perm2()
Definition: matrix_permuted.hpp:101
const permutation_type & perm2() const
Definition: matrix_permuted.hpp:92
const_reference operator()(size_type i, size_type j) const
Definition: matrix_permuted.hpp:114
matrix_permuted(matrix_type &matrix)
Definition: matrix_permuted.hpp:46
const self_type const_closure_type
Definition: matrix_permuted.hpp:27
const permutation_type & perm1() const
Definition: matrix_permuted.hpp:74
matrix_type & data()
Definition: matrix_permuted.hpp:136
boost::numeric::ublas::detail::indexed_const_iterator1< self_type, typename matrix_type::const_iterator1::iterator_category > const_iterator1
Definition: matrix_permuted.hpp:153
boost::numeric::ublas::detail::indexed_iterator1< self_type, typename matrix_type::iterator1::iterator_category > iterator1
Definition: matrix_permuted.hpp:150
M::difference_type difference_type
Definition: matrix_permuted.hpp:22
M matrix_type
Definition: matrix_permuted.hpp:20
matrix_permuted< M > self_type
Definition: matrix_permuted.hpp:19
M::orientation_category orientation_category
Definition: matrix_permuted.hpp:30
M::value_type value_type
Definition: matrix_permuted.hpp:23
M::storage_category storage_category
Definition: matrix_permuted.hpp:31
boost::numeric::ublas::detail::indexed_iterator2< self_type, typename matrix_type::iterator2::iterator_category > iterator2
Definition: matrix_permuted.hpp:151
self_type closure_type
Definition: matrix_permuted.hpp:28
permutation_type & perm1()
Definition: matrix_permuted.hpp:83
M::size_type size_type
Definition: matrix_permuted.hpp:21
size_type size2() const
Definition: matrix_permuted.hpp:65
size_type size1() const
Definition: matrix_permuted.hpp:56
boost::mpl::if_< boost::is_const< M >, typename M::const_closure_type, typename M::closure_type >::type matrix_closure_type
Definition: matrix_permuted.hpp:26
boost::mpl::if_< boost::is_const< M >, typename M::const_reference, typename M::reference >::type reference
Definition: matrix_permuted.hpp:25
boost::numeric::ublas::detail::indexed_const_iterator2< self_type, typename matrix_type::const_iterator2::iterator_category > const_iterator2
Definition: matrix_permuted.hpp:155
permutation permutation_type
Definition: matrix_permuted.hpp:29
const matrix_type & data() const
Definition: matrix_permuted.hpp:145
M::const_reference const_reference
Definition: matrix_permuted.hpp:24
Definition: matrix_transposed.hpp:47
matrix_type & data()
Definition: matrix_transposed.hpp:101
Definition: permutations.hpp:44
void swap(value_type a, value_type b)
Definition: permutations.hpp:187
size_type size() const
Definition: permutations.hpp:150
#define CMR_UNUSED(x)
Definition: env.h:24
Definition: algorithm.hpp:14
permutation matrix_get_perm2(matrix_permuted< MatrixType > &matrix)
Definition: matrix_permuted.hpp:236
permutation matrix_get_perm1(matrix_permuted< MatrixType > &matrix)
Definition: matrix_permuted.hpp:230
void matrix_permute1(MatrixType &matrix, size_t index1, size_t index2)
Definition: matrix.hpp:1723
void matrix_set_perm1(matrix_permuted< MatrixType > &matrix, const permutation &permutation)
Definition: matrix_permuted.hpp:254
void matrix_set_value(matrix_permuted< MatrixType > &matrix, size_t row, size_t column, typename MatrixType::value_type value)
Definition: matrix_permuted.hpp:168
void matrix_set_perm2(matrix_permuted< MatrixType > &matrix, const permutation &permutation)
Definition: matrix_permuted.hpp:260
void matrix_binary_pivot(matrix_permuted< MatrixType > &matrix, size_t i, size_t j)
Definition: matrix_permuted.hpp:224
void matrix_permute2(MatrixType &matrix, size_t index1, size_t index2)
Definition: matrix.hpp:1740