op_cumsum_meat.hpp
Go to the documentation of this file.
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 
16 
17 
18 template<typename T1>
19 inline
20 void
22  {
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
82  {
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 
110 
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
Definition: Mat_meat.hpp:4024
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
static void apply(Mat< typename T1::elem_type > &out, const Op< T1, op_cumsum_vec > &in)
#define arma_extra_debug_print
Definition: debug.hpp:1118
arma_aligned const T1 & m
storage of reference to the operand (eg. a matrix)
Definition: Op_bones.hpp:45
arma_inline arma_warn_unused eT * colptr(const uword in_col)
returns a pointer to array of eTs for a specified column; no bounds check
Definition: Mat_meat.hpp:4000
u32 uword
Definition: typedef.hpp:85
#define arma_debug_check
Definition: debug.hpp:1084
const Mat< eT > M
Definition: unwrap.hpp:32
arma_inline arma_warn_unused eT & at(const uword i)
linear element accessor (treats the matrix as a vector); no bounds check.
Definition: Mat_meat.hpp:3692
void copy_size(const Mat< eT2 > &m)
change the matrix (without preserving data) to have the same dimensions as the given matrix ...
Definition: Mat_meat.hpp:4303
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
Dense matrix class.
static void apply(Mat< typename T1::elem_type > &out, const Op< T1, op_cumsum_mat > &in)
arma_aligned uword aux_uword_a
storage of auxiliary data, uword format
Definition: Op_bones.hpp:47


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:58