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