GetFEM  5.4.3
gmm_transposed.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2002-2020 Yves Renard
5 
6  This file is a part of GetFEM
7 
8  GetFEM is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Lesser General Public License as published
10  by the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version along with the GCC Runtime Library
12  Exception either version 3.1 or (at your option) any later version.
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  License and GCC Runtime Library Exception for more details.
17  You should have received a copy of the GNU Lesser General Public License
18  along with this program; if not, write to the Free Software Foundation,
19  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, you may use this file as it is a part of a free
22  software library without restriction. Specifically, if other files
23  instantiate templates or use macros or inline functions from this file,
24  or you compile this file and link it with other files to produce an
25  executable, this file does not by itself cause the resulting executable
26  to be covered by the GNU Lesser General Public License. This exception
27  does not however invalidate any other reasons why the executable file
28  might be covered by the GNU Lesser General Public License.
29 
30 ===========================================================================*/
31 
32 /**@file gmm_transposed.h
33  @author Yves Renard <[email protected]>
34  @date November 10, 2002.
35  @brief Generic transposed matrices
36 */
37 #ifndef GMM_TRANSPOSED_H__
38 #define GMM_TRANSPOSED_H__
39 
40 #include "gmm_def.h"
41 
42 namespace gmm {
43 
44  /* ********************************************************************* */
45  /* transposed reference */
46  /* ********************************************************************* */
47 
48  template <typename PT> struct transposed_row_ref {
49 
50  typedef transposed_row_ref<PT> this_type;
51  typedef typename std::iterator_traits<PT>::value_type M;
52  typedef M * CPT;
53  typedef typename std::iterator_traits<PT>::reference ref_M;
54  typedef typename select_ref<typename linalg_traits<this_type>
55  ::const_col_iterator, typename linalg_traits<this_type>
56  ::col_iterator, PT>::ref_type iterator;
57  typedef typename linalg_traits<this_type>::reference reference;
58  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
59 
60  iterator begin_, end_;
61  porigin_type origin;
62  size_type nr, nc;
63 
64  transposed_row_ref(ref_M m)
65  : begin_(mat_row_begin(m)), end_(mat_row_end(m)),
66  origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
67 
68  transposed_row_ref(const transposed_row_ref<CPT> &cr) :
69  begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
70 
71  reference operator()(size_type i, size_type j) const
72  { return linalg_traits<M>::access(begin_+j, i); }
73  };
74 
75  template <typename PT> struct linalg_traits<transposed_row_ref<PT> > {
76  typedef transposed_row_ref<PT> this_type;
77  typedef typename std::iterator_traits<PT>::value_type M;
78  typedef typename linalg_traits<M>::origin_type origin_type;
79  typedef typename select_ref<const origin_type *, origin_type *,
80  PT>::ref_type porigin_type;
81  typedef typename which_reference<PT>::is_reference is_reference;
82  typedef abstract_matrix linalg_type;
83  typedef typename linalg_traits<M>::value_type value_type;
84  typedef typename select_ref<value_type,
85  typename linalg_traits<M>::reference, PT>::ref_type reference;
86  typedef typename linalg_traits<M>::storage_type storage_type;
87  typedef abstract_null_type sub_row_type;
88  typedef abstract_null_type const_sub_row_type;
89  typedef abstract_null_type row_iterator;
90  typedef abstract_null_type const_row_iterator;
91  typedef typename linalg_traits<M>::const_sub_row_type const_sub_col_type;
92  typedef typename select_ref<abstract_null_type, typename
93  linalg_traits<M>::sub_row_type, PT>::ref_type sub_col_type;
94  typedef typename linalg_traits<M>::const_row_iterator const_col_iterator;
95  typedef typename select_ref<abstract_null_type, typename
96  linalg_traits<M>::row_iterator, PT>::ref_type col_iterator;
97  typedef col_major sub_orientation;
98  typedef typename linalg_traits<M>::index_sorted index_sorted;
99  static size_type ncols(const this_type &v) { return v.nc; }
100  static size_type nrows(const this_type &v) { return v.nr; }
101  static const_sub_col_type col(const const_col_iterator &it)
102  { return linalg_traits<M>::row(it); }
103  static sub_col_type col(const col_iterator &it)
104  { return linalg_traits<M>::row(it); }
105  static col_iterator col_begin(this_type &m) { return m.begin_; }
106  static col_iterator col_end(this_type &m) { return m.end_; }
107  static const_col_iterator col_begin(const this_type &m)
108  { return m.begin_; }
109  static const_col_iterator col_end(const this_type &m) { return m.end_; }
110  static origin_type* origin(this_type &v) { return v.origin; }
111  static const origin_type* origin(const this_type &v) { return v.origin; }
112  static void do_clear(this_type &v);
113  static value_type access(const const_col_iterator &itcol, size_type i)
114  { return linalg_traits<M>::access(itcol, i); }
115  static reference access(const col_iterator &itcol, size_type i)
116  { return linalg_traits<M>::access(itcol, i); }
117  };
118 
119  template <typename PT>
120  void linalg_traits<transposed_row_ref<PT> >::do_clear(this_type &v) {
121  col_iterator it = mat_col_begin(v), ite = mat_col_end(v);
122  for (; it != ite; ++it) clear(col(it));
123  }
124 
125  template<typename PT> std::ostream &operator <<
126  (std::ostream &o, const transposed_row_ref<PT>& m)
127  { gmm::write(o,m); return o; }
128 
129  template <typename PT> struct transposed_col_ref {
130 
131  typedef transposed_col_ref<PT> this_type;
132  typedef typename std::iterator_traits<PT>::value_type M;
133  typedef M * CPT;
134  typedef typename std::iterator_traits<PT>::reference ref_M;
135  typedef typename select_ref<typename linalg_traits<this_type>
136  ::const_row_iterator, typename linalg_traits<this_type>
137  ::row_iterator, PT>::ref_type iterator;
138  typedef typename linalg_traits<this_type>::reference reference;
139  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
140 
141  iterator begin_, end_;
142  porigin_type origin;
143  size_type nr, nc;
144 
145  transposed_col_ref(ref_M m)
146  : begin_(mat_col_begin(m)), end_(mat_col_end(m)),
147  origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
148 
149  transposed_col_ref(const transposed_col_ref<CPT> &cr) :
150  begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
151 
152  reference operator()(size_type i, size_type j) const
153  { return linalg_traits<M>::access(begin_+i, j); }
154  };
155 
156  template <typename PT> struct linalg_traits<transposed_col_ref<PT> > {
157  typedef transposed_col_ref<PT> this_type;
158  typedef typename std::iterator_traits<PT>::value_type M;
159  typedef typename linalg_traits<M>::origin_type origin_type;
160  typedef typename select_ref<const origin_type *, origin_type *,
161  PT>::ref_type porigin_type;
162  typedef typename which_reference<PT>::is_reference is_reference;
163  typedef abstract_matrix linalg_type;
164  typedef typename linalg_traits<M>::value_type value_type;
165  typedef typename select_ref<value_type,
166  typename linalg_traits<M>::reference, PT>::ref_type reference;
167  typedef typename linalg_traits<M>::storage_type storage_type;
168  typedef abstract_null_type sub_col_type;
169  typedef abstract_null_type const_sub_col_type;
170  typedef abstract_null_type col_iterator;
171  typedef abstract_null_type const_col_iterator;
172  typedef typename linalg_traits<M>::const_sub_col_type const_sub_row_type;
173  typedef typename select_ref<abstract_null_type, typename
174  linalg_traits<M>::sub_col_type, PT>::ref_type sub_row_type;
175  typedef typename linalg_traits<M>::const_col_iterator const_row_iterator;
176  typedef typename select_ref<abstract_null_type, typename
177  linalg_traits<M>::col_iterator, PT>::ref_type row_iterator;
178  typedef row_major sub_orientation;
179  typedef typename linalg_traits<M>::index_sorted index_sorted;
180  static size_type nrows(const this_type &v)
181  { return v.nr; }
182  static size_type ncols(const this_type &v)
183  { return v.nc; }
184  static const_sub_row_type row(const const_row_iterator &it)
185  { return linalg_traits<M>::col(it); }
186  static sub_row_type row(const row_iterator &it)
187  { return linalg_traits<M>::col(it); }
188  static row_iterator row_begin(this_type &m) { return m.begin_; }
189  static row_iterator row_end(this_type &m) { return m.end_; }
190  static const_row_iterator row_begin(const this_type &m)
191  { return m.begin_; }
192  static const_row_iterator row_end(const this_type &m) { return m.end_; }
193  static origin_type* origin(this_type &v) { return v.origin; }
194  static const origin_type* origin(const this_type &v) { return v.origin; }
195  static void do_clear(this_type &m);
196  static value_type access(const const_row_iterator &itrow, size_type i)
197  { return linalg_traits<M>::access(itrow, i); }
198  static reference access(const row_iterator &itrow, size_type i)
199  { return linalg_traits<M>::access(itrow, i); }
200  };
201 
202  template <typename PT>
203  void linalg_traits<transposed_col_ref<PT> >::do_clear(this_type &v) {
204  row_iterator it = mat_row_begin(v), ite = mat_row_end(v);
205  for (; it != ite; ++it) clear(row(it));
206  }
207 
208  template<typename PT> std::ostream &operator <<
209  (std::ostream &o, const transposed_col_ref<PT>& m)
210  { gmm::write(o,m); return o; }
211 
212  template <typename TYPE, typename PT> struct transposed_return_ {
213  typedef abstract_null_type return_type;
214  };
215  template <typename PT> struct transposed_return_<row_major, PT> {
216  typedef typename std::iterator_traits<PT>::value_type L;
217  typedef typename select_return<transposed_row_ref<const L *>,
218  transposed_row_ref< L *>, PT>::return_type return_type;
219  };
220  template <typename PT> struct transposed_return_<col_major, PT> {
221  typedef typename std::iterator_traits<PT>::value_type L;
222  typedef typename select_return<transposed_col_ref<const L *>,
223  transposed_col_ref< L *>, PT>::return_type return_type;
224  };
225  template <typename PT> struct transposed_return {
226  typedef typename std::iterator_traits<PT>::value_type L;
227  typedef typename transposed_return_<typename principal_orientation_type<
228  typename linalg_traits<L>::sub_orientation>::potype,
229  PT>::return_type return_type;
230  };
231 
232  template <typename L> inline
233  typename transposed_return<const L *>::return_type transposed(const L &l) {
234  return typename transposed_return<const L *>::return_type
235  (linalg_cast(const_cast<L &>(l)));
236  }
237 
238  template <typename L> inline
239  typename transposed_return<L *>::return_type transposed(L &l)
240  { return typename transposed_return<L *>::return_type(linalg_cast(l)); }
241 
242 }
243 
244 #endif // GMM_TRANSPOSED_H__
void clear(L &l)
clear (fill with zeros) a vector or matrix.
Definition: gmm_blas.h:59
Basic definitions and tools of GMM.
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49