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