comparison armadillo-2.4.4/include/armadillo_bits/op_cumsum_meat.hpp @ 0:8b6102e2a9b0

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