GetFEM  5.4.3
gmm_sub_vector.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2002-2020 Yves Renard
5 
6  This file is a part of GetFEM
7 
8  GetFEM is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Lesser General Public License as published
10  by the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version along with the GCC Runtime Library
12  Exception either version 3.1 or (at your option) any later version.
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  License and GCC Runtime Library Exception for more details.
17  You should have received a copy of the GNU Lesser General Public License
18  along with this program; if not, write to the Free Software Foundation,
19  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, you may use this file as it is a part of a free
22  software library without restriction. Specifically, if other files
23  instantiate templates or use macros or inline functions from this file,
24  or you compile this file and link it with other files to produce an
25  executable, this file does not by itself cause the resulting executable
26  to be covered by the GNU Lesser General Public License. This exception
27  does not however invalidate any other reasons why the executable file
28  might be covered by the GNU Lesser General Public License.
29 
30 ===========================================================================*/
31 
32 /**@file gmm_sub_vector.h
33  @author Yves Renard <[email protected]>
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() const { return si.rindex(itb.index()); }
66  void forward();
67  void backward();
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() {}
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
83  (const sparse_sub_vector_iterator<MIT, MIT, SUBI> &it)
84  : itb(it.itb), itbe(it.itbe), si(it.si) {}
85  sparse_sub_vector_iterator &operator =
86  (const sparse_sub_vector_iterator<MIT, MIT, SUBI> &it)
87  { itb = it.itb; itbe = it.itbe; si = it.si; return *this; }
88 
89  };
90 
91  template <typename IT, typename MIT, typename SUBI>
92  void sparse_sub_vector_iterator<IT, MIT, SUBI>::forward()
93  { while(itb!=itbe && index()==size_type(-1)) { ++itb; } }
94 
95  template <typename IT, typename MIT, typename SUBI>
96  void sparse_sub_vector_iterator<IT, MIT, SUBI>::backward()
97  { while(itb!=itbe && index()==size_type(-1)) --itb; }
98 
99  template <typename PT, typename SUBI> struct sparse_sub_vector {
100  typedef sparse_sub_vector<PT, SUBI> this_type;
101  typedef typename std::iterator_traits<PT>::value_type V;
102  typedef V * CPT;
103  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
104  typename linalg_traits<V>::iterator, PT>::ref_type iterator;
105  typedef typename linalg_traits<this_type>::reference reference;
106  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
107 
108  iterator begin_, end_;
109  porigin_type origin;
110  SUBI si;
111 
112  size_type size() const { return si.size(); }
113 
114  reference operator[](size_type i) const
115  { return linalg_traits<V>::access(origin, begin_, end_, si.index(i)); }
116 
117  sparse_sub_vector(V &v, const SUBI &s) : begin_(vect_begin(v)),
118  end_(vect_end(v)), origin(linalg_origin(v)), si(s) {}
119  sparse_sub_vector(const V &v, const SUBI &s)
120  : begin_(vect_begin(const_cast<V &>(v))),
121  end_(vect_end(const_cast<V &>(v))),
122  origin(linalg_origin(const_cast<V &>(v))), si(s) {}
123  sparse_sub_vector() {}
124  sparse_sub_vector(const sparse_sub_vector<CPT, SUBI> &cr)
125  : begin_(cr.begin_),end_(cr.end_),origin(cr.origin), si(cr.si) {}
126  };
127 
128  template <typename IT, typename MIT, typename SUBI, typename ORG,
129  typename PT> inline
130  void set_to_begin(sparse_sub_vector_iterator<IT, MIT, SUBI> &it,
131  ORG o, sparse_sub_vector<PT, SUBI> *,
132  linalg_modifiable) {
133  typedef sparse_sub_vector<PT, SUBI> VECT;
134  typedef typename linalg_traits<VECT>::V_reference ref_t;
135  set_to_begin(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
136  set_to_end(it.itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
137  it.forward();
138  }
139  template <typename IT, typename MIT, typename SUBI, typename ORG,
140  typename PT> inline
141  void set_to_begin(sparse_sub_vector_iterator<IT, MIT, SUBI> &it,
142  ORG o, const sparse_sub_vector<PT, SUBI> *,
143  linalg_modifiable) {
144  typedef sparse_sub_vector<PT, SUBI> VECT;
145  typedef typename linalg_traits<VECT>::V_reference ref_t;
146  set_to_begin(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
147  set_to_end(it.itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
148  it.forward();
149  }
150 
151  template <typename IT, typename MIT, typename SUBI, typename ORG,
152  typename PT> inline
153  void set_to_end(sparse_sub_vector_iterator<IT, MIT, SUBI> &it,
154  ORG o, sparse_sub_vector<PT, SUBI> *, linalg_modifiable) {
155  typedef sparse_sub_vector<PT, SUBI> VECT;
156  typedef typename linalg_traits<VECT>::V_reference ref_t;
157  set_to_end(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
158  set_to_end(it.itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
159  it.forward();
160  }
161  template <typename IT, typename MIT, typename SUBI, typename ORG,
162  typename PT> inline
163  void set_to_end(sparse_sub_vector_iterator<IT, MIT, SUBI> &it,
164  ORG o, const sparse_sub_vector<PT, SUBI> *,
165  linalg_modifiable) {
166  typedef sparse_sub_vector<PT, SUBI> VECT;
167  typedef typename linalg_traits<VECT>::V_reference ref_t;
168  set_to_end(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
169  set_to_end(it.itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
170  it.forward();
171  }
172 
173  template <typename PT, typename SUBI>
174  struct linalg_traits<sparse_sub_vector<PT, SUBI> > {
175  typedef sparse_sub_vector<PT, SUBI> this_type;
176  typedef this_type * pthis_type;
177  typedef PT pV;
178  typedef typename std::iterator_traits<PT>::value_type V;
179  typedef typename linalg_and<typename index_is_sorted<SUBI>::bool_type,
180  typename linalg_traits<V>::index_sorted>::bool_type index_sorted;
181  typedef typename linalg_traits<V>::is_reference V_reference;
182  typedef typename linalg_traits<V>::origin_type origin_type;
183  typedef typename select_ref<const origin_type *, origin_type *,
184  PT>::ref_type porigin_type;
185  typedef typename which_reference<PT>::is_reference is_reference;
186  typedef abstract_vector linalg_type;
187  typedef typename linalg_traits<V>::value_type value_type;
188  typedef typename select_ref<value_type, typename
189  linalg_traits<V>::reference, PT>::ref_type reference;
190  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
191  typename linalg_traits<V>::iterator, PT>::ref_type pre_iterator;
192  typedef typename select_ref<abstract_null_type,
193  sparse_sub_vector_iterator<pre_iterator,
194  pre_iterator, SUBI>,
195  PT>::ref_type iterator;
196  typedef sparse_sub_vector_iterator<typename linalg_traits<V>
197  ::const_iterator, pre_iterator, SUBI> const_iterator;
198  typedef abstract_sparse storage_type;
199  static size_type size(const this_type &v) { return v.size(); }
200  static iterator begin(this_type &v) {
201  iterator it;
202  it.itb = v.begin_;
203  it.itbe = v.end_;
204  it.si = v.si;
205  if (!is_const_reference(is_reference()))
206  set_to_begin(it, v.origin, pthis_type(), is_reference());
207  else
208  it.forward();
209  return it;
210  }
211  static const_iterator begin(const this_type &v) {
212  const_iterator it;
213  it.itb = v.begin_;
214  it.itbe = v.end_;
215  it.si = v.si;
216  if (!is_const_reference(is_reference()))
217  set_to_begin(it, v.origin, pthis_type(), is_reference());
218  else
219  it.forward();
220  return it;
221  }
222  static iterator end(this_type &v) {
223  iterator it;
224  it.itb = v.end_;
225  it.itbe = v.end_;
226  it.si = v.si;
227  if (!is_const_reference(is_reference()))
228  set_to_end(it, v.origin, pthis_type(), is_reference());
229  else
230  it.forward();
231  return it;
232  }
233  static const_iterator end(const this_type &v) {
234  const_iterator it;
235  it.itb = v.end_;
236  it.itbe = v.end_;
237  it.si = v.si;
238  if (!is_const_reference(is_reference()))
239  set_to_end(it, v.origin, pthis_type(), is_reference());
240  else
241  it.forward();
242  return it;
243  }
244  static origin_type* origin(this_type &v) { return v.origin; }
245  static const origin_type* origin(const this_type &v) { return v.origin; }
246  static void clear(origin_type* o, const iterator &begin_,
247  const iterator &end_) {
248  std::deque<size_type> ind;
249  iterator it = begin_;
250  for (; it != end_; ++it) ind.push_front(it.index());
251  for (; !(ind.empty()); ind.pop_back())
252  access(o, begin_, end_, ind.back()) = value_type(0);
253  }
254  static void do_clear(this_type &v) { clear(v.origin, begin(v), end(v)); }
255  static value_type access(const origin_type *o, const const_iterator &it,
256  const const_iterator &ite, size_type i)
257  { return linalg_traits<V>::access(o, it.itb, ite.itb, it.si.index(i)); }
258  static reference access(origin_type *o, const iterator &it,
259  const iterator &ite, size_type i)
260  { return linalg_traits<V>::access(o, it.itb, ite.itb, it.si.index(i)); }
261  };
262 
263  template <typename PT, typename SUBI> std::ostream &operator <<
264  (std::ostream &o, const sparse_sub_vector<PT, SUBI>& m)
265  { gmm::write(o,m); return o; }
266 
267  /* ********************************************************************* */
268  /* skyline sub-vectors */
269  /* ********************************************************************* */
270 
271  template <typename IT, typename MIT, typename SUBI>
272  struct skyline_sub_vector_iterator {
273 
274  IT itb;
275  SUBI si;
276 
277  typedef std::iterator_traits<IT> traits_type;
278  typedef typename traits_type::value_type value_type;
279  typedef typename traits_type::pointer pointer;
280  typedef typename traits_type::reference reference;
281  typedef typename traits_type::difference_type difference_type;
282  typedef std::bidirectional_iterator_tag iterator_category;
283  typedef size_t size_type;
284  typedef skyline_sub_vector_iterator<IT, MIT, SUBI> iterator;
285 
286  size_type index() const
287  { return (itb.index() - si.min + si.step() - 1) / si.step(); }
288  void backward();
289  iterator &operator ++()
290  { itb += si.step(); return *this; }
291  iterator operator ++(int) { iterator tmp = *this; ++(*this); return tmp; }
292  iterator &operator --()
293  { itb -= si.step(); return *this; }
294  iterator operator --(int) { iterator tmp = *this; --(*this); return tmp; }
295 
296  iterator &operator +=(difference_type i)
297  { itb += si.step() * i; return *this; }
298  iterator &operator -=(difference_type i)
299  { itb -= si.step() * i; return *this; }
300  iterator operator +(difference_type i) const
301  { iterator ii = *this; return (ii += i); }
302  iterator operator -(difference_type i) const
303  { iterator ii = *this; return (ii -= i); }
304  difference_type operator -(const iterator &i) const
305  { return (itb - i.itb) / si.step(); }
306 
307  reference operator *() const { return *itb; }
308  reference operator [](int ii) { return *(itb + ii * si.step()); }
309 
310  bool operator ==(const iterator &i) const { return index() == i.index();}
311  bool operator !=(const iterator &i) const { return !(i == *this); }
312  bool operator < (const iterator &i) const { return index() < i.index();}
313  bool operator > (const iterator &i) const { return index() > i.index();}
314  bool operator >=(const iterator &i) const { return index() >= i.index();}
315 
316  skyline_sub_vector_iterator() {}
317  skyline_sub_vector_iterator(const IT &it, const SUBI &s)
318  : itb(it), si(s) {}
319  skyline_sub_vector_iterator
320  (const skyline_sub_vector_iterator<MIT, MIT, SUBI> &it)
321  : itb(it.itb), si(it.si) {}
322  skyline_sub_vector_iterator &
323  operator =(const skyline_sub_vector_iterator<MIT, MIT, SUBI> &it)
324  { itb=it.itb; si=it.si; return *this; }
325  };
326 
327  template <typename IT, typename SUBI>
328  void update_for_sub_skyline(IT &it, IT &ite, const SUBI &si) {
329  if (it.index() >= si.max || ite.index() <= si.min) { it = ite; return; }
330  ptrdiff_t dec1 = si.min - it.index(), dec2 = ite.index() - si.max;
331  it += (dec1 < 0) ? ((si.step()-((-dec1) % si.step())) % si.step()) : dec1;
332  ite -= (dec2 < 0) ? -((-dec2) % si.step()) : dec2;
333  }
334 
335  template <typename PT, typename SUBI> struct skyline_sub_vector {
336  typedef skyline_sub_vector<PT, SUBI> this_type;
337  typedef typename std::iterator_traits<PT>::value_type V;
338  typedef V * pV;
339  typedef typename select_ref<typename linalg_traits<V>::const_iterator,
340  typename linalg_traits<V>::iterator, PT>::ref_type iterator;
341  typedef typename linalg_traits<this_type>::reference reference;
342  typedef typename linalg_traits<this_type>::porigin_type porigin_type;
343 
344  iterator begin_, end_;
345  porigin_type origin;
346  SUBI si;
347 
348  size_type size() const { return si.size(); }
349 
350  reference operator[](size_type i) const
351  { return linalg_traits<V>::access(origin, begin_, end_, si.index(i)); }
352 
353  skyline_sub_vector(V &v, const SUBI &s) : begin_(vect_begin(v)),
354  end_(vect_end(v)), origin(linalg_origin(v)), si(s) {
355  update_for_sub_skyline(begin_, end_, si);
356  }
357  skyline_sub_vector(const V &v, const SUBI &s)
358  : begin_(vect_begin(const_cast<V &>(v))),
359  end_(vect_end(const_cast<V &>(v))),
360  origin(linalg_origin(const_cast<V &>(v))), si(s) {
361  update_for_sub_skyline(begin_, end_, si);
362  }
363  skyline_sub_vector() {}
364  skyline_sub_vector(const skyline_sub_vector<pV, SUBI> &cr)
365  : begin_(cr.begin_),end_(cr.end_),origin(cr.origin), si(cr.si) {}
366  };
367 
368  template <typename IT, typename MIT, typename SUBI, typename ORG,
369  typename PT> inline
370  void set_to_begin(skyline_sub_vector_iterator<IT, MIT, SUBI> &it,
371  ORG o, skyline_sub_vector<PT, SUBI> *,
372  linalg_modifiable) {
373  typedef skyline_sub_vector<PT, SUBI> VECT;
374  typedef typename linalg_traits<VECT>::V_reference ref_t;
375  IT itbe = it.itb;
376  set_to_begin(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
377  set_to_end(itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
378  update_for_sub_skyline(it.itb, itbe, it.si);
379  }
380  template <typename IT, typename MIT, typename SUBI, typename ORG,
381  typename PT> inline
382  void set_to_begin(skyline_sub_vector_iterator<IT, MIT, SUBI> &it,
383  ORG o, const skyline_sub_vector<PT, SUBI> *,
384  linalg_modifiable) {
385  typedef skyline_sub_vector<PT, SUBI> VECT;
386  typedef typename linalg_traits<VECT>::V_reference ref_t;
387  IT itbe = it.itb;
388  set_to_begin(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
389  set_to_end(itbe, o, typename linalg_traits<VECT>::pV(), ref_t());
390  update_for_sub_skyline(it.itb, itbe, it.si);
391  }
392 
393  template <typename IT, typename MIT, typename SUBI, typename ORG,
394  typename PT> inline
395  void set_to_end(skyline_sub_vector_iterator<IT, MIT, SUBI> &it,
396  ORG o, skyline_sub_vector<PT, SUBI> *,
397  linalg_modifiable) {
398  typedef skyline_sub_vector<PT, SUBI> VECT;
399  typedef typename linalg_traits<VECT>::V_reference ref_t;
400  IT itb = it.itb;
401  set_to_begin(itb, o, typename linalg_traits<VECT>::pV(), ref_t());
402  set_to_end(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
403  update_for_sub_skyline(itb, it.itb, it.si);
404  }
405  template <typename IT, typename MIT, typename SUBI, typename ORG,
406  typename PT> inline
407  void set_to_end(skyline_sub_vector_iterator<IT, MIT, SUBI> &it,
408  ORG o, const skyline_sub_vector<PT, SUBI> *,
409  linalg_modifiable) {
410  typedef skyline_sub_vector<PT, SUBI> VECT;
411  typedef typename linalg_traits<VECT>::V_reference ref_t;
412  IT itb = it.itb;
413  set_to_begin(itb, o, typename linalg_traits<VECT>::pV(), ref_t());
414  set_to_end(it.itb, o, typename linalg_traits<VECT>::pV(), ref_t());
415  update_for_sub_skyline(itb, it.itb, it.si);
416  }
417 
418 
419  template <typename PT, typename SUBI>
420  struct linalg_traits<skyline_sub_vector<PT, SUBI> > {
421  typedef skyline_sub_vector<PT, SUBI> this_type;
422  typedef this_type *pthis_type;
423  typedef typename std::iterator_traits<PT>::value_type V;
424  typedef typename linalg_traits<V>::is_reference V_reference;
425  typedef typename linalg_traits<V>::origin_type origin_type;
426  typedef typename select_ref<const origin_type *,
427  origin_type *, PT>::ref_type porigin_type;
428  typedef V * pV;
429  typedef typename which_reference<PT>::is_reference is_reference;
430  typedef abstract_vector linalg_type;
431  typedef typename linalg_traits<V>::value_type value_type;
432  typedef typename select_ref<value_type, typename
433  linalg_traits<V>::reference, PT>::ref_type reference;
434  typedef typename linalg_traits<V>::const_iterator const_V_iterator;
435  typedef typename linalg_traits<V>::iterator V_iterator;
436  typedef typename select_ref<const_V_iterator,
437  V_iterator, PT>::ref_type pre_iterator;
438  typedef typename select_ref<abstract_null_type,
439  skyline_sub_vector_iterator<pre_iterator,
440  pre_iterator, SUBI>,
441  PT>::ref_type iterator;
442  typedef skyline_sub_vector_iterator<const_V_iterator, pre_iterator, SUBI>
443  const_iterator;
444  typedef abstract_skyline storage_type;
445  typedef linalg_true index_sorted;
446  static size_type size(const this_type &v) { return v.size(); }
447  static iterator begin(this_type &v) {
448  iterator it;
449  it.itb = v.begin_;
450  it.si = v.si;
451  if (!is_const_reference(is_reference()))
452  set_to_begin(it, v.origin, pthis_type(), is_reference());
453  return it;
454  }
455  static const_iterator begin(const this_type &v) {
456  const_iterator it;
457  it.itb = v.begin_;
458  it.si = v.si;
459  if (!is_const_reference(is_reference()))
460  set_to_begin(it, v.origin, pthis_type(), is_reference());
461  return it;
462  }
463  static iterator end(this_type &v) {
464  iterator it;
465  it.itb = v.end_;
466  it.si = v.si;
467  if (!is_const_reference(is_reference()))
468  set_to_end(it, v.origin, pthis_type(), is_reference());
469  return it;
470  }
471  static const_iterator end(const this_type &v) {
472  const_iterator it;
473  it.itb = v.end_;
474  it.si = v.si;
475  if (!is_const_reference(is_reference()))
476  set_to_end(it, v.origin, pthis_type(), is_reference());
477  return it;
478  }
479  static origin_type* origin(this_type &v) { return v.origin; }
480  static const origin_type* origin(const this_type &v) { return v.origin; }
481  static void clear(origin_type*, const iterator &it, const iterator &ite)
482  { std::fill(it, ite, value_type(0)); }
483  static void do_clear(this_type &v) { clear(v.origin, begin(v), end(v)); }
484  static value_type access(const origin_type *o, const const_iterator &it,
485  const const_iterator &ite, size_type i)
486  { return linalg_traits<V>::access(o, it.itb, ite.itb, it.si.index(i)); }
487  static reference access(origin_type *o, const iterator &it,
488  const iterator &ite, size_type i)
489  { return linalg_traits<V>::access(o, it.itb, ite.itb, it.si.index(i)); }
490  };
491 
492  template <typename PT, typename SUBI> std::ostream &operator <<
493  (std::ostream &o, const skyline_sub_vector<PT, SUBI>& m)
494  { gmm::write(o,m); return o; }
495 
496  /* ******************************************************************** */
497  /* sub vector. */
498  /* ******************************************************************** */
499  /* sub_vector_type<PT, SUBI>::vector_type is the sub vector type */
500  /* returned by sub_vector(v, sub_index) */
501  /************************************************************************/
502 
503  template <typename PT, typename SUBI, typename st_type> struct svrt_ir {
504  typedef abstract_null_type vector_type;
505  };
506 
507  template <typename PT>
508  struct svrt_ir<PT, sub_index, abstract_dense> {
509  typedef typename std::iterator_traits<PT>::value_type V;
510  typedef typename vect_ref_type<PT, V>::iterator iterator;
511  typedef tab_ref_index_ref_with_origin<iterator,
512  sub_index::const_iterator, V> vector_type;
513  };
514 
515  template <typename PT>
516  struct svrt_ir<PT, unsorted_sub_index, abstract_dense> {
517  typedef typename std::iterator_traits<PT>::value_type V;
518  typedef typename vect_ref_type<PT, V>::iterator iterator;
519  typedef tab_ref_index_ref_with_origin<iterator,
520  unsorted_sub_index::const_iterator, V> vector_type;
521  };
522 
523  template <typename PT>
524  struct svrt_ir<PT, sub_interval, abstract_dense> {
525  typedef typename std::iterator_traits<PT>::value_type V;
526  typedef typename vect_ref_type<PT, V>::iterator iterator;
527  typedef tab_ref_with_origin<iterator, V> vector_type;
528  };
529 
530  template <typename PT>
531  struct svrt_ir<PT, sub_slice, abstract_dense> {
532  typedef typename std::iterator_traits<PT>::value_type V;
533  typedef typename vect_ref_type<PT, V>::iterator iterator;
534  typedef tab_ref_reg_spaced_with_origin<iterator, V> vector_type;
535  };
536 
537  template <typename PT, typename SUBI>
538  struct svrt_ir<PT, SUBI, abstract_skyline> {
539  typedef skyline_sub_vector<PT, SUBI> vector_type;
540  };
541 
542  template <typename PT>
543  struct svrt_ir<PT, sub_index, abstract_skyline> {
544  typedef sparse_sub_vector<PT, sub_index> vector_type;
545  };
546 
547  template <typename PT>
548  struct svrt_ir<PT, unsorted_sub_index, abstract_skyline> {
549  typedef sparse_sub_vector<PT, unsorted_sub_index> vector_type;
550  };
551 
552 
553  template <typename PT, typename SUBI>
554  struct svrt_ir<PT, SUBI, abstract_sparse> {
555  typedef sparse_sub_vector<PT, SUBI> vector_type;
556  };
557 
558  template <typename PT, typename SUBI>
559  struct sub_vector_type {
560  typedef typename std::iterator_traits<PT>::value_type V;
561  typedef typename svrt_ir<PT, SUBI,
562  typename linalg_traits<V>::storage_type>::vector_type vector_type;
563  };
564 
565  template <typename V, typename SUBI>
566  typename select_return<
567  typename sub_vector_type<const V *, SUBI>::vector_type,
568  typename sub_vector_type<V *, SUBI>::vector_type, const V *>::return_type
569  sub_vector(const V &v, const SUBI &si) {
570  GMM_ASSERT2(si.last() <= vect_size(v),
571  "sub vector too large, " << si.last() << " > " << vect_size(v));
572  return typename select_return<
573  typename sub_vector_type<const V *, SUBI>::vector_type,
574  typename sub_vector_type<V *, SUBI>::vector_type, const V *>::return_type
575  (linalg_cast(v), si);
576  }
577 
578  template <typename V, typename SUBI>
579  typename select_return<
580  typename sub_vector_type<const V *, SUBI>::vector_type,
581  typename sub_vector_type<V *, SUBI>::vector_type, V *>::return_type
582  sub_vector(V &v, const SUBI &si) {
583  GMM_ASSERT2(si.last() <= vect_size(v),
584  "sub vector too large, " << si.last() << " > " << vect_size(v));
585  return typename select_return<
586  typename sub_vector_type<const V *, SUBI>::vector_type,
587  typename sub_vector_type<V *, SUBI>::vector_type, V *>::return_type
588  (linalg_cast(v), si);
589  }
590 
591 }
592 
593 #endif // GMM_SUB_VECTOR_H__
void clear(L &l)
clear (fill with zeros) a vector or matrix.
Definition: gmm_blas.h:59
gmm interface for STL vectors.
sub-indices.
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