GetFEM++  5.3
gmm_real_part.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2003-2017 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_real_part.h
33  @author Yves Renard <Yves.Renard@insa-lyon.fr>
34  @date September 18, 2003.
35  @brief extract the real/imaginary part of vectors/matrices
36 */
37 #ifndef GMM_REAL_PART_H
38 #define GMM_REAL_PART_H
39 
40 #include "gmm_def.h"
41 #include "gmm_vector.h"
42 
43 namespace gmm {
44 
45  struct linalg_real_part {};
46  struct linalg_imag_part {};
47  template <typename R, typename PART> struct which_part {};
48 
49  template <typename C> typename number_traits<C>::magnitude_type
50  real_or_imag_part(C x, linalg_real_part) { return gmm::real(x); }
51  template <typename C> typename number_traits<C>::magnitude_type
52  real_or_imag_part(C x, linalg_imag_part) { return gmm::imag(x); }
53  template <typename T, typename C, typename OP> C
54  complex_from(T x, C y, OP op, linalg_real_part) { return std::complex<T>(op(std::real(y), x), std::imag(y)); }
55  template <typename T, typename C, typename OP> C
56  complex_from(T x, C y, OP op,linalg_imag_part) { return std::complex<T>(std::real(y), op(std::imag(y), x)); }
57 
58  template<typename T> struct project2nd {
59  T operator()(T , T b) const { return b; }
60  };
61 
62  template<typename T, typename R, typename PART> class ref_elt_vector<T, which_part<R, PART> > {
63 
64  R r;
65 
66  public :
67 
68  operator T() const { return real_or_imag_part(std::complex<T>(r), PART()); }
69  ref_elt_vector(R r_) : r(r_) {}
70  inline ref_elt_vector &operator =(T v)
71  { r = complex_from(v, std::complex<T>(r), gmm::project2nd<T>(), PART()); return *this; }
72  inline bool operator ==(T v) const { return (r == v); }
73  inline bool operator !=(T v) const { return (r != v); }
74  inline ref_elt_vector &operator +=(T v)
75  { r = complex_from(v, std::complex<T>(r), std::plus<T>(), PART()); return *this; }
76  inline ref_elt_vector &operator -=(T v)
77  { r = complex_from(v, std::complex<T>(r), std::minus<T>(), PART()); return *this; }
78  inline ref_elt_vector &operator /=(T v)
79  { r = complex_from(v, std::complex<T>(r), std::divides<T>(), PART()); return *this; }
80  inline ref_elt_vector &operator *=(T v)
81  { r = complex_from(v, std::complex<T>(r), std::multiplies<T>(), PART()); return *this; }
82  inline ref_elt_vector &operator =(const ref_elt_vector &re)
83  { *this = T(re); return *this; }
84  T operator +() { return T(*this); } // necessary for unknow reason
85  T operator -() { return -T(*this); } // necessary for unknow reason
86  T operator +(T v) { return T(*this)+ v; } // necessary for unknow reason
87  T operator -(T v) { return T(*this)- v; } // necessary for unknow reason
88  T operator *(T v) { return T(*this)* v; } // necessary for unknow reason
89  T operator /(T v) { return T(*this)/ v; } // necessary for unknow reason
90  };
91 
92  template<typename reference> struct ref_or_value_type {
93  template <typename T, typename W>
94  static W r(const T &x, linalg_real_part, W) {
95  return gmm::real(x);
96  }
97  template <typename T, typename W>
98  static W r(const T &x, linalg_imag_part, W) {
99  return gmm::imag(x);
100  }
101  };
102 
103  template<typename U, typename R, typename PART>
104  struct ref_or_value_type<ref_elt_vector<U, which_part<R, PART> > > {
105  template<typename T , typename W>
106  static const T &r(const T &x, linalg_real_part, W)
107  { return x; }
108  template<typename T, typename W>
109  static const T &r(const T &x, linalg_imag_part, W) {
110  return x;
111  }
112  template<typename T , typename W>
113  static T &r(T &x, linalg_real_part, W)
114  { return x; }
115  template<typename T, typename W>
116  static T &r(T &x, linalg_imag_part, W) {
117  return x;
118  }
119  };
120 
121 
122  /* ********************************************************************* */
123  /* Reference to the real part of (complex) vectors */
124  /* ********************************************************************* */
125 
126  template <typename IT, typename MIT, typename PART>
127  struct part_vector_iterator {
128  typedef typename std::iterator_traits<IT>::value_type vtype;
129  typedef typename gmm::number_traits<vtype>::magnitude_type value_type;
130  typedef value_type *pointer;
131  typedef ref_elt_vector<value_type, which_part<typename std::iterator_traits<IT>::reference, PART> > reference;
132  typedef typename std::iterator_traits<IT>::difference_type difference_type;
133  typedef typename std::iterator_traits<IT>::iterator_category
134  iterator_category;
135 
136  IT it;
137 
138  part_vector_iterator(void) {}
139  explicit part_vector_iterator(const IT &i) : it(i) {}
140  part_vector_iterator(const part_vector_iterator<MIT, MIT, PART> &i) : it(i.it) {}
141 
142 
143  size_type index(void) const { return it.index(); }
144  part_vector_iterator operator ++(int)
145  { part_vector_iterator tmp = *this; ++it; return tmp; }
146  part_vector_iterator operator --(int)
147  { part_vector_iterator tmp = *this; --it; return tmp; }
148  part_vector_iterator &operator ++() { ++it; return *this; }
149  part_vector_iterator &operator --() { --it; return *this; }
150  part_vector_iterator &operator +=(difference_type i)
151  { it += i; return *this; }
152  part_vector_iterator &operator -=(difference_type i)
153  { it -= i; return *this; }
154  part_vector_iterator operator +(difference_type i) const
155  { part_vector_iterator itb = *this; return (itb += i); }
156  part_vector_iterator operator -(difference_type i) const
157  { part_vector_iterator itb = *this; return (itb -= i); }
158  difference_type operator -(const part_vector_iterator &i) const
159  { return difference_type(it - i.it); }
160 
161  reference operator *() const { return reference(*it); }
162  reference operator [](size_type ii) const { return reference(it[ii]); }
163 
164  bool operator ==(const part_vector_iterator &i) const
165  { return (i.it == it); }
166  bool operator !=(const part_vector_iterator &i) const
167  { return (i.it != it); }
168  bool operator < (const part_vector_iterator &i) const
169  { return (it < i.it); }
170  };
171 
172 
173  template <typename PT, typename PART> struct part_vector {
174  typedef part_vector<PT, PART> this_type;
175  typedef typename std::iterator_traits<PT>::value_type V;
176  typedef V * CPT;
177  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
178  typename linalg_traits<V>::iterator, PT>::ref_type iterator;
179  typedef typename linalg_traits<this_type>::reference reference;
180  typedef typename linalg_traits<this_type>::value_type value_type;
181  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
182 
183  iterator begin_, end_;
184  porigin_type origin;
185  size_type size_;
186 
187  size_type size(void) const { return size_; }
188 
189  reference operator[](size_type i) const {
190  return reference(ref_or_value_type<reference>::r(
191  linalg_traits<V>::access(origin, begin_, end_, i),
192  PART(), value_type()));
193  }
194 
195  part_vector(V &v)
196  : begin_(vect_begin(v)), end_(vect_end(v)),
197  origin(linalg_origin(v)), size_(gmm::vect_size(v)) {}
198  part_vector(const V &v)
199  : begin_(vect_begin(const_cast<V &>(v))),
200  end_(vect_end(const_cast<V &>(v))),
201  origin(linalg_origin(const_cast<V &>(v))), size_(gmm::vect_size(v)) {}
202  part_vector() {}
203  part_vector(const part_vector<CPT, PART> &cr)
204  : begin_(cr.begin_),end_(cr.end_),origin(cr.origin), size_(cr.size_) {}
205  };
206 
207  template <typename IT, typename MIT, typename ORG, typename PT,
208  typename PART> inline
209  void set_to_begin(part_vector_iterator<IT, MIT, PART> &it,
210  ORG o, part_vector<PT, PART> *, linalg_modifiable) {
211  typedef part_vector<PT, PART> VECT;
212  typedef typename linalg_traits<VECT>::V_reference ref_t;
213  set_to_begin(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
214  }
215  template <typename IT, typename MIT, typename ORG, typename PT,
216  typename PART> inline
217  void set_to_begin(part_vector_iterator<IT, MIT, PART> &it,
218  ORG o, const part_vector<PT, PART> *, linalg_modifiable) {
219  typedef part_vector<PT, PART> VECT;
220  typedef typename linalg_traits<VECT>::V_reference ref_t;
221  set_to_begin(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
222  }
223  template <typename IT, typename MIT, typename ORG, typename PT,
224  typename PART> inline
225  void set_to_end(part_vector_iterator<IT, MIT, PART> &it,
226  ORG o, part_vector<PT, PART> *, linalg_modifiable) {
227  typedef part_vector<PT, PART> VECT;
228  typedef typename linalg_traits<VECT>::V_reference ref_t;
229  set_to_end(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
230  }
231  template <typename IT, typename MIT, typename ORG,
232  typename PT, typename PART> inline
233  void set_to_end(part_vector_iterator<IT, MIT, PART> &it,
234  ORG o, const part_vector<PT, PART> *,
235  linalg_modifiable) {
236  typedef part_vector<PT, PART> VECT;
237  typedef typename linalg_traits<VECT>::V_reference ref_t;
238  set_to_end(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
239  }
240 
241  template <typename PT, typename PART> std::ostream &operator <<
242  (std::ostream &o, const part_vector<PT, PART>& m)
243  { gmm::write(o,m); return o; }
244 
245 
246  /* ********************************************************************* */
247  /* Reference to the real or imaginary part of (complex) matrices */
248  /* ********************************************************************* */
249 
250 
251  template <typename PT, typename PART> struct part_row_ref {
252 
253  typedef part_row_ref<PT, PART> this_type;
254  typedef typename std::iterator_traits<PT>::value_type M;
255  typedef M * CPT;
256  typedef typename std::iterator_traits<PT>::reference ref_M;
257  typedef typename select_ref<typename linalg_traits<this_type>
258  ::const_row_iterator, typename linalg_traits<this_type>
259  ::row_iterator, PT>::ref_type iterator;
260  typedef typename linalg_traits<this_type>::value_type value_type;
261  typedef typename linalg_traits<this_type>::reference reference;
262  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
263 
264  iterator begin_, end_;
265  porigin_type origin;
266  size_type nr, nc;
267 
268  part_row_ref(ref_M m)
269  : begin_(mat_row_begin(m)), end_(mat_row_end(m)),
270  origin(linalg_origin(m)), nr(mat_nrows(m)), nc(mat_ncols(m)) {}
271 
272  part_row_ref(const part_row_ref<CPT, PART> &cr) :
273  begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
274 
275  reference operator()(size_type i, size_type j) const {
276  return reference(ref_or_value_type<reference>::r(
277  linalg_traits<M>::access(begin_+i, j),
278  PART(), value_type()));
279  }
280  };
281 
282  template<typename PT, typename PART> std::ostream &operator <<
283  (std::ostream &o, const part_row_ref<PT, PART>& m)
284  { gmm::write(o,m); return o; }
285 
286  template <typename PT, typename PART> struct part_col_ref {
287 
288  typedef part_col_ref<PT, PART> this_type;
289  typedef typename std::iterator_traits<PT>::value_type M;
290  typedef M * CPT;
291  typedef typename std::iterator_traits<PT>::reference ref_M;
292  typedef typename select_ref<typename linalg_traits<this_type>
293  ::const_col_iterator, typename linalg_traits<this_type>
294  ::col_iterator, PT>::ref_type iterator;
295  typedef typename linalg_traits<this_type>::value_type value_type;
296  typedef typename linalg_traits<this_type>::reference reference;
297  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
298 
299  iterator begin_, end_;
300  porigin_type origin;
301  size_type nr, nc;
302 
303  part_col_ref(ref_M m)
304  : begin_(mat_col_begin(m)), end_(mat_col_end(m)),
305  origin(linalg_origin(m)), nr(mat_nrows(m)), nc(mat_ncols(m)) {}
306 
307  part_col_ref(const part_col_ref<CPT, PART> &cr) :
308  begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
309 
310  reference operator()(size_type i, size_type j) const {
311  return reference(ref_or_value_type<reference>::r(
312  linalg_traits<M>::access(begin_+j, i),
313  PART(), value_type()));
314  }
315  };
316 
317 
318 
319  template<typename PT, typename PART> std::ostream &operator <<
320  (std::ostream &o, const part_col_ref<PT, PART>& m)
321  { gmm::write(o,m); return o; }
322 
323 
324 
325 
326 
327 
328 template <typename TYPE, typename PART, typename PT>
329  struct part_return_ {
330  typedef abstract_null_type return_type;
331  };
332  template <typename PT, typename PART>
333  struct part_return_<row_major, PART, PT> {
334  typedef typename std::iterator_traits<PT>::value_type L;
335  typedef typename select_return<part_row_ref<const L *, PART>,
336  part_row_ref< L *, PART>, PT>::return_type return_type;
337  };
338  template <typename PT, typename PART>
339  struct part_return_<col_major, PART, PT> {
340  typedef typename std::iterator_traits<PT>::value_type L;
341  typedef typename select_return<part_col_ref<const L *, PART>,
342  part_col_ref<L *, PART>, PT>::return_type return_type;
343  };
344 
345  template <typename PT, typename PART, typename LT> struct part_return__{
346  typedef abstract_null_type return_type;
347  };
348 
349  template <typename PT, typename PART>
350  struct part_return__<PT, PART, abstract_matrix> {
351  typedef typename std::iterator_traits<PT>::value_type L;
352  typedef typename part_return_<typename principal_orientation_type<
353  typename linalg_traits<L>::sub_orientation>::potype, PART,
354  PT>::return_type return_type;
355  };
356 
357  template <typename PT, typename PART>
358  struct part_return__<PT, PART, abstract_vector> {
359  typedef typename std::iterator_traits<PT>::value_type L;
360  typedef typename select_return<part_vector<const L *, PART>,
361  part_vector<L *, PART>, PT>::return_type return_type;
362  };
363 
364  template <typename PT, typename PART> struct part_return {
365  typedef typename std::iterator_traits<PT>::value_type L;
366  typedef typename part_return__<PT, PART,
367  typename linalg_traits<L>::linalg_type>::return_type return_type;
368  };
369 
370  template <typename L> inline
371  typename part_return<const L *, linalg_real_part>::return_type
372  real_part(const L &l) {
373  return typename part_return<const L *, linalg_real_part>::return_type
374  (linalg_cast(const_cast<L &>(l)));
375  }
376 
377  template <typename L> inline
378  typename part_return<L *, linalg_real_part>::return_type
379  real_part(L &l) {
380  return typename part_return<L *, linalg_real_part>::return_type(linalg_cast(l));
381  }
382 
383  template <typename L> inline
384  typename part_return<const L *, linalg_imag_part>::return_type
385  imag_part(const L &l) {
386  return typename part_return<const L *, linalg_imag_part>::return_type
387  (linalg_cast(const_cast<L &>(l)));
388  }
389 
390  template <typename L> inline
391  typename part_return<L *, linalg_imag_part>::return_type
392  imag_part(L &l) {
393  return typename part_return<L *, linalg_imag_part>::return_type(linalg_cast(l));
394  }
395 
396 
397  template <typename PT, typename PART>
398  struct linalg_traits<part_vector<PT, PART> > {
399  typedef part_vector<PT, PART> this_type;
400  typedef this_type * pthis_type;
401  typedef PT pV;
402  typedef typename std::iterator_traits<PT>::value_type V;
403  typedef typename linalg_traits<V>::index_sorted index_sorted;
404  typedef typename linalg_traits<V>::is_reference V_reference;
405  typedef typename linalg_traits<V>::origin_type origin_type;
406  typedef typename select_ref<const origin_type *, origin_type *,
407  PT>::ref_type porigin_type;
408  typedef typename which_reference<PT>::is_reference is_reference;
409  typedef abstract_vector linalg_type;
410  typedef typename linalg_traits<V>::value_type vtype;
411  typedef typename number_traits<vtype>::magnitude_type value_type;
412  typedef typename select_ref<value_type, ref_elt_vector<value_type,
413  which_part<typename linalg_traits<V>::reference,
414  PART> >, PT>::ref_type reference;
415  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
416  typename linalg_traits<V>::iterator, PT>::ref_type pre_iterator;
417  typedef typename select_ref<abstract_null_type,
418  part_vector_iterator<pre_iterator, pre_iterator, PART>,
419  PT>::ref_type iterator;
420  typedef part_vector_iterator<typename linalg_traits<V>::const_iterator,
421  pre_iterator, PART> const_iterator;
422  typedef typename linalg_traits<V>::storage_type storage_type;
423  static size_type size(const this_type &v) { return v.size(); }
424  static iterator begin(this_type &v) {
425  iterator it; it.it = v.begin_;
426  if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
427  set_to_begin(it, v.origin, pthis_type(), is_reference());
428  return it;
429  }
430  static const_iterator begin(const this_type &v) {
431  const_iterator it(v.begin_);
432  if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
433  { set_to_begin(it, v.origin, pthis_type(), is_reference()); }
434  return it;
435  }
436  static iterator end(this_type &v) {
437  iterator it(v.end_);
438  if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
439  set_to_end(it, v.origin, pthis_type(), is_reference());
440  return it;
441  }
442  static const_iterator end(const this_type &v) {
443  const_iterator it(v.end_);
444  if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
445  set_to_end(it, v.origin, pthis_type(), is_reference());
446  return it;
447  }
448  static origin_type* origin(this_type &v) { return v.origin; }
449  static const origin_type* origin(const this_type &v) { return v.origin; }
450 
451  static void clear(origin_type* o, const iterator &begin_,
452  const iterator &end_, abstract_sparse) {
453  std::deque<size_type> ind;
454  iterator it = begin_;
455  for (; it != end_; ++it) ind.push_front(it.index());
456  for (; !(ind.empty()); ind.pop_back())
457  access(o, begin_, end_, ind.back()) = value_type(0);
458  }
459  static void clear(origin_type* o, const iterator &begin_,
460  const iterator &end_, abstract_skyline) {
461  clear(o, begin_, end_, abstract_sparse());
462  }
463  static void clear(origin_type* o, const iterator &begin_,
464  const iterator &end_, abstract_dense) {
465  for (iterator it = begin_; it != end_; ++it) *it = value_type(0);
466  }
467 
468  static void clear(origin_type* o, const iterator &begin_,
469  const iterator &end_)
470  { clear(o, begin_, end_, storage_type()); }
471  static void do_clear(this_type &v) { clear(v.origin, begin(v), end(v)); }
472  static value_type access(const origin_type *o, const const_iterator &it,
473  const const_iterator &ite, size_type i) {
474  return real_or_imag_part(linalg_traits<V>::access(o, it.it, ite.it,i),
475  PART());
476  }
477  static reference access(origin_type *o, const iterator &it,
478  const iterator &ite, size_type i)
479  { return reference(linalg_traits<V>::access(o, it.it, ite.it,i)); }
480  };
481 
482  template <typename PT, typename PART>
483  struct linalg_traits<part_row_ref<PT, PART> > {
484  typedef part_row_ref<PT, PART> this_type;
485  typedef typename std::iterator_traits<PT>::value_type M;
486  typedef typename linalg_traits<M>::origin_type origin_type;
487  typedef typename select_ref<const origin_type *, origin_type *,
488  PT>::ref_type porigin_type;
489  typedef typename which_reference<PT>::is_reference is_reference;
490  typedef abstract_matrix linalg_type;
491  typedef typename linalg_traits<M>::value_type vtype;
492  typedef typename number_traits<vtype>::magnitude_type value_type;
493  typedef typename linalg_traits<M>::storage_type storage_type;
494  typedef abstract_null_type sub_col_type;
495  typedef abstract_null_type const_sub_col_type;
496  typedef abstract_null_type col_iterator;
497  typedef abstract_null_type const_col_iterator;
498  typedef typename org_type<typename linalg_traits<M>::const_sub_row_type>::t
499  pre_const_sub_row_type;
500  typedef typename org_type<typename linalg_traits<M>::sub_row_type>::t pre_sub_row_type;
501  typedef part_vector<const pre_const_sub_row_type *, PART>
502  const_sub_row_type;
503  typedef typename select_ref<abstract_null_type,
504  part_vector<pre_sub_row_type *, PART>, PT>::ref_type sub_row_type;
505  typedef typename linalg_traits<M>::const_row_iterator const_row_iterator;
506  typedef typename select_ref<abstract_null_type, typename
507  linalg_traits<M>::row_iterator, PT>::ref_type row_iterator;
508  typedef typename select_ref<
509  typename linalg_traits<const_sub_row_type>::reference,
510  typename linalg_traits<sub_row_type>::reference,
511  PT>::ref_type reference;
512  typedef row_major sub_orientation;
513  typedef typename linalg_traits<M>::index_sorted index_sorted;
514  static size_type ncols(const this_type &v) { return v.nc; }
515  static size_type nrows(const this_type &v) { return v.nr; }
516  static const_sub_row_type row(const const_row_iterator &it)
517  { return const_sub_row_type(linalg_traits<M>::row(it)); }
518  static sub_row_type row(const row_iterator &it)
519  { return sub_row_type(linalg_traits<M>::row(it)); }
520  static row_iterator row_begin(this_type &m) { return m.begin_; }
521  static row_iterator row_end(this_type &m) { return m.end_; }
522  static const_row_iterator row_begin(const this_type &m)
523  { return m.begin_; }
524  static const_row_iterator row_end(const this_type &m) { return m.end_; }
525  static origin_type* origin(this_type &v) { return v.origin; }
526  static const origin_type* origin(const this_type &v) { return v.origin; }
527  static void do_clear(this_type &v);
528  static value_type access(const const_row_iterator &itrow, size_type i)
529  { return real_or_imag_part(linalg_traits<M>::access(itrow, i), PART()); }
530  static reference access(const row_iterator &itrow, size_type i) {
531  return reference(ref_or_value_type<reference>::r(
532  linalg_traits<M>::access(itrow, i),
533  PART(), value_type()));
534  }
535  };
536 
537  template <typename PT, typename PART>
538  struct linalg_traits<part_col_ref<PT, PART> > {
539  typedef part_col_ref<PT, PART> this_type;
540  typedef typename std::iterator_traits<PT>::value_type M;
541  typedef typename linalg_traits<M>::origin_type origin_type;
542  typedef typename select_ref<const origin_type *, origin_type *,
543  PT>::ref_type porigin_type;
544  typedef typename which_reference<PT>::is_reference is_reference;
545  typedef abstract_matrix linalg_type;
546  typedef typename linalg_traits<M>::value_type vtype;
547  typedef typename number_traits<vtype>::magnitude_type value_type;
548  typedef typename linalg_traits<M>::storage_type storage_type;
549  typedef abstract_null_type sub_row_type;
550  typedef abstract_null_type const_sub_row_type;
551  typedef abstract_null_type row_iterator;
552  typedef abstract_null_type const_row_iterator;
553  typedef typename org_type<typename linalg_traits<M>::const_sub_col_type>::t
554  pre_const_sub_col_type;
555  typedef typename org_type<typename linalg_traits<M>::sub_col_type>::t pre_sub_col_type;
556  typedef part_vector<const pre_const_sub_col_type *, PART>
557  const_sub_col_type;
558  typedef typename select_ref<abstract_null_type,
559  part_vector<pre_sub_col_type *, PART>, PT>::ref_type sub_col_type;
560  typedef typename linalg_traits<M>::const_col_iterator const_col_iterator;
561  typedef typename select_ref<abstract_null_type, typename
562  linalg_traits<M>::col_iterator, PT>::ref_type col_iterator;
563  typedef typename select_ref<
564  typename linalg_traits<const_sub_col_type>::reference,
565  typename linalg_traits<sub_col_type>::reference,
566  PT>::ref_type reference;
567  typedef col_major sub_orientation;
568  typedef typename linalg_traits<M>::index_sorted index_sorted;
569  static size_type nrows(const this_type &v) { return v.nr; }
570  static size_type ncols(const this_type &v) { return v.nc; }
571  static const_sub_col_type col(const const_col_iterator &it)
572  { return const_sub_col_type(linalg_traits<M>::col(it)); }
573  static sub_col_type col(const col_iterator &it)
574  { return sub_col_type(linalg_traits<M>::col(it)); }
575  static col_iterator col_begin(this_type &m) { return m.begin_; }
576  static col_iterator col_end(this_type &m) { return m.end_; }
577  static const_col_iterator col_begin(const this_type &m)
578  { return m.begin_; }
579  static const_col_iterator col_end(const this_type &m) { return m.end_; }
580  static origin_type* origin(this_type &v) { return v.origin; }
581  static const origin_type* origin(const this_type &v) { return v.origin; }
582  static void do_clear(this_type &v);
583  static value_type access(const const_col_iterator &itcol, size_type i)
584  { return real_or_imag_part(linalg_traits<M>::access(itcol, i), PART()); }
585  static reference access(const col_iterator &itcol, size_type i) {
586  return reference(ref_or_value_type<reference>::r(
587  linalg_traits<M>::access(itcol, i),
588  PART(), value_type()));
589  }
590  };
591 
592  template <typename PT, typename PART>
593  void linalg_traits<part_col_ref<PT, PART> >::do_clear(this_type &v) {
594  col_iterator it = mat_col_begin(v), ite = mat_col_end(v);
595  for (; it != ite; ++it) clear(col(it));
596  }
597 
598  template <typename PT, typename PART>
599  void linalg_traits<part_row_ref<PT, PART> >::do_clear(this_type &v) {
600  row_iterator it = mat_row_begin(v), ite = mat_row_end(v);
601  for (; it != ite; ++it) clear(row(it));
602  }
603 }
604 
605 #endif // GMM_REAL_PART_H
rational_fraction< T > operator+(const polynomial< T > &P, const rational_fraction< T > &Q)
Add Q to P.
Definition: bgeot_poly.h:750
rational_fraction< T > operator-(const polynomial< T > &P, const rational_fraction< T > &Q)
Subtract Q from P.
Definition: bgeot_poly.h:757
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
Declaration of the vector types (gmm::rsvector, gmm::wsvector, gmm::slvector ,..) ...
void clear(L &l)
clear (fill with zeros) a vector or matrix.
Definition: gmm_blas.h:59
Basic definitions and tools of GMM.