37 #ifndef GMM_TRANSPOSED_H__ 
   38 #define GMM_TRANSPOSED_H__ 
   48   template <
typename PT> 
struct  transposed_row_ref {
 
   50     typedef transposed_row_ref<PT> this_type;
 
   51     typedef typename std::iterator_traits<PT>::value_type M;
 
   53     typedef typename std::iterator_traits<PT>::reference ref_M;
 
   54     typedef typename select_ref<typename linalg_traits<this_type>
 
   55             ::const_col_iterator, 
typename linalg_traits<this_type>
 
   56             ::col_iterator, PT>::ref_type iterator;
 
   57     typedef typename linalg_traits<this_type>::reference reference;
 
   58     typedef typename linalg_traits<this_type>::porigin_type porigin_type;
 
   60     iterator begin_, end_;
 
   64     transposed_row_ref(ref_M m)
 
   65       : begin_(mat_row_begin(m)), end_(mat_row_end(m)),
 
   66         origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
 
   68     transposed_row_ref(
const transposed_row_ref<CPT> &cr) :
 
   69       begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
 
   72     { 
return linalg_traits<M>::access(begin_+j, i); }
 
   75   template <
typename PT> 
struct linalg_traits<transposed_row_ref<PT> > {
 
   76     typedef transposed_row_ref<PT> this_type;
 
   77     typedef typename std::iterator_traits<PT>::value_type M;
 
   78     typedef typename linalg_traits<M>::origin_type origin_type;
 
   79     typedef typename select_ref<
const origin_type *, origin_type *,
 
   80                                 PT>::ref_type porigin_type;
 
   81     typedef typename which_reference<PT>::is_reference is_reference;
 
   82     typedef abstract_matrix linalg_type;
 
   83     typedef typename linalg_traits<M>::value_type value_type;
 
   84     typedef typename select_ref<value_type,
 
   85             typename linalg_traits<M>::reference, PT>::ref_type reference;
 
   86     typedef typename linalg_traits<M>::storage_type storage_type;
 
   87     typedef abstract_null_type sub_row_type;
 
   88     typedef abstract_null_type const_sub_row_type;
 
   89     typedef abstract_null_type row_iterator;
 
   90     typedef abstract_null_type const_row_iterator;
 
   91     typedef typename linalg_traits<M>::const_sub_row_type const_sub_col_type;
 
   92     typedef typename select_ref<abstract_null_type, 
typename 
   93             linalg_traits<M>::sub_row_type, PT>::ref_type sub_col_type;
 
   94     typedef typename linalg_traits<M>::const_row_iterator const_col_iterator;
 
   95     typedef typename select_ref<abstract_null_type, 
typename 
   96             linalg_traits<M>::row_iterator, PT>::ref_type col_iterator;
 
   97     typedef col_major sub_orientation;
 
   98     typedef typename linalg_traits<M>::index_sorted index_sorted;
 
   99     static size_type ncols(
const this_type &v) { 
return v.nc; }
 
  100     static size_type nrows(
const this_type &v) { 
return v.nr; }
 
  101     static const_sub_col_type col(
const const_col_iterator &it)
 
  102     { 
return linalg_traits<M>::row(it); }
 
  103     static sub_col_type col(
const col_iterator &it)
 
  104     { 
return linalg_traits<M>::row(it); }
 
  105     static col_iterator col_begin(this_type &m) { 
return m.begin_; }
 
  106     static col_iterator col_end(this_type &m) { 
return m.end_; }
 
  107     static const_col_iterator col_begin(
const this_type &m)
 
  109     static const_col_iterator col_end(
const this_type &m) { 
return m.end_; }
 
  110     static origin_type* origin(this_type &v) { 
return v.origin; }
 
  111     static const origin_type* origin(
const this_type &v) { 
return v.origin; }
 
  112     static void do_clear(this_type &v);
 
  113     static value_type access(
const const_col_iterator &itcol, 
size_type i)
 
  114     { 
return linalg_traits<M>::access(itcol, i); }
 
  115     static reference access(
const col_iterator &itcol, 
size_type i)
 
  116     { 
return linalg_traits<M>::access(itcol, i); }
 
  119   template <
typename PT> 
 
