GetFEM  5.5
gmm_real_part.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2003-2026 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, see https://www.gnu.org/licenses/.
19 
20  As a special exception, you may use this file as it is a part of a free
21  software library without restriction. Specifically, if other files
22  instantiate templates or use macros or inline functions from this file,
23  or you compile this file and link it with other files to produce an
24  executable, this file does not by itself cause the resulting executable
25  to be covered by the GNU Lesser General Public License. This exception
26  does not however invalidate any other reasons why the executable file
27  might be covered by the GNU Lesser General Public License.
28 
29 ===========================================================================*/
30 
31 /**@file gmm_real_part.h
32  @author Yves Renard <[email protected]>
33  @date September 18, 2003.
34  @brief extract the real/imaginary part of vectors/matrices
35 */
36 #ifndef GMM_REAL_PART_H
37 #define GMM_REAL_PART_H
38 
39 #include "gmm_def.h"
40 #include "gmm_vector.h"
41 #include <functional>
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)
141  : it(i.it) {}
142  part_vector_iterator &operator =
143  (const part_vector_iterator<MIT, MIT, PART> &i) { it = i.it; return *this; }
144 
145  size_type index(void) const { return it.index(); }
146  part_vector_iterator operator ++(int)
147  { part_vector_iterator tmp = *this; ++it; return tmp; }
148  part_vector_iterator operator --(int)
149  { part_vector_iterator tmp = *this; --it; return tmp; }
150  part_vector_iterator &operator ++() { ++it; return *this; }
151  part_vector_iterator &operator --() { --it; return *this; }
152  part_vector_iterator &operator +=(difference_type i)
153  { it += i; return *this; }
154  part_vector_iterator &operator -=(difference_type i)
155  { it -= i; return *this; }
156  part_vector_iterator operator +(difference_type i) const
157  { part_vector_iterator itb = *this; return (itb += i); }
158  part_vector_iterator operator -(difference_type i) const
159  { part_vector_iterator itb = *this; return (itb -= i); }
160  difference_type operator -(const part_vector_iterator &i) const
161  { return difference_type(it - i.it); }
162 
163  reference operator *() const { return reference(*it); }
164  reference operator [](size_type ii) const { return reference(it[ii]); }
165 
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 (i.it != it); }
170  bool operator < (const part_vector_iterator &i) const
171  { return (it < i.it); }
172  bool operator > (const part_vector_iterator &i) const
173  { return (it > i.it); }
174  bool operator >=(const part_vector_iterator &i) const
175  { return (it >= i.it); }
176  };
177 
178 
179  template <typename PT, typename PART> struct part_vector {
180  typedef part_vector<PT, PART> this_type;
181  typedef typename std::iterator_traits<PT>::value_type V;
182  typedef V * CPT;
183  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
184  typename linalg_traits<V>::iterator, PT>::ref_type iterator;
185  typedef typename linalg_traits<this_type>::reference reference;
186  typedef typename linalg_traits<this_type>::value_type value_type;
187  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
188 
189  iterator begin_, end_;
190  porigin_type origin;
191  size_type size_;
192 
193  size_type size(void) const { return size_; }
194 
195  reference operator[](size_type i) const {
196  return reference(ref_or_value_type<reference>::r(
197  linalg_traits<V>::access(origin, begin_, end_, i),
198  PART(), value_type()));
199  }
200 
201  part_vector(V &v)
202  : begin_(vect_begin(v)), end_(vect_end(v)),
203  origin(linalg_origin(v)), size_(gmm::vect_size(v)) {}
204  part_vector(const V &v)
205  : begin_(vect_begin(const_cast<V &>(v))),
206  end_(vect_end(const_cast<V &>(v))),
207  origin(linalg_origin(const_cast<V &>(v))), size_(gmm::vect_size(v)) {}
208  part_vector() {}
209  part_vector(const part_vector<CPT, PART> &cr)
210  : begin_(cr.begin_),end_(cr.end_),origin(cr.origin), size_(cr.size_) {}
211  };
212 
213  template <typename IT, typename MIT, typename ORG, typename PT,
214  typename PART> inline
215  void set_to_begin(part_vector_iterator<IT, MIT, PART> &it,
216  ORG o, part_vector<PT, PART> *, linalg_modifiable) {
217  typedef part_vector<PT, PART> VECT;
218  typedef typename linalg_traits<VECT>::V_reference ref_t;
219  set_to_begin(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
220  }
221  template <typename IT, typename MIT, typename ORG, typename PT,
222  typename PART> inline
223  void set_to_begin(part_vector_iterator<IT, MIT, PART> &it,
224  ORG o, const part_vector<PT, PART> *, linalg_modifiable) {
225  typedef part_vector<PT, PART> VECT;
226  typedef typename linalg_traits<VECT>::V_reference ref_t;
227  set_to_begin(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
228  }
229  template <typename IT, typename MIT, typename ORG, typename PT,
230  typename PART> inline
231  void set_to_end(part_vector_iterator<IT, MIT, PART> &it,
232  ORG o, part_vector<PT, PART> *, linalg_modifiable) {
233  typedef part_vector<PT, PART> VECT;
234  typedef typename linalg_traits<VECT>::V_reference ref_t;
235  set_to_end(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
236  }
237  template <typename IT, typename MIT, typename ORG,
238  typename PT, typename PART> inline
239  void set_to_end(part_vector_iterator<IT, MIT, PART> &it,
240  ORG o, const part_vector<PT, PART> *,
241  linalg_modifiable) {
242  typedef part_vector<PT, PART> VECT;
243  typedef typename linalg_traits<VECT>::V_reference ref_t;
244  set_to_end(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
245  }
246 
247  template <typename PT, typename PART> std::ostream &operator <<
248  (std::ostream &o, const part_vector<PT, PART>& m)
249  { gmm::write(o,m); return o; }
250 
251 
252  /* ********************************************************************* */
253  /* Reference to the real or imaginary part of (complex) matrices */
254  /* ********************************************************************* */
255 
256 
257  template <typename PT, typename PART> struct part_row_ref {
258 
259  typedef part_row_ref<PT, PART> this_type;
260  typedef typename std::iterator_traits<PT>::value_type M;
261  typedef M * CPT;
262  typedef typename std::iterator_traits<PT>::reference ref_M;
263  typedef typename select_ref<typename linalg_traits<this_type>
264  ::const_row_iterator, typename linalg_traits<this_type>
265  ::row_iterator, PT>::ref_type iterator;
266  typedef typename linalg_traits<this_type>::value_type value_type;
267  typedef typename linalg_traits<this_type>::reference reference;
268  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
269 
270  iterator begin_, end_;
271  porigin_type origin;
272  size_type nr, nc;
273 
274  part_row_ref(ref_M m)
275  : begin_(mat_row_begin(m)), end_(mat_row_end(m)),
276  origin(linalg_origin(m)), nr(mat_nrows(m)), nc(mat_ncols(m)) {}
277 
278  part_row_ref(const part_row_ref<CPT, PART> &cr) :
279  begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
280 
281  reference operator()(size_type i, size_type j) const {
282  return reference(ref_or_value_type<reference>::r(
283  linalg_traits<M>::access(begin_+i, j),
284  PART(), value_type()));
285  }
286  };
287 
288  template<typename PT, typename PART> std::ostream &operator <<
289  (std::ostream &o, const part_row_ref<PT, PART>& m)
290  { gmm::write(o,m); return o; }
291 
292  template <typename PT, typename PART> struct part_col_ref {
293 
294  typedef part_col_ref<PT, PART> this_type;
295  typedef typename std::iterator_traits<PT>::value_type M;
296  typedef M * CPT;
297  typedef typename std::iterator_traits<PT>::reference ref_M;
298  typedef typename select_ref<typename linalg_traits<this_type>
299  ::const_col_iterator, typename linalg_traits<this_type>
300  ::col_iterator, PT>::ref_type iterator;
301  typedef typename linalg_traits<this_type>::value_type value_type;
302  typedef typename linalg_traits<this_type>::reference reference;
303  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
304 
305  iterator begin_, end_;
306  porigin_type origin;
307  size_type nr, nc;
308 
309  part_col_ref(ref_M m)
310  : begin_(mat_col_begin(m)), end_(mat_col_end(m)),
311  origin(linalg_origin(m)), nr(mat_nrows(m)), nc(mat_ncols(m)) {}
312 
313  part_col_ref(const part_col_ref<CPT, PART> &cr) :
314  begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
315 
316  reference operator()(size_type i, size_type j) const {
317  return reference(ref_or_value_type<reference>::r(
318  linalg_traits<M>::access(begin_+j, i),
319  PART(), value_type()));
320  }
321  };
322 
323 
324 
325  template<typename PT, typename PART> std::ostream &operator <<
326  (std::ostream &o, const part_col_ref<PT, PART>& m)
327  { gmm::write(o,m); return o; }
328 
329 
330 
331 
332 
333 
334 template <typename TYPE, typename PART, typename PT>
335  struct part_return_ {
336  typedef abstract_null_type return_type;
337  };
338  template <typename PT, typename PART>
339  struct part_return_<row_major, PART, PT> {
340  typedef typename std::iterator_traits<PT>::value_type L;
341  typedef typename select_return<part_row_ref<const L *, PART>,
342  part_row_ref< L *, PART>, PT>::return_type return_type;
343  };
344  template <typename PT, typename PART>
345  struct part_return_<col_major, PART, PT> {
346  typedef typename std::iterator_traits<PT>::value_type L;
347  typedef typename select_return<part_col_ref<const L *, PART>,
348  part_col_ref<L *, PART>, PT>::return_type return_type;
349  };
350 
351  template <typename PT, typename PART, typename LT> struct part_return__{
352  typedef abstract_null_type return_type;
353  };
354 
355  template <typename PT, typename PART>
356  struct part_return__<PT, PART, abstract_matrix> {
357  typedef typename std::iterator_traits<PT>::value_type L;
358  typedef typename part_return_<typename principal_orientation_type<
359  typename linalg_traits<L>::sub_orientation>::potype, PART,
360  PT>::return_type return_type;
361  };
362 
363  template <typename PT, typename PART>
364  struct part_return__<PT, PART, abstract_vector> {
365  typedef typename std::iterator_traits<PT>::value_type L;
366  typedef typename select_return<part_vector<const L *, PART>,
367  part_vector<L *, PART>, PT>::return_type return_type;
368  };
369 
370  template <typename PT, typename PART> struct part_return {
371  typedef typename std::iterator_traits<PT>::value_type L;
372  typedef typename part_return__<PT, PART,
373  typename linalg_traits<L>::linalg_type>::return_type return_type;
374  };
375 
376  template <typename L> inline
377  typename part_return<const L *, linalg_real_part>::return_type
378  real_part(const L &l) {
379  return typename part_return<const L *, linalg_real_part>::return_type
380  (linalg_cast(const_cast<L &>(l)));
381  }
382 
383  template <typename L> inline
384  typename part_return<L *, linalg_real_part>::return_type
385  real_part(L &l) {
386  return typename part_return<L *, linalg_real_part>::return_type(linalg_cast(l));
387  }
388 
389  template <typename L> inline
390  typename part_return<const L *, linalg_imag_part>::return_type
391  imag_part(const L &l) {
392  return typename part_return<const L *, linalg_imag_part>::return_type
393  (linalg_cast(const_cast<L &>(l)));
394  }
395 
396  template <typename L> inline
397  typename part_return<L *, linalg_imag_part>::return_type
398  imag_part(L &l) {
399  return typename part_return<L *, linalg_imag_part>::return_type(linalg_cast(l));
400  }
401 
402 
403  template <typename PT, typename PART>
404  struct linalg_traits<part_vector<PT, PART> > {
405  typedef part_vector<PT, PART> this_type;
406  typedef this_type * pthis_type;
407  typedef PT pV;
408  typedef typename std::iterator_traits<PT>::value_type V;
409  typedef typename linalg_traits<V>::index_sorted index_sorted;
410  typedef typename linalg_traits<V>::is_reference V_reference;
411  typedef typename linalg_traits<V>::origin_type origin_type;
412  typedef typename select_ref<const origin_type *, origin_type *,
413  PT>::ref_type porigin_type;
414  typedef typename which_reference<PT>::is_reference is_reference;
415  typedef abstract_vector linalg_type;
416  typedef typename linalg_traits<V>::value_type vtype;
417  typedef typename number_traits<vtype>::magnitude_type value_type;
418  typedef typename select_ref<value_type, ref_elt_vector<value_type,
419  which_part<typename linalg_traits<V>::reference,
420  PART> >, PT>::ref_type reference;
421  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
422  typename linalg_traits<V>::iterator, PT>::ref_type pre_iterator;
423  typedef typename select_ref<abstract_null_type,
424  part_vector_iterator<pre_iterator, pre_iterator, PART>,
425  PT>::ref_type iterator;
426  typedef part_vector_iterator<typename linalg_traits<V>::const_iterator,
427  pre_iterator, PART> const_iterator;
428  typedef typename linalg_traits<V>::storage_type storage_type;
429  static size_type size(const this_type &v) { return v.size(); }
430  static iterator begin(this_type &v) {
431  iterator it; it.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 const_iterator begin(const this_type &v) {
437  const_iterator it(v.begin_);
438  if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
439  { set_to_begin(it, v.origin, pthis_type(), is_reference()); }
440  return it;
441  }
442  static iterator end(this_type &v) {
443  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 const_iterator end(const this_type &v) {
449  const_iterator it(v.end_);
450  if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
451  set_to_end(it, v.origin, pthis_type(), is_reference());
452  return it;
453  }
454  static origin_type* origin(this_type &v) { return v.origin; }
455  static const origin_type* origin(const this_type &v) { return v.origin; }
456 
457  static void clear(origin_type* o, const iterator &begin_,
458  const iterator &end_, abstract_sparse) {
459  std::deque<size_type> ind;
460  iterator it = begin_;
461  for (; it != end_; ++it) ind.push_front(it.index());
462  for (; !(ind.empty()); ind.pop_back())
463  access(o, begin_, end_, ind.back()) = value_type(0);
464  }
465  static void clear(origin_type* o, const iterator &begin_,
466  const iterator &end_, abstract_skyline) {
467  clear(o, begin_, end_, abstract_sparse());
468  }
469  static void clear(origin_type* o, const iterator &begin_,
470  const iterator &end_, abstract_dense) {
471  for (iterator it = begin_; it != end_; ++it)
472  *it = value_type(0);
473  }
474 
475  static void clear(origin_type* o, const iterator &begin_,
476  const iterator &end_)
477  { clear(o, begin_, end_, storage_type()); }
478  static void do_clear(this_type &v) { clear(v.origin, begin(v), end(v)); }
479  static value_type access(const origin_type *o, const const_iterator &it,
480  const const_iterator &ite, size_type i) {
481  return real_or_imag_part(linalg_traits<V>::access(o, it.it, ite.it,i),
482  PART());
483  }
484  static reference access(origin_type *o, const iterator &it,
485  const iterator &ite, size_type i)
486  { return reference(linalg_traits<V>::access(o, it.it, ite.it,i)); }
487  };
488 
489  template <typename PT, typename PART>
490  struct linalg_traits<part_row_ref<PT, PART> > {
491  typedef part_row_ref<PT, PART> this_type;
492  typedef typename std::iterator_traits<PT>::value_type M;
493  typedef typename linalg_traits<M>::origin_type origin_type;
494  typedef typename select_ref<const origin_type *, origin_type *,
495  PT>::ref_type porigin_type;
496  typedef typename which_reference<PT>::is_reference is_reference;
497  typedef abstract_matrix linalg_type;
498  typedef typename linalg_traits<M>::value_type vtype;
499  typedef typename number_traits<vtype>::magnitude_type value_type;
500  typedef typename linalg_traits<M>::storage_type storage_type;
501  typedef abstract_null_type sub_col_type;
502  typedef abstract_null_type const_sub_col_type;
503  typedef abstract_null_type col_iterator;
504  typedef abstract_null_type const_col_iterator;
505  typedef typename org_type<typename linalg_traits<M>::const_sub_row_type>::t
506  pre_const_sub_row_type;
507  typedef typename org_type<typename linalg_traits<M>::sub_row_type>::t pre_sub_row_type;
508  typedef part_vector<const pre_const_sub_row_type *, PART>
509  const_sub_row_type;
510  typedef typename select_ref<abstract_null_type,
511  part_vector<pre_sub_row_type *, PART>, PT>::ref_type sub_row_type;
512  typedef typename linalg_traits<M>::const_row_iterator const_row_iterator;
513  typedef typename select_ref<abstract_null_type, typename
514  linalg_traits<M>::row_iterator, PT>::ref_type row_iterator;
515  typedef typename select_ref<
516  typename linalg_traits<const_sub_row_type>::reference,
517  typename linalg_traits<sub_row_type>::reference,
518  PT>::ref_type reference;
519  typedef row_major sub_orientation;
520  typedef typename linalg_traits<M>::index_sorted index_sorted;
521  static size_type ncols(const this_type &v) { return v.nc; }
522  static size_type nrows(const this_type &v) { return v.nr; }
523  static const_sub_row_type row(const const_row_iterator &it)
524  { return const_sub_row_type(linalg_traits<M>::row(it)); }
525  static sub_row_type row(const row_iterator &it)
526  { return sub_row_type(linalg_traits<M>::row(it)); }
527  static row_iterator row_begin(this_type &m) { return m.begin_; }
528  static row_iterator row_end(this_type &m) { return m.end_; }
529  static const_row_iterator row_begin(const this_type &m)
530  { return m.begin_; }
531  static const_row_iterator row_end(const this_type &m) { return m.end_; }
532  static origin_type* origin(this_type &v) { return v.origin; }
533  static const origin_type* origin(const this_type &v) { return v.origin; }
534  static void do_clear(this_type &v);
535  static value_type access(const const_row_iterator &itrow, size_type i)
536  { return real_or_imag_part(linalg_traits<M>::access(itrow, i), PART()); }
537  static reference access(const row_iterator &itrow, size_type i) {
538  return reference(ref_or_value_type<reference>::r(
539  linalg_traits<M>::access(itrow, i),
540  PART(), value_type()));
541  }
542  };
543 
544  template <typename PT, typename PART>
545  struct linalg_traits<part_col_ref<PT, PART> > {
546  typedef part_col_ref<PT, PART> this_type;
547  typedef typename std::iterator_traits<PT>::value_type M;
548  typedef typename linalg_traits<M>::origin_type origin_type;
549  typedef typename select_ref<const origin_type *, origin_type *,
550  PT>::ref_type porigin_type;
551  typedef typename which_reference<PT>::is_reference is_reference;
552  typedef abstract_matrix linalg_type;
553  typedef typename linalg_traits<M>::value_type vtype;
554  typedef typename number_traits<vtype>::magnitude_type value_type;
555  typedef typename linalg_traits<M>::storage_type storage_type;
556  typedef abstract_null_type sub_row_type;
557  typedef abstract_null_type const_sub_row_type;
558  typedef abstract_null_type row_iterator;
559  typedef abstract_null_type const_row_iterator;
560  typedef typename org_type<typename linalg_traits<M>::const_sub_col_type>::t
561  pre_const_sub_col_type;
562  typedef typename org_type<typename linalg_traits<M>::sub_col_type>::t pre_sub_col_type;
563  typedef part_vector<const pre_const_sub_col_type *, PART>
564  const_sub_col_type;
565  typedef typename select_ref<abstract_null_type,
566  part_vector<pre_sub_col_type *, PART>, PT>::ref_type sub_col_type;
567  typedef typename linalg_traits<M>::const_col_iterator const_col_iterator;
568  typedef typename select_ref<abstract_null_type, typename
569  linalg_traits<M>::col_iterator, PT>::ref_type col_iterator;
570  typedef typename select_ref<
571  typename linalg_traits<const_sub_col_type>::reference,
572  typename linalg_traits<sub_col_type>::reference,
573  PT>::ref_type reference;
574  typedef col_major sub_orientation;
575  typedef typename linalg_traits<M>::index_sorted index_sorted;
576  static size_type nrows(const this_type &v) { return v.nr; }
577  static size_type ncols(const this_type &v) { return v.nc; }
578  static const_sub_col_type col(const const_col_iterator &it)
579  { return const_sub_col_type(linalg_traits<M>::col(it)); }
580  static sub_col_type col(const col_iterator &it)
581  { return sub_col_type(linalg_traits<M>::col(it)); }
582  static col_iterator col_begin(this_type &m) { return m.begin_; }
583  static col_iterator col_end(this_type &m) { return m.end_; }
584  static const_col_iterator col_begin(const this_type &m)
585  { return m.begin_; }
586  static const_col_iterator col_end(const this_type &m) { return m.end_; }
587  static origin_type* origin(this_type &v) { return v.origin; }
588  static const origin_type* origin(const this_type &v) { return v.origin; }
589  static void do_clear(this_type &v);
590  static value_type access(const const_col_iterator &itcol, size_type i)
591  { return real_or_imag_part(linalg_traits<M>::access(itcol, i), PART()); }
592  static reference access(const col_iterator &itcol, size_type i) {
593  return reference(ref_or_value_type<reference>::r(
594  linalg_traits<M>::access(itcol, i),
595  PART(), value_type()));
596  }
597  };
598 
599  template <typename PT, typename PART>
600  void linalg_traits<part_col_ref<PT, PART> >::do_clear(this_type &v) {
601  col_iterator it = mat_col_begin(v), ite = mat_col_end(v);
602  for (; it != ite; ++it) clear(col(it));
603  }
604 
605  template <typename PT, typename PART>
606  void linalg_traits<part_row_ref<PT, PART> >::do_clear(this_type &v) {
607  row_iterator it = mat_row_begin(v), ite = mat_row_end(v);
608  for (; it != ite; ++it) clear(row(it));
609  }
610 }
611 
612 #endif // GMM_REAL_PART_H
void clear(L &l)
clear (fill with zeros) a vector or matrix.
Definition: gmm_blas.h:58
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:755
rational_fraction< T > operator+(const polynomial< T > &P, const rational_fraction< T > &Q)
Add Q to P.
Definition: bgeot_poly.h:748
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:48