36 #ifndef GMM_VECTOR_TO_MATRIX_H__ 
   37 #define GMM_VECTOR_TO_MATRIX_H__ 
   47   template <
typename PT> 
struct gen_row_vector {
 
   48     typedef gen_row_vector<PT> this_type;
 
   49     typedef typename std::iterator_traits<PT>::value_type V;
 
   51     typedef typename std::iterator_traits<PT>::reference ref_V;
 
   52     typedef typename linalg_traits<this_type>::reference reference;
 
   54     simple_vector_ref<PT> vec;
 
   59     size_type ncols(
void)
 const { 
return vect_size(vec); }
 
   61     gen_row_vector(ref_V v) : vec(v) {}
 
   63     gen_row_vector(
const gen_row_vector<CPT> &cr) : vec(cr.vec) {}
 
   66   template <
typename PT>
 
   67   struct gen_row_vector_iterator {
 
   68     typedef gen_row_vector<PT> this_type;
 
   69     typedef typename modifiable_pointer<PT>::pointer MPT;
 
   70     typedef typename std::iterator_traits<PT>::value_type V;
 
   71     typedef simple_vector_ref<PT> value_type;
 
   72     typedef const simple_vector_ref<PT> *pointer;
 
   73     typedef const simple_vector_ref<PT> &reference;
 
   74     typedef ptrdiff_t difference_type;
 
   76     typedef std::random_access_iterator_tag  iterator_category;
 
   77     typedef gen_row_vector_iterator<PT> iterator;
 
   79     simple_vector_ref<PT> vec;
 
   82     iterator &operator ++()   { isend = 
true; 
return *
this; }
 
   83     iterator &operator --()   { isend = 
false; 
return *
this; }
 
   84     iterator operator ++(
int) { iterator tmp = *
this; ++(*this); 
return tmp; }
 
   85     iterator operator --(
int) { iterator tmp = *
this; --(*this); 
return tmp; }
 
   86     iterator &operator +=(difference_type i)
 
   87     { 
if (i) isend = 
false; 
return *
this; }
 
   88     iterator &operator -=(difference_type i)
 
   89     { 
if (i) isend = 
true; 
return *
this;  }
 
   91     { iterator itt = *
this; 
return (itt += i); }
 
   93     { iterator itt = *
this; 
return (itt -= i); }
 
   94     difference_type 
operator -(
const iterator &i)
 const { 
 
   95       return (isend == 
true) ? ((i.isend == 
true) ? 0 : 1)
 
   96                              : ((i.isend == 
true) ? -1 : 0);
 
   99     const simple_vector_ref<PT>& operator *()
 const { 
return vec; }
 
  100     const simple_vector_ref<PT>& operator [](
int i) { 
return vec; }
 
  102     bool operator ==(
const iterator &i)
 const { 
return (isend == i.isend); }
 
  103     bool operator !=(
const iterator &i)
 const { 
return !(i == *
this); }
 
  104     bool operator < (
const iterator &i)
 const { 
return (*
this - i <  0); }
 
  105     bool operator > (
const iterator &i)
 const { 
return (*
this - i >  0); }
 
  106     bool operator >=(
const iterator &i)
 const { 
return (*
this - i >= 0); }
 
  108     gen_row_vector_iterator(
void) {}
 
  109     gen_row_vector_iterator(
const gen_row_vector_iterator<MPT> &itm)
 
  110       : vec(itm.vec), isend(itm.isend) {}
 
  111     gen_row_vector_iterator(
const gen_row_vector<PT> &m, 
bool iis_end)
 
  112       : vec(m.vec), isend(iis_end) { }
 
  116   template <
typename PT>
 
  117   struct linalg_traits<gen_row_vector<PT> > {
 
  118     typedef gen_row_vector<PT> this_type;
 
  119     typedef typename std::iterator_traits<PT>::value_type V;
 
  120     typedef typename which_reference<PT>::is_reference is_reference;
 
  121     typedef abstract_matrix linalg_type;
 
  122     typedef typename linalg_traits<V>::origin_type origin_type;
 
  123     typedef typename select_ref<
const origin_type *, origin_type *,
 
  124                                 PT>::ref_type porigin_type;
 
  125     typedef typename linalg_traits<V>::value_type value_type;
 
  126     typedef typename select_ref<value_type,
 
  127             typename linalg_traits<V>::reference, PT>::ref_type reference;
 
  128     typedef abstract_null_type sub_col_type;
 
  129     typedef abstract_null_type col_iterator;
 
  130     typedef abstract_null_type const_sub_col_type;
 
  131     typedef abstract_null_type const_col_iterator;
 
  132     typedef simple_vector_ref<const V *> const_sub_row_type;
 
  133     typedef typename select_ref<abstract_null_type, 
 
  134             simple_vector_ref<V *>, PT>::ref_type sub_row_type;
 
  135     typedef gen_row_vector_iterator<typename const_pointer<PT>::pointer>
 
  137     typedef typename select_ref<abstract_null_type, 
 
  138             gen_row_vector_iterator<PT>, PT>::ref_type row_iterator;
 
  139     typedef typename linalg_traits<V>::storage_type storage_type;
 
  140     typedef row_major sub_orientation;
 
  141     typedef typename linalg_traits<V>::index_sorted index_sorted;
 
  142     static size_type nrows(
const this_type &) { 
return 1; }
 
  143     static size_type ncols(
const this_type &m) { 
return m.ncols(); }
 
  144     static const_sub_row_type row(
const const_row_iterator &it) { 
return *it; }
 
  145     static sub_row_type row(
const row_iterator &it) { 
return *it; }
 
  146     static const_row_iterator row_begin(
const this_type &m)
 
  147     { 
return const_row_iterator(m, 
false); }
 
  148     static row_iterator row_begin(this_type &m)
 
  149     { 
return row_iterator(m, 
false); }
 
  150     static const_row_iterator row_end(
const this_type &m)
 
  151     { 
return const_row_iterator(m, 
true); }
 
  152     static row_iterator row_end(this_type &m)
 
  153     { 
return row_iterator(m, 
true); }
 
  154     static origin_type* origin(this_type &m) { 
return m.vec.origin; }
 
  155     static const origin_type* origin(
const this_type &m)
 
  156     { 
return m.vec.origin; }
 
  157     static void do_clear(this_type &m)
 
  158     { 
clear(row(mat_row_begin(m))); }
 
  159     static value_type access(
const const_row_iterator &itrow, 
size_type i)
 
  160     { 
return itrow.vec[i]; }
 
  161     static reference access(
const row_iterator &itrow, 
size_type i)
 
  162     { 
return itrow.vec[i]; }
 
  165   template <
typename PT>
 
  166   std::ostream &operator <<(std::ostream &o, 
const gen_row_vector<PT>& m)
 
  167   { gmm::write(o,m); 
return o; }
 
  173   template <
typename PT> 
struct gen_col_vector {
 
  174     typedef gen_col_vector<PT> this_type;
 
  175     typedef typename std::iterator_traits<PT>::value_type V;
 
  177     typedef typename std::iterator_traits<PT>::reference ref_V;
 
  178     typedef typename linalg_traits<this_type>::reference reference;
 
  180     simple_vector_ref<PT> vec;
 
  184     size_type ncols(
void)
 const { 
return 1; }
 
  185     size_type nrows(
void)
 const { 
return vect_size(vec); }
 
  187     gen_col_vector(ref_V v) : vec(v) {}
 
  189     gen_col_vector(
const gen_col_vector<CPT> &cr) : vec(cr.vec) {}
 
  192   template <
typename PT>
 
  193   struct gen_col_vector_iterator {
 
  194     typedef gen_col_vector<PT> this_type;
 
  195     typedef typename modifiable_pointer<PT>::pointer MPT;
 
  196     typedef typename std::iterator_traits<PT>::value_type V;
 
  197     typedef simple_vector_ref<PT> value_type;
 
  198     typedef const simple_vector_ref<PT> *pointer;
 
  199     typedef const simple_vector_ref<PT> &reference;
 
  200     typedef ptrdiff_t difference_type;
 
  202     typedef std::random_access_iterator_tag  iterator_category;
 
  203     typedef gen_col_vector_iterator<PT> iterator;
 
  205     simple_vector_ref<PT> vec;
 
  208     iterator &operator ++()   { isend = 
true; 
return *
this; }
 
  209     iterator &operator --()   { isend = 
false; 
return *
this; }
 
  210     iterator operator ++(
int) { iterator tmp = *
this; ++(*this); 
return tmp; }
 
  211     iterator operator --(
int) { iterator tmp = *
this; --(*this); 
return tmp; }
 
  212     iterator &operator +=(difference_type i)
 
  213     { 
if (i) isend = 
false; 
return *
this; }
 
  214     iterator &operator -=(difference_type i)
 
  215     { 
if (i) isend = 
true; 
return *
this;  }
 
  217     { iterator itt = *
this; 
return (itt += i); }
 
  219     { iterator itt = *
this; 
return (itt -= i); }
 
  220     difference_type 
operator -(
const iterator &i)
 const { 
 
  221       return (isend == 
true) ? ((i.isend == 
true) ? 0 : 1)
 
  222                              : ((i.isend == 
true) ? -1 : 0);
 
  225     const simple_vector_ref<PT>& operator *()
 const { 
return vec; }
 
  226     const simple_vector_ref<PT>& operator [](
int i) { 
return vec; }
 
  228     bool operator ==(
const iterator &i)
 const { 
return (isend == i.isend); }
 
  229     bool operator !=(
const iterator &i)
 const { 
return !(i == *
this); }
 
  230     bool operator < (
const iterator &i)
 const { 
return (*
this - i <  0); }
 
  231     bool operator > (
const iterator &i)
 const { 
return (*
this - i >  0); }
 
  232     bool operator >=(
const iterator &i)
 const { 
return (*
this - i >= 0); }
 
  234     gen_col_vector_iterator(
void) {}
 
  235     gen_col_vector_iterator(
const gen_col_vector_iterator<MPT> &itm)
 
  236       : vec(itm.vec), isend(itm.isend) {}
 
  237     gen_col_vector_iterator(
const gen_col_vector<PT> &m, 
bool iis_end)
 
  238       : vec(m.vec), isend(iis_end) { }
 
  242   template <
typename PT>
 
  243   struct linalg_traits<gen_col_vector<PT> > {
 
  244     typedef gen_col_vector<PT> this_type;
 
  245     typedef typename std::iterator_traits<PT>::value_type V;
 
  246     typedef typename which_reference<PT>::is_reference is_reference;
 
  247     typedef abstract_matrix linalg_type;
 
  248     typedef typename linalg_traits<V>::origin_type origin_type;
 
  249     typedef typename select_ref<
const origin_type *, origin_type *,
 
  250                                 PT>::ref_type porigin_type;
 
  251     typedef typename linalg_traits<V>::value_type value_type;
 
  252     typedef typename select_ref<value_type,
 
  253             typename linalg_traits<V>::reference, PT>::ref_type reference;
 
  254     typedef abstract_null_type sub_row_type;
 
  255     typedef abstract_null_type row_iterator;
 
  256     typedef abstract_null_type const_sub_row_type;
 
  257     typedef abstract_null_type const_row_iterator;
 
  258     typedef simple_vector_ref<const V *> const_sub_col_type;
 
  259     typedef typename select_ref<abstract_null_type, 
 
  260             simple_vector_ref<V *>, PT>::ref_type sub_col_type;
 
  261     typedef gen_col_vector_iterator<typename const_pointer<PT>::pointer>
 
  263     typedef typename select_ref<abstract_null_type, 
 
  264             gen_col_vector_iterator<PT>, PT>::ref_type col_iterator;
 
  265     typedef typename linalg_traits<V>::storage_type storage_type;
 
  266     typedef col_major sub_orientation;
 
  267     typedef typename linalg_traits<V>::index_sorted index_sorted;
 
  268     static size_type ncols(
const this_type &) { 
return 1; }
 
  269     static size_type nrows(
const this_type &m) { 
return m.nrows(); }
 
  270     static const_sub_col_type col(
const const_col_iterator &it) { 
return *it; }
 
  271     static sub_col_type col(
const col_iterator &it) { 
return *it; }
 
  272     static const_col_iterator col_begin(
const this_type &m)
 
  273     { 
return const_col_iterator(m, 
false); }
 
  274     static col_iterator col_begin(this_type &m)
 
  275     { 
return col_iterator(m, 
false); }
 
  276     static const_col_iterator col_end(
const this_type &m)
 
  277     { 
return const_col_iterator(m, 
true); }
 
  278     static col_iterator col_end(this_type &m)
 
  279     { 
return col_iterator(m, 
true); }
 
  280     static origin_type* origin(this_type &m) { 
return m.vec.origin; }
 
  281     static const origin_type* origin(
const this_type &m)
 
  282     { 
return m.vec.origin; }
 
  283     static void do_clear(this_type &m)
 
  284     { 
clear(col(mat_col_begin(m))); }
 
  285     static value_type access(
const const_col_iterator &itcol, 
size_type i)
 
  286     { 
return itcol.vec[i]; }
 
  287     static reference access(
const col_iterator &itcol, 
size_type i)
 
  288     { 
return itcol.vec[i]; }
 
  291   template <
typename PT>
 
  292   std::ostream &operator <<(std::ostream &o, 
const gen_col_vector<PT>& m)
 
  293   { gmm::write(o,m); 
return o; }
 
  300   template <
class V> 
inline 
  301   typename select_return< gen_row_vector<const V *>, gen_row_vector<V *>,
 
  302                           const V *>::return_type
 
  303   row_vector(
const V& v) {
 
  304     return typename select_return< gen_row_vector<const V *>,
 
  305       gen_row_vector<V *>, 
const V *>::return_type(linalg_cast(v));
 
  308   template <
class V> 
inline 
  309   typename select_return< gen_row_vector<const V *>, gen_row_vector<V *>,
 
  312     return typename select_return< gen_row_vector<const V *>,
 
  313       gen_row_vector<V *>, V *>::return_type(linalg_cast(v));
 
  316   template <
class V> 
inline gen_row_vector<const V *>
 
  317   const_row_vector(V& v)
 
  318   { 
return gen_row_vector<const V *>(v); }
 
  321   template <
class V> 
inline 
  322   typename select_return< gen_col_vector<const V *>, gen_col_vector<V *>,
 
  323                           const V *>::return_type
 
  324   col_vector(
const V& v) {
 
  325     return typename select_return< gen_col_vector<const V *>,
 
  326       gen_col_vector<V *>, 
const V *>::return_type(linalg_cast(v));
 
  329   template <
class V> 
inline 
  330   typename select_return< gen_col_vector<const V *>, gen_col_vector<V *>,
 
  333     return typename select_return< gen_col_vector<const V *>,
 
  334       gen_col_vector<V *>, V *>::return_type(linalg_cast(v));
 
  337   template <
class V> 
inline gen_col_vector<const V *>
 
  338   const_col_vector(V& v)
 
  339   { 
return gen_col_vector<const V *>(v); }
 
void clear(L &l)
clear (fill with zeros) a vector or matrix.
 
gmm interface for STL vectors.
 
rational_fraction< T > operator-(const polynomial< T > &P, const rational_fraction< T > &Q)
Subtract Q from P.
 
rational_fraction< T > operator+(const polynomial< T > &P, const rational_fraction< T > &Q)
Add Q to P.
 
size_t size_type
used as the common size type in the library