  120   void linalg_traits<transposed_row_ref<PT> >::do_clear(this_type &v) { 
 
  121     col_iterator it = mat_col_begin(v), ite = mat_col_end(v);
 
  122     for (; it != ite; ++it) 
clear(col(it));
 
  125   template<
typename PT> std::ostream &
operator <<
 
  126   (std::ostream &o, 
const transposed_row_ref<PT>& m)
 
  127   { gmm::write(o,m); 
return o; }
 
  129   template <
typename PT> 
struct  transposed_col_ref {
 
  131     typedef transposed_col_ref<PT> this_type;
 
  132     typedef typename std::iterator_traits<PT>::value_type M;
 
  134     typedef typename std::iterator_traits<PT>::reference ref_M;
 
  135     typedef typename select_ref<typename linalg_traits<this_type>
 
  136             ::const_row_iterator, 
typename linalg_traits<this_type>
 
  137             ::row_iterator, PT>::ref_type iterator;
 
  138     typedef typename linalg_traits<this_type>::reference reference;
 
  139     typedef typename linalg_traits<this_type>::porigin_type porigin_type;
 
  141     iterator begin_, end_;
 
  145     transposed_col_ref(ref_M m)
 
  146       : begin_(mat_col_begin(m)), end_(mat_col_end(m)),
 
  147         origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
 
  149     transposed_col_ref(
const transposed_col_ref<CPT> &cr) :
 
  150       begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
 
  153     { 
return linalg_traits<M>::access(begin_+i, j); }
 
  156   template <
typename PT> 
struct linalg_traits<transposed_col_ref<PT> > {
 
  157     typedef transposed_col_ref<PT> this_type;
 
  158     typedef typename std::iterator_traits<PT>::value_type M;
 
  159     typedef typename linalg_traits<M>::origin_type origin_type;
 
  160     typedef typename select_ref<
const origin_type *, origin_type *,
 
  161                                 PT>::ref_type porigin_type;
 
  162     typedef typename which_reference<PT>::is_reference is_reference;
 
  163     typedef abstract_matrix linalg_type;
 
  164     typedef typename linalg_traits<M>::value_type value_type;
 
  165     typedef typename select_ref<value_type,
 
  166             typename linalg_traits<M>::reference, PT>::ref_type reference;
 
  167     typedef typename linalg_traits<M>::storage_type storage_type;
 
  168     typedef abstract_null_type sub_col_type;
 
  169     typedef abstract_null_type const_sub_col_type;
 
  170     typedef abstract_null_type col_iterator;
 
  171     typedef abstract_null_type const_col_iterator;
 
  172     typedef typename linalg_traits<M>::const_sub_col_type const_sub_row_type;
 
  173     typedef typename select_ref<abstract_null_type, 
typename 
  174             linalg_traits<M>::sub_col_type, PT>::ref_type sub_row_type;
 
  175     typedef typename linalg_traits<M>::const_col_iterator const_row_iterator;
 
  176     typedef typename select_ref<abstract_null_type, 
typename 
  177             linalg_traits<M>::col_iterator, PT>::ref_type row_iterator;
 
  178     typedef row_major sub_orientation;
 
  179     typedef typename linalg_traits<M>::index_sorted index_sorted;
 
  180     static size_type nrows(
const this_type &v)
 
  182     static size_type ncols(
const this_type &v)
 
  184     static const_sub_row_type row(
const const_row_iterator &it)
 
  185     { 
return linalg_traits<M>::col(it); }
 
  186     static sub_row_type row(
const row_iterator &it)
 
  187     { 
return linalg_traits<M>::col(it); }
 
  188     static row_iterator row_begin(this_type &m) { 
return m.begin_; }
 
  189     static row_iterator row_end(this_type &m) { 
return m.end_; }
 
  190     static const_row_iterator row_begin(
const this_type &m)
 
  192     static const_row_iterator row_end(
const this_type &m) { 
return m.end_; }
 
  193     static origin_type* origin(this_type &v) { 
return v.origin; }
 
  194     static const origin_type* origin(
const this_type &v) { 
return v.origin; }
 
  195     static void do_clear(this_type &m);
 
  196     static value_type access(
const const_row_iterator &itrow, 
size_type i)
 
  197     { 
return linalg_traits<M>::access(itrow, i); }
 
  198     static reference access(
const row_iterator &itrow, 
size_type i)
 
  199     { 
return linalg_traits<M>::access(itrow, i); }
 
  202   template <
typename PT> 
 
  203   void linalg_traits<transposed_col_ref<PT> >::do_clear(this_type &v) { 
 
  204     row_iterator it = mat_row_begin(v), ite = mat_row_end(v);
 
  205     for (; it != ite; ++it) 
clear(row(it));
 
  208   template<
typename PT> std::ostream &
operator <<
 
  209   (std::ostream &o, 
const transposed_col_ref<PT>& m)
 
  210   { gmm::write(o,m); 
return o; }
 
  212   template <
typename TYPE, 
typename PT> 
struct transposed_return_ {
 
  213     typedef abstract_null_type return_type;
 
  215   template <
typename PT> 
struct transposed_return_<row_major, PT> {
 
  216     typedef typename std::iterator_traits<PT>::value_type L;
 
  217     typedef typename select_return<transposed_row_ref<const L *>,
 
  218             transposed_row_ref< L *>, PT>::return_type return_type;
 
  220   template <
typename PT> 
struct transposed_return_<col_major, PT> {
 
  221     typedef typename std::iterator_traits<PT>::value_type L;
 
  222     typedef typename select_return<transposed_col_ref<const L *>,
 
  223             transposed_col_ref< L *>, PT>::return_type return_type;
 
  225   template <
typename PT> 
struct transposed_return {
 
  226     typedef typename std::iterator_traits<PT>::value_type L;
 
  227     typedef typename transposed_return_<
typename principal_orientation_type<
 
  228             typename linalg_traits<L>::sub_orientation>::potype,
 
  229             PT>::return_type return_type;
 
  232   template <
typename L> 
inline  
  233   typename transposed_return<const L *>::return_type transposed(
const L &l) {
 
  234     return typename transposed_return<const L *>::return_type
 
  235       (linalg_cast(
const_cast<L &
>(l)));
 
  238   template <
typename L> 
inline  
  239   typename transposed_return<L *>::return_type transposed(L &l)
 
  240   { 
return typename transposed_return<L *>::return_type(linalg_cast(l)); }
 
void clear(L &l)
clear (fill with zeros) a vector or matrix.
 
Basic definitions and tools of GMM.
 
size_t size_type
used as the common size type in the library