"Fossies" - the Fresh Open Source Software Archive

Member "armadillo-9.800.3/include/armadillo_bits/spop_reverse_meat.hpp" (16 Jun 2016, 3990 Bytes) of package /linux/misc/armadillo-9.800.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "spop_reverse_meat.hpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
    2 // Copyright 2008-2016 National ICT Australia (NICTA)
    3 // 
    4 // Licensed under the Apache License, Version 2.0 (the "License");
    5 // you may not use this file except in compliance with the License.
    6 // You may obtain a copy of the License at
    7 // http://www.apache.org/licenses/LICENSE-2.0
    8 // 
    9 // Unless required by applicable law or agreed to in writing, software
   10 // distributed under the License is distributed on an "AS IS" BASIS,
   11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12 // See the License for the specific language governing permissions and
   13 // limitations under the License.
   14 // ------------------------------------------------------------------------
   15 
   16 
   17 //! \addtogroup spop_reverse
   18 //! @{
   19 
   20 
   21 
   22 template<typename eT>
   23 inline
   24 void
   25 spop_reverse::apply_spmat(SpMat<eT>& out, const SpMat<eT>& X, const uword dim)
   26   {
   27   arma_extra_debug_sigprint();
   28   
   29   const uword X_n_rows = X.n_rows;
   30   const uword X_n_cols = X.n_cols;
   31   
   32   const uword X_n_rows_m1 = X_n_rows - 1;
   33   const uword X_n_cols_m1 = X_n_cols - 1;
   34   
   35   const uword N = X.n_nonzero;
   36   
   37   if(N == uword(0))
   38     {
   39     out.zeros(X_n_rows, X_n_cols);
   40     return;
   41     }
   42   
   43   umat locs(2, N);
   44   
   45   uword* locs_mem = locs.memptr();
   46   
   47   typename SpMat<eT>::const_iterator it = X.begin();
   48   
   49   if(dim == 0)
   50     {
   51     for(uword i=0; i < N; ++i)
   52       {
   53       const uword row = it.row();
   54       const uword col = it.col();
   55       
   56       (*locs_mem) = X_n_rows_m1 - row;  locs_mem++;
   57       (*locs_mem) =               col;  locs_mem++;
   58       
   59       ++it;
   60       }
   61     }
   62   else
   63   if(dim == 1)
   64     {
   65     for(uword i=0; i < N; ++i)
   66       {
   67       const uword row = it.row();
   68       const uword col = it.col();
   69       
   70       (*locs_mem) =               row;  locs_mem++;
   71       (*locs_mem) = X_n_cols_m1 - col;  locs_mem++;
   72       
   73       ++it;
   74       }
   75     }
   76   
   77   const Col<eT> vals(const_cast<eT*>(X.values), N, false);
   78   
   79   SpMat<eT> tmp(locs, vals, X_n_rows, X_n_cols, true, false);
   80   
   81   out.steal_mem(tmp);
   82   }
   83 
   84 
   85 
   86 template<typename T1>
   87 inline
   88 void
   89 spop_reverse::apply_proxy(SpMat<typename T1::elem_type>& out, const T1& X, const uword dim)
   90   {
   91   arma_extra_debug_sigprint();
   92   
   93   typedef typename T1::elem_type eT;
   94   
   95   const SpProxy<T1> P(X);
   96   
   97   const uword P_n_rows = P.get_n_rows();
   98   const uword P_n_cols = P.get_n_cols();
   99   
  100   const uword P_n_rows_m1 = P_n_rows - 1;
  101   const uword P_n_cols_m1 = P_n_cols - 1;
  102   
  103   const uword N = P.get_n_nonzero();
  104   
  105   if(N == uword(0))
  106     {
  107     out.zeros(P_n_rows, P_n_cols);
  108     return;
  109     }
  110   
  111   umat    locs(2, N);
  112   Col<eT> vals(   N);
  113   
  114   uword* locs_mem = locs.memptr();
  115   eT*    vals_mem = vals.memptr();
  116   
  117   typename SpProxy<T1>::const_iterator_type it = P.begin();
  118   
  119   if(dim == 0)
  120     {
  121     for(uword i=0; i < N; ++i)
  122       {
  123       const uword row = it.row();
  124       const uword col = it.col();
  125       
  126       (*locs_mem) = P_n_rows_m1 - row;  locs_mem++;
  127       (*locs_mem) =               col;  locs_mem++;
  128       
  129       (*vals_mem) = (*it);  vals_mem++;
  130       
  131       ++it;
  132       }
  133     }
  134   else
  135   if(dim == 1)
  136     {
  137     for(uword i=0; i < N; ++i)
  138       {
  139       const uword row = it.row();
  140       const uword col = it.col();
  141       
  142       (*locs_mem) =               row;  locs_mem++;
  143       (*locs_mem) = P_n_cols_m1 - col;  locs_mem++;
  144       
  145       (*vals_mem) = (*it);  vals_mem++;
  146       
  147       ++it;
  148       }
  149     }
  150   
  151   SpMat<eT> tmp(locs, vals, P_n_rows, P_n_cols, true, false);
  152   
  153   out.steal_mem(tmp);
  154   }
  155 
  156 
  157 
  158 template<typename T1>
  159 inline
  160 void
  161 spop_reverse::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_reverse>& in)
  162   {
  163   arma_extra_debug_sigprint();
  164   
  165   const uword dim = in.aux_uword_a;
  166   
  167   arma_debug_check( (dim > 1), "reverse(): parameter 'dim' must be 0 or 1" );
  168   
  169   if(is_SpMat<T1>::value)
  170     {
  171     const unwrap_spmat<T1> tmp(in.m);
  172     
  173     spop_reverse::apply_spmat(out, tmp.M, dim);
  174     }
  175   else
  176     {
  177     spop_reverse::apply_proxy(out, in.m, dim);
  178     }
  179   }
  180 
  181 
  182 
  183 //! @}