op_cumsum_meat.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2010-2011 Conrad Sanderson
00003 // 
00004 // This file is part of the Armadillo C++ library.
00005 // It is provided without any warranty of fitness
00006 // for any purpose. You can redistribute this file
00007 // and/or modify it under the terms of the GNU
00008 // Lesser General Public License (LGPL) as published
00009 // by the Free Software Foundation, either version 3
00010 // of the License or (at your option) any later version.
00011 // (see http://www.opensource.org/licenses for more info)
00012 
00013 
00016 
00017 
00018 template<typename T1>
00019 inline
00020 void
00021 op_cumsum_mat::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cumsum_mat>& in)
00022   {
00023   arma_extra_debug_sigprint();
00024   
00025   typedef typename T1::elem_type eT;
00026   
00027   const unwrap<T1>   tmp(in.m);
00028   const Mat<eT>& X = tmp.M;
00029   
00030   const uword dim = in.aux_uword_a;
00031   arma_debug_check( (dim > 1), "cumsum(): incorrect usage. dim must be 0 or 1");
00032   
00033   out.copy_size(X);
00034   
00035   const uword X_n_rows = X.n_rows;
00036   const uword X_n_cols = X.n_cols;
00037   
00038   if(dim == 0)
00039     {
00040     arma_extra_debug_print("op_cumsum::apply(), dim = 0");
00041     
00042     for(uword col=0; col<X_n_cols; ++col)
00043       {
00044             eT* out_colmem = out.colptr(col);
00045       const eT* X_colmem   = X.colptr(col);
00046       
00047       eT acc = eT(0);
00048       
00049       for(uword row=0; row<X_n_rows; ++row)
00050         {
00051         acc += X_colmem[row];
00052         
00053         out_colmem[row] = acc;
00054         }
00055       }
00056     }
00057   else
00058   if(dim == 1)
00059     {
00060     arma_extra_debug_print("op_cumsum::apply(), dim = 1");
00061     
00062     for(uword row=0; row<X_n_rows; ++row)
00063       {
00064       eT acc = eT(0);
00065       
00066       for(uword col=0; col<X_n_cols; ++col)
00067         {
00068         acc += X.at(row,col);
00069         
00070         out.at(row,col) = acc;
00071         }
00072       }
00073     }
00074   }
00075 
00076 
00077 
00078 template<typename T1>
00079 inline
00080 void
00081 op_cumsum_vec::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cumsum_vec>& in)
00082   {
00083   arma_extra_debug_sigprint();
00084   
00085   typedef typename T1::elem_type eT;
00086   
00087   const unwrap<T1>   tmp(in.m);
00088   const Mat<eT>& X = tmp.M;
00089   
00090   const uword n_elem = X.n_elem;
00091   
00092   out.copy_size(X);
00093   
00094         eT* out_mem = out.memptr();
00095   const eT* X_mem   = X.memptr();
00096   
00097   eT acc = eT(0);
00098   
00099   for(uword i=0; i<n_elem; ++i)
00100     {
00101     acc += X_mem[i];
00102     
00103     out_mem[i] = acc;
00104     }
00105   }
00106 
00107 
00108 
00110 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:05