annotate armadillo-2.4.4/include/armadillo_bits/op_cumsum_meat.hpp @ 18:8d046a9d36aa slimline

Back out rev 13:ac07c60aa798. Like an idiot, I committed a whole pile of unrelated changes in the guise of a single typo fix. Will re-commit in stages
author Chris Cannam
date Thu, 10 May 2012 10:45:44 +0100
parents 8b6102e2a9b0
children
rev   line source
max@0 1 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
max@0 2 // Copyright (C) 2010-2011 Conrad Sanderson
max@0 3 //
max@0 4 // This file is part of the Armadillo C++ library.
max@0 5 // It is provided without any warranty of fitness
max@0 6 // for any purpose. You can redistribute this file
max@0 7 // and/or modify it under the terms of the GNU
max@0 8 // Lesser General Public License (LGPL) as published
max@0 9 // by the Free Software Foundation, either version 3
max@0 10 // of the License or (at your option) any later version.
max@0 11 // (see http://www.opensource.org/licenses for more info)
max@0 12
max@0 13
max@0 14 //! \addtogroup op_cumsum
max@0 15 //! @{
max@0 16
max@0 17
max@0 18 template<typename T1>
max@0 19 inline
max@0 20 void
max@0 21 op_cumsum_mat::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cumsum_mat>& in)
max@0 22 {
max@0 23 arma_extra_debug_sigprint();
max@0 24
max@0 25 typedef typename T1::elem_type eT;
max@0 26
max@0 27 const unwrap<T1> tmp(in.m);
max@0 28 const Mat<eT>& X = tmp.M;
max@0 29
max@0 30 const uword dim = in.aux_uword_a;
max@0 31 arma_debug_check( (dim > 1), "cumsum(): incorrect usage. dim must be 0 or 1");
max@0 32
max@0 33 out.copy_size(X);
max@0 34
max@0 35 const uword X_n_rows = X.n_rows;
max@0 36 const uword X_n_cols = X.n_cols;
max@0 37
max@0 38 if(dim == 0)
max@0 39 {
max@0 40 arma_extra_debug_print("op_cumsum::apply(), dim = 0");
max@0 41
max@0 42 for(uword col=0; col<X_n_cols; ++col)
max@0 43 {
max@0 44 eT* out_colmem = out.colptr(col);
max@0 45 const eT* X_colmem = X.colptr(col);
max@0 46
max@0 47 eT acc = eT(0);
max@0 48
max@0 49 for(uword row=0; row<X_n_rows; ++row)
max@0 50 {
max@0 51 acc += X_colmem[row];
max@0 52
max@0 53 out_colmem[row] = acc;
max@0 54 }
max@0 55 }
max@0 56 }
max@0 57 else
max@0 58 if(dim == 1)
max@0 59 {
max@0 60 arma_extra_debug_print("op_cumsum::apply(), dim = 1");
max@0 61
max@0 62 for(uword row=0; row<X_n_rows; ++row)
max@0 63 {
max@0 64 eT acc = eT(0);
max@0 65
max@0 66 for(uword col=0; col<X_n_cols; ++col)
max@0 67 {
max@0 68 acc += X.at(row,col);
max@0 69
max@0 70 out.at(row,col) = acc;
max@0 71 }
max@0 72 }
max@0 73 }
max@0 74 }
max@0 75
max@0 76
max@0 77
max@0 78 template<typename T1>
max@0 79 inline
max@0 80 void
max@0 81 op_cumsum_vec::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cumsum_vec>& in)
max@0 82 {
max@0 83 arma_extra_debug_sigprint();
max@0 84
max@0 85 typedef typename T1::elem_type eT;
max@0 86
max@0 87 const unwrap<T1> tmp(in.m);
max@0 88 const Mat<eT>& X = tmp.M;
max@0 89
max@0 90 const uword n_elem = X.n_elem;
max@0 91
max@0 92 out.copy_size(X);
max@0 93
max@0 94 eT* out_mem = out.memptr();
max@0 95 const eT* X_mem = X.memptr();
max@0 96
max@0 97 eT acc = eT(0);
max@0 98
max@0 99 for(uword i=0; i<n_elem; ++i)
max@0 100 {
max@0 101 acc += X_mem[i];
max@0 102
max@0 103 out_mem[i] = acc;
max@0 104 }
max@0 105 }
max@0 106
max@0 107
max@0 108
max@0 109 //! @}
max@0 110