GetFEM++  5.3
gmm_sub_vector.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2002-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_sub_vector.h
33  @author Yves Renard <Yves.Renard@insa-lyon.fr>
34  @date October 13, 2002.
35  @brief Generic sub-vectors.
36 */
37 
38 #ifndef GMM_SUB_VECTOR_H__
39 #define GMM_SUB_VECTOR_H__
40 
41 #include "gmm_interface.h"
42 #include "gmm_sub_index.h"
43 
44 namespace gmm {
45 
46  /* ********************************************************************* */
47  /* sparse sub-vectors */
48  /* ********************************************************************* */
49 
50  template <typename IT, typename MIT, typename SUBI>
51  struct sparse_sub_vector_iterator {
52 
53  IT itb, itbe;
54  SUBI si;
55 
56  typedef std::iterator_traits<IT> traits_type;
57  typedef typename traits_type::value_type value_type;
58  typedef typename traits_type::pointer pointer;
59  typedef typename traits_type::reference reference;
60  typedef typename traits_type::difference_type difference_type;
61  typedef std::bidirectional_iterator_tag iterator_category;
62  typedef size_t size_type;
63  typedef sparse_sub_vector_iterator<IT, MIT, SUBI> iterator;
64 
65  size_type index(void) const { return si.rindex(itb.index()); }
66  void forward(void);
67  void backward(void);
68  iterator &operator ++()
69  { ++itb; forward(); return *this; }
70  iterator operator ++(int) { iterator tmp = *this; ++(*this); return tmp; }
71  iterator &operator --()
72  { --itb; backward(); return *this; }
73  iterator operator --(int) { iterator tmp = *this; --(*this); return tmp; }
74  reference operator *() const { return *itb; }
75 
76  bool operator ==(const iterator &i) const { return itb == i.itb; }
77  bool operator !=(const iterator &i) const { return !(i == *this); }
78 
79  sparse_sub_vector_iterator(void) {}
80  sparse_sub_vector_iterator(const IT &it, const IT &ite, const SUBI &s)
81  : itb(it), itbe(ite), si(s) { forward(); }
82  sparse_sub_vector_iterator(const sparse_sub_vector_iterator<MIT, MIT,
83  SUBI> &it) : itb(it.itb), itbe(it.itbe), si(it.si) {}
84  };
85 
86  template <typename IT, typename MIT, typename SUBI>
87  void sparse_sub_vector_iterator<IT, MIT, SUBI>::forward(void)
88  { while(itb!=itbe && index()==size_type(-1)) { ++itb; } }
89 
90  template <typename IT, typename MIT, typename SUBI>
91  void sparse_sub_vector_iterator<IT, MIT, SUBI>::backward(void)
92  { while(itb!=itbe && index()==size_type(-1)) --itb; }
93 
94  template <typename PT, typename SUBI> struct sparse_sub_vector {
95  typedef sparse_sub_vector<PT, SUBI> this_type;
96  typedef typename std::iterator_traits<PT>::value_type V;
97  typedef V * CPT;
98  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
99  typename linalg_traits<V>::iterator, PT>::ref_type iterator;
100  typedef typename linalg_traits<this_type>::reference reference;
101  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
102 
103  iterator begin_, end_;
104  porigin_type origin;
105  SUBI si;
106 
107  size_type size(void) const { return si.size(); }
108 
109  reference operator[](size_type i) const
110  { return linalg_traits<V>::access(origin, begin_, end_, si.index(i)); }
111 
112  sparse_sub_vector(V &v, const SUBI &s) : begin_(vect_begin(v)),
113  end_(vect_end(v)), origin(linalg_origin(v)), si(s) {}
114  sparse_sub_vector(const V &v, const SUBI &s)
115  : begin_(vect_begin(const_cast<V &>(v))),
116  end_(vect_end(const_cast<V &>(v))),
117  origin(linalg_origin(const_cast<V &>(v))), si(s) {}
118  sparse_sub_vector() {}
119  sparse_sub_vector(const sparse_sub_vector<CPT, SUBI> &cr)
120  : begin_(cr.begin_),end_(cr.end_),origin(cr.origin), si(cr.si) {}
121  };
122 
123  template <typename IT, typename MIT, typename SUBI, typename ORG,
124  typename PT> inline
125  void set_to_begin(sparse_sub_vector_iterator<IT, MIT, SUBI> &it,
126  ORG o, sparse_sub_vector<PT, SUBI> *,
127  linalg_modifiable) {
128  typedef sparse_sub_vector<PT, SUBI> VECT;
129  typedef typename linalg_traits<VECT>::V_reference ref_t;
130  set_to_begin(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
131  set_to_end(it.itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
132  it.forward();
133  }
134  template <typename IT, typename MIT, typename SUBI, typename ORG,
135  typename PT> inline
136  void set_to_begin(sparse_sub_vector_iterator<IT, MIT, SUBI> &it,
137  ORG o, const sparse_sub_vector<PT, SUBI> *,
138  linalg_modifiable) {
139  typedef sparse_sub_vector<PT, SUBI> VECT;
140  typedef typename linalg_traits<VECT>::V_reference ref_t;
141  set_to_begin(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
142  set_to_end(it.itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
143  it.forward();
144  }
145 
146  template <typename IT, typename MIT, typename SUBI, typename ORG,
147  typename PT> inline
148  void set_to_end(sparse_sub_vector_iterator<IT, MIT, SUBI> &it,
149  ORG o, sparse_sub_vector<PT, SUBI> *, linalg_modifiable) {
150  typedef sparse_sub_vector<PT, SUBI> VECT;
151  typedef typename linalg_traits<VECT>::V_reference ref_t;
152  set_to_end(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
153  set_to_end(it.itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
154  it.forward();
155  }
156  template <typename IT, typename MIT, typename SUBI, typename ORG,
157  typename PT> inline
158  void set_to_end(sparse_sub_vector_iterator<IT, MIT, SUBI> &it,
159  ORG o, const sparse_sub_vector<PT, SUBI> *,
160  linalg_modifiable) {
161  typedef sparse_sub_vector<PT, SUBI> VECT;
162  typedef typename linalg_traits<VECT>::V_reference ref_t;
163  set_to_end(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
164  set_to_end(it.itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
165  it.forward();
166  }
167 
168  template <typename PT, typename SUBI>
169  struct linalg_traits<sparse_sub_vector<PT, SUBI> > {
170  typedef sparse_sub_vector<PT, SUBI> this_type;
171  typedef this_type * pthis_type;
172  typedef PT pV;
173  typedef typename std::iterator_traits<PT>::value_type V;
174  typedef typename linalg_and<typename index_is_sorted<SUBI>::bool_type,
175  typename linalg_traits<V>::index_sorted>::bool_type index_sorted;
176  typedef typename linalg_traits<V>::is_reference V_reference;
177  typedef typename linalg_traits<V>::origin_type origin_type;
178  typedef typename select_ref<const origin_type *, origin_type *,
179  PT>::ref_type porigin_type;
180  typedef typename which_reference<PT>::is_reference is_reference;
181  typedef abstract_vector linalg_type;
182  typedef typename linalg_traits<V>::value_type value_type;
183  typedef typename select_ref<value_type, typename
184  linalg_traits<V>::reference, PT>::ref_type reference;
185  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
186  typename linalg_traits<V>::iterator, PT>::ref_type pre_iterator;
187  typedef typename select_ref<abstract_null_type,
188  sparse_sub_vector_iterator<pre_iterator, pre_iterator, SUBI>,
189  PT>::ref_type iterator;
190  typedef sparse_sub_vector_iterator<typename linalg_traits<V>
191  ::const_iterator, pre_iterator, SUBI> const_iterator;
192  typedef abstract_sparse storage_type;
193  static size_type size(const this_type &v) { return v.size(); }
194  static iterator begin(this_type &v) {
195  iterator it;
196  it.itb = v.begin_; it.itbe = v.end_; it.si = v.si;
197  if (!is_const_reference(is_reference()))
198  set_to_begin(it, v.origin, pthis_type(), is_reference());
199  else it.forward();
200  return it;
201  }
202  static const_iterator begin(const this_type &v) {
203  const_iterator it; it.itb = v.begin_; it.itbe = v.end_; it.si = v.si;
204  if (!is_const_reference(is_reference()))
205  { set_to_begin(it, v.origin, pthis_type(), is_reference()); }
206  else it.forward();
207  return it;
208  }
209  static iterator end(this_type &v) {
210  iterator it;
211  it.itb = v.end_; it.itbe = v.end_; it.si = v.si;
212  if (!is_const_reference(is_reference()))
213  set_to_end(it, v.origin, pthis_type(), is_reference());
214  else it.forward();
215  return it;
216  }
217  static const_iterator end(const this_type &v) {
218  const_iterator it; it.itb = v.end_; it.itbe = v.end_; it.si = v.si;
219  if (!is_const_reference(is_reference()))
220  set_to_end(it, v.origin, pthis_type(), is_reference());
221  else it.forward();
222  return it;
223  }
224  static origin_type* origin(this_type &v) { return v.origin; }
225  static const origin_type* origin(const this_type &v) { return v.origin; }
226  static void clear(origin_type* o, const iterator &begin_,
227  const iterator &end_) {
228  std::deque<size_type> ind;
229  iterator it = begin_;
230  for (; it != end_; ++it) ind.push_front(it.index());
231  for (; !(ind.empty()); ind.pop_back())
232  access(o, begin_, end_, ind.back()) = value_type(0);
233  }
234  static void do_clear(this_type &v) { clear(v.origin, begin(v), end(v)); }
235  static value_type access(const origin_type *o, const const_iterator &it,
236  const const_iterator &ite, size_type i)
237  { return linalg_traits<V>::access(o, it.itb, ite.itb, it.si.index(i)); }
238  static reference access(origin_type *o, const iterator &it,
239  const iterator &ite, size_type i)
240  { return linalg_traits<V>::access(o, it.itb, ite.itb, it.si.index(i)); }
241  };
242 
243  template <typename PT, typename SUBI> std::ostream &operator <<
244  (std::ostream &o, const sparse_sub_vector<PT, SUBI>& m)
245  { gmm::write(o,m); return o; }
246 
247  /* ********************************************************************* */
248  /* skyline sub-vectors */
249  /* ********************************************************************* */
250 
251  template <typename IT, typename MIT, typename SUBI>
252  struct skyline_sub_vector_iterator {
253 
254  IT itb;
255  SUBI si;
256 
257  typedef std::iterator_traits<IT> traits_type;
258  typedef typename traits_type::value_type value_type;
259  typedef typename traits_type::pointer pointer;
260  typedef typename traits_type::reference reference;
261  typedef typename traits_type::difference_type difference_type;
262  typedef std::bidirectional_iterator_tag iterator_category;
263  typedef size_t size_type;
264  typedef skyline_sub_vector_iterator<IT, MIT, SUBI> iterator;
265 
266  size_type index(void) const
267  { return (itb.index() - si.min + si.step() - 1) / si.step(); }
268  void backward(void);
269  iterator &operator ++()
270  { itb += si.step(); return *this; }
271  iterator operator ++(int) { iterator tmp = *this; ++(*this); return tmp; }
272  iterator &operator --()
273  { itb -= si.step(); return *this; }
274  iterator operator --(int) { iterator tmp = *this; --(*this); return tmp; }
275 
276  iterator &operator +=(difference_type i)
277  { itb += si.step() * i; return *this; }
278  iterator &operator -=(difference_type i)
279  { itb -= si.step() * i; return *this; }
280  iterator operator +(difference_type i) const
281  { iterator ii = *this; return (ii += i); }
282  iterator operator -(difference_type i) const
283  { iterator ii = *this; return (ii -= i); }
284  difference_type operator -(const iterator &i) const
285  { return (itb - i.itb) / si.step(); }
286 
287  reference operator *() const { return *itb; }
288  reference operator [](int ii) { return *(itb + ii * si.step()); }
289 
290  bool operator ==(const iterator &i) const { return index() == i.index();}
291  bool operator !=(const iterator &i) const { return !(i == *this); }
292  bool operator < (const iterator &i) const { return index() < i.index();}
293 
294  skyline_sub_vector_iterator(void) {}
295  skyline_sub_vector_iterator(const IT &it, const SUBI &s)
296  : itb(it), si(s) {}
297  skyline_sub_vector_iterator(const skyline_sub_vector_iterator<MIT, MIT,
298  SUBI> &it) : itb(it.itb), si(it.si) {}
299  };
300 
301  template <typename IT, typename SUBI>
302  void update_for_sub_skyline(IT &it, IT &ite, const SUBI &si) {
303  if (it.index() >= si.max || ite.index() <= si.min) { it = ite; return; }
304  ptrdiff_t dec1 = si.min - it.index(), dec2 = ite.index() - si.max;
305  it += (dec1 < 0) ? ((si.step()-((-dec1) % si.step())) % si.step()) : dec1;
306  ite -= (dec2 < 0) ? -((-dec2) % si.step()) : dec2;
307  }
308 
309  template <typename PT, typename SUBI> struct skyline_sub_vector {
310  typedef skyline_sub_vector<PT, SUBI> this_type;
311  typedef typename std::iterator_traits<PT>::value_type V;
312  typedef V * pV;
313  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
314  typename linalg_traits<V>::iterator, PT>::ref_type iterator;
315  typedef typename linalg_traits<this_type>::reference reference;
316  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
317 
318  iterator begin_, end_;
319  porigin_type origin;
320  SUBI si;
321 
322  size_type size(void) const { return si.size(); }
323 
324  reference operator[](size_type i) const
325  { return linalg_traits<V>::access(origin, begin_, end_, si.index(i)); }
326 
327  skyline_sub_vector(V &v, const SUBI &s) : begin_(vect_begin(v)),
328  end_(vect_end(v)), origin(linalg_origin(v)), si(s) {
329  update_for_sub_skyline(begin_, end_, si);
330  }
331  skyline_sub_vector(const V &v, const SUBI &s)
332  : begin_(vect_begin(const_cast<V &>(v))),
333  end_(vect_end(const_cast<V &>(v))),
334  origin(linalg_origin(const_cast<V &>(v))), si(s) {
335  update_for_sub_skyline(begin_, end_, si);
336  }
337  skyline_sub_vector() {}
338  skyline_sub_vector(const skyline_sub_vector<pV, SUBI> &cr)
339  : begin_(cr.begin_),end_(cr.end_),origin(cr.origin), si(cr.si) {}
340  };
341 
342  template <typename IT, typename MIT, typename SUBI, typename ORG,
343  typename PT> inline
344  void set_to_begin(skyline_sub_vector_iterator<IT, MIT, SUBI> &it,
345  ORG o, skyline_sub_vector<PT, SUBI> *,
346  linalg_modifiable) {
347  typedef skyline_sub_vector<PT, SUBI> VECT;
348  typedef typename linalg_traits<VECT>::V_reference ref_t;
349  IT itbe = it.itb;
350  set_to_begin(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
351  set_to_end(itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
352  update_for_sub_skyline(it.itb, itbe, it.si);
353  }
354  template <typename IT, typename MIT, typename SUBI, typename ORG,
355  typename PT> inline
356  void set_to_begin(skyline_sub_vector_iterator<IT, MIT, SUBI> &it,
357  ORG o, const skyline_sub_vector<PT, SUBI> *,
358  linalg_modifiable) {
359  typedef skyline_sub_vector<PT, SUBI> VECT;
360  typedef typename linalg_traits<VECT>::V_reference ref_t;
361  IT itbe = it.itb;
362  set_to_begin(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
363  set_to_end(itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
364  update_for_sub_skyline(it.itb, itbe, it.si);
365  }
366 
367  template <typename IT, typename MIT, typename SUBI, typename ORG,
368  typename PT> inline
369  void set_to_end(skyline_sub_vector_iterator<IT, MIT, SUBI> &it,
370  ORG o, skyline_sub_vector<PT, SUBI> *,
371  linalg_modifiable) {
372  typedef skyline_sub_vector<PT, SUBI> VECT;
373  typedef typename linalg_traits<VECT>::V_reference ref_t;
374  IT itb = it.itb;
375  set_to_begin(itb, o, typename linalg_traits<VECT>::pV(), ref_t());
376  set_to_end(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
377  update_for_sub_skyline(itb, it.itb, it.si);
378  }
379  template <typename IT, typename MIT, typename SUBI, typename ORG,
380  typename PT> inline
381  void set_to_end(skyline_sub_vector_iterator<IT, MIT, SUBI> &it,
382  ORG o, const skyline_sub_vector<PT, SUBI> *,
383  linalg_modifiable) {
384  typedef skyline_sub_vector<PT, SUBI> VECT;
385  typedef typename linalg_traits<VECT>::V_reference ref_t;
386  IT itb = it.itb;
387  set_to_begin(itb, o, typename linalg_traits<VECT>::pV(), ref_t());
388  set_to_end(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
389  update_for_sub_skyline(itb, it.itb, it.si);
390  }
391 
392 
393  template <typename PT, typename SUBI>
394  struct linalg_traits<skyline_sub_vector<PT, SUBI> > {
395  typedef skyline_sub_vector<PT, SUBI> this_type;
396  typedef this_type *pthis_type;
397  typedef typename std::iterator_traits<PT>::value_type V;
398  typedef typename linalg_traits<V>::is_reference V_reference;
399  typedef typename linalg_traits<V>::origin_type origin_type;
400  typedef typename select_ref<const origin_type *, origin_type *,
401  PT>::ref_type porigin_type;
402  typedef V * pV;
403  typedef typename which_reference<PT>::is_reference is_reference;
404  typedef abstract_vector linalg_type;
405  typedef typename linalg_traits<V>::value_type value_type;
406  typedef typename select_ref<value_type, typename
407  linalg_traits<V>::reference, PT>::ref_type reference;
408  typedef typename linalg_traits<V>::const_iterator const_V_iterator;
409  typedef typename linalg_traits<V>::iterator V_iterator;
410  typedef typename select_ref<const_V_iterator, V_iterator,
411  PT>::ref_type pre_iterator;
412  typedef typename select_ref<abstract_null_type,
413  skyline_sub_vector_iterator<pre_iterator, pre_iterator, SUBI>,
414  PT>::ref_type iterator;
415  typedef skyline_sub_vector_iterator<const_V_iterator, pre_iterator, SUBI>
416  const_iterator;
417  typedef abstract_skyline storage_type;
418  typedef linalg_true index_sorted;
419  static size_type size(const this_type &v) { return v.size(); }
420  static iterator begin(this_type &v) {
421  iterator it;
422  it.itb = v.begin_; it.si = v.si;
423  if (!is_const_reference(is_reference()))
424  set_to_begin(it, v.origin, pthis_type(), is_reference());
425  return it;
426  }
427  static const_iterator begin(const this_type &v) {
428  const_iterator it; it.itb = v.begin_; it.si = v.si;
429  if (!is_const_reference(is_reference()))
430  { set_to_begin(it, v.origin, pthis_type(), is_reference()); }
431  return it;
432  }
433  static iterator end(this_type &v) {
434  iterator it;
435  it.itb = v.end_; it.si = v.si;
436  if (!is_const_reference(is_reference()))
437  set_to_end(it, v.origin, pthis_type(), is_reference());
438  return it;
439  }
440  static const_iterator end(const this_type &v) {
441  const_iterator it; it.itb = v.end_; it.si = v.si;
442  if (!is_const_reference(is_reference()))
443  set_to_end(it, v.origin, pthis_type(), is_reference());
444  return it;
445  }
446  static origin_type* origin(this_type &v) { return v.origin; }
447  static const origin_type* origin(const this_type &v) { return v.origin; }
448  static void clear(origin_type*, const iterator &it, const iterator &ite)
449  { std::fill(it, ite, value_type(0)); }
450  static void do_clear(this_type &v) { clear(v.origin, begin(v), end(v)); }
451  static value_type access(const origin_type *o, const const_iterator &it,
452  const const_iterator &ite, size_type i)
453  { return linalg_traits<V>::access(o, it.itb, ite.itb, it.si.index(i)); }
454  static reference access(origin_type *o, const iterator &it,
455  const iterator &ite, size_type i)
456  { return linalg_traits<V>::access(o, it.itb, ite.itb, it.si.index(i)); }
457  };
458 
459  template <typename PT, typename SUBI> std::ostream &operator <<
460  (std::ostream &o, const skyline_sub_vector<PT, SUBI>& m)
461  { gmm::write(o,m); return o; }
462 
463  /* ******************************************************************** */
464  /* sub vector. */
465  /* ******************************************************************** */
466  /* sub_vector_type<PT, SUBI>::vector_type is the sub vector type */
467  /* returned by sub_vector(v, sub_index) */
468  /************************************************************************/
469 
470  template <typename PT, typename SUBI, typename st_type> struct svrt_ir {
471  typedef abstract_null_type vector_type;
472  };
473 
474  template <typename PT>
475  struct svrt_ir<PT, sub_index, abstract_dense> {
476  typedef typename std::iterator_traits<PT>::value_type V;
477  typedef typename vect_ref_type<PT, V>::iterator iterator;
478  typedef tab_ref_index_ref_with_origin<iterator,
479  sub_index::const_iterator, V> vector_type;
480  };
481 
482  template <typename PT>
483  struct svrt_ir<PT, unsorted_sub_index, abstract_dense> {
484  typedef typename std::iterator_traits<PT>::value_type V;
485  typedef typename vect_ref_type<PT, V>::iterator iterator;
486  typedef tab_ref_index_ref_with_origin<iterator,
487  unsorted_sub_index::const_iterator, V> vector_type;
488  };
489 
490  template <typename PT>
491  struct svrt_ir<PT, sub_interval, abstract_dense> {
492  typedef typename std::iterator_traits<PT>::value_type V;
493  typedef typename vect_ref_type<PT, V>::iterator iterator;
494  typedef tab_ref_with_origin<iterator, V> vector_type;
495  };
496 
497  template <typename PT>
498  struct svrt_ir<PT, sub_slice, abstract_dense> {
499  typedef typename std::iterator_traits<PT>::value_type V;
500  typedef typename vect_ref_type<PT, V>::iterator iterator;
501  typedef tab_ref_reg_spaced_with_origin<iterator, V> vector_type;
502  };
503 
504  template <typename PT, typename SUBI>
505  struct svrt_ir<PT, SUBI, abstract_skyline> {
506  typedef skyline_sub_vector<PT, SUBI> vector_type;
507  };
508 
509  template <typename PT>
510  struct svrt_ir<PT, sub_index, abstract_skyline> {
511  typedef sparse_sub_vector<PT, sub_index> vector_type;
512  };
513 
514  template <typename PT>
515  struct svrt_ir<PT, unsorted_sub_index, abstract_skyline> {
516  typedef sparse_sub_vector<PT, unsorted_sub_index> vector_type;
517  };
518 
519 
520  template <typename PT, typename SUBI>
521  struct svrt_ir<PT, SUBI, abstract_sparse> {
522  typedef sparse_sub_vector<PT, SUBI> vector_type;
523  };
524 
525  template <typename PT, typename SUBI>
526  struct sub_vector_type {
527  typedef typename std::iterator_traits<PT>::value_type V;
528  typedef typename svrt_ir<PT, SUBI,
529  typename linalg_traits<V>::storage_type>::vector_type vector_type;
530  };
531 
532  template <typename V, typename SUBI>
533  typename select_return<
534  typename sub_vector_type<const V *, SUBI>::vector_type,
535  typename sub_vector_type<V *, SUBI>::vector_type, const V *>::return_type
536  sub_vector(const V &v, const SUBI &si) {
537  GMM_ASSERT2(si.last() <= vect_size(v),
538  "sub vector too large, " << si.last() << " > " << vect_size(v));
539  return typename select_return<
540  typename sub_vector_type<const V *, SUBI>::vector_type,
541  typename sub_vector_type<V *, SUBI>::vector_type, const V *>::return_type
542  (linalg_cast(v), si);
543  }
544 
545  template <typename V, typename SUBI>
546  typename select_return<
547  typename sub_vector_type<const V *, SUBI>::vector_type,
548  typename sub_vector_type<V *, SUBI>::vector_type, V *>::return_type
549  sub_vector(V &v, const SUBI &si) {
550  GMM_ASSERT2(si.last() <= vect_size(v),
551  "sub vector too large, " << si.last() << " > " << vect_size(v));
552  return typename select_return<
553  typename sub_vector_type<const V *, SUBI>::vector_type,
554  typename sub_vector_type<V *, SUBI>::vector_type, V *>::return_type
555  (linalg_cast(v), si);
556  }
557 
558 }
559 
560 #endif // GMM_SUB_VECTOR_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
sub-indices.
void clear(L &l)
clear (fill with zeros) a vector or matrix.
Definition: gmm_blas.h:59
gmm interface for STL vectors.