Fn_accu

Functions

template<typename T1 >
arma_hot T1::elem_type accu_unwrap (const Base< typename T1::elem_type, T1 > &X)
template<typename T1 >
arma_hot T1::elem_type accu_proxy (const Base< typename T1::elem_type, T1 > &X)
template<typename T1 >
arma_inline arma_warn_unused
T1::elem_type 
accu (const Base< typename T1::elem_type, T1 > &X)
 accumulate the elements of a matrix
template<typename T1 >
arma_hot arma_warn_unused
T1::elem_type 
accu (const BaseCube< typename T1::elem_type, T1 > &X)
 accumulate the elements of a cube
template<typename eT >
arma_pure arma_warn_unused eT accu (const diagview< eT > &X)
 accumulate the elements of a diagview
template<typename eT >
arma_pure arma_warn_unused eT accu (const subview< eT > &S)
 accumulate the elements of a subview (submatrix)
template<typename eT >
arma_pure arma_warn_unused eT accu (const subview_row< eT > &S)
 accumulate the elements of a subview_row
template<typename eT >
arma_pure arma_warn_unused eT accu (const subview_col< eT > &S)
 accumulate the elements of a subview_col

Function Documentation

template<typename T1 >
arma_hot T1::elem_type accu_unwrap ( const Base< typename T1::elem_type, T1 > &  X  )  [inline]

Definition at line 26 of file fn_accu.hpp.

References Base< elem_type, derived >::get_ref().

Referenced by accu().

00027   {
00028   arma_extra_debug_sigprint();
00029   
00030   typedef typename T1::elem_type eT;
00031   
00032   const unwrap<T1>   tmp(X.get_ref());
00033   const Mat<eT>& A = tmp.M;
00034   
00035   const eT* A_mem = A.memptr();
00036   const u32 N     = A.n_elem;
00037   
00038   eT val1 = eT(0);
00039   eT val2 = eT(0);
00040   
00041   u32 i,j;
00042   
00043   for(i=0, j=1; j<N; i+=2, j+=2)
00044     {
00045     val1 += A_mem[i];
00046     val2 += A_mem[j];
00047     }
00048   
00049   if(i < N)
00050     {
00051     val1 += A_mem[i];
00052     }
00053   
00054   return val1 + val2;
00055   }

template<typename T1 >
arma_hot T1::elem_type accu_proxy ( const Base< typename T1::elem_type, T1 > &  X  )  [inline]

Definition at line 63 of file fn_accu.hpp.

References Base< elem_type, derived >::get_ref().

Referenced by accu().

00064   {
00065   arma_extra_debug_sigprint();
00066   
00067   typedef typename T1::elem_type eT;
00068   
00069   const Proxy<T1> A(X.get_ref());
00070   
00071   const u32 N = A.n_elem;
00072   
00073   eT val = eT(0);
00074   
00075   for(u32 i=0; i<N; ++i)
00076     {
00077     val += A[i];
00078     }
00079   
00080   return val;
00081   }

template<typename T1 >
arma_inline arma_warn_unused T1::elem_type accu ( const Base< typename T1::elem_type, T1 > &  X  )  [inline]

accumulate the elements of a matrix

Definition at line 90 of file fn_accu.hpp.

References accu_proxy(), and accu_unwrap().

Referenced by sum().

00091   {
00092   arma_extra_debug_sigprint();
00093   
00094   return (is_Mat<T1>::value == true) ? accu_unwrap(X) : accu_proxy(X);
00095   }

template<typename T1 >
arma_hot arma_warn_unused T1::elem_type accu ( const BaseCube< typename T1::elem_type, T1 > &  X  )  [inline]

accumulate the elements of a cube

Definition at line 105 of file fn_accu.hpp.

References BaseCube< elem_type, derived >::get_ref().

00106   {
00107   arma_extra_debug_sigprint();
00108   
00109   typedef typename T1::elem_type eT;
00110   
00111   const ProxyCube<T1> A(X.get_ref());
00112   
00113   const u32 n_elem = A.n_elem;
00114   
00115   eT val = eT(0);
00116   
00117   for(u32 i=0; i<n_elem; ++i)
00118     {
00119     val += A[i];
00120     }
00121   
00122   return val;
00123   }

template<typename eT >
arma_pure arma_warn_unused eT accu ( const diagview< eT > &  X  )  [inline]

accumulate the elements of a diagview

Definition at line 133 of file fn_accu.hpp.

References diagview< eT >::n_elem.

00134   {
00135   arma_extra_debug_sigprint();  
00136   
00137   const u32 n_elem = X.n_elem;
00138   eT val = eT(0);
00139   
00140   for(u32 i=0; i<n_elem; ++i)
00141     {
00142     val += X[i];
00143     }
00144   
00145   return val;
00146   }

template<typename eT >
arma_pure arma_warn_unused eT accu ( const subview< eT > &  S  )  [inline]

accumulate the elements of a subview (submatrix)

Definition at line 156 of file fn_accu.hpp.

References subview< eT >::colptr(), subview< eT >::n_cols, and subview< eT >::n_rows.

00157   {
00158   arma_extra_debug_sigprint();  
00159   
00160   eT val = eT(0);
00161   
00162   for(u32 col=0; col<S.n_cols; ++col)
00163     {
00164     const eT* coldata = S.colptr(col);
00165     
00166     for(u32 row=0; row<S.n_rows; ++row)
00167       {
00168       val += coldata[row];
00169       }
00170     
00171     }
00172   
00173   return val;
00174   }

template<typename eT >
arma_pure arma_warn_unused eT accu ( const subview_row< eT > &  S  )  [inline]

accumulate the elements of a subview_row

Definition at line 184 of file fn_accu.hpp.

References Mat< eT >::at(), subview< eT >::aux_col1, subview< eT >::aux_col2, subview< eT >::aux_row1, and subview< eT >::m.

00185   {
00186   arma_extra_debug_sigprint();  
00187   
00188   const Mat<eT>& X = S.m;
00189   
00190   const u32 row       = S.aux_row1;
00191   const u32 start_col = S.aux_col1;
00192   const u32 end_col   = S.aux_col2;
00193   
00194   eT val = eT(0);
00195   
00196   for(u32 col=start_col; col<=end_col; ++col)
00197     {
00198     val += X.at(row,col);
00199     }
00200   
00201   return val;
00202   }

template<typename eT >
arma_pure arma_warn_unused eT accu ( const subview_col< eT > &  S  )  [inline]

accumulate the elements of a subview_col

Definition at line 212 of file fn_accu.hpp.

References subview< eT >::colptr(), and subview< eT >::n_rows.

00213   {
00214   arma_extra_debug_sigprint();
00215   
00216   const eT* S_colptr = S.colptr(0);
00217   const u32 n_rows   = S.n_rows;
00218   
00219   eT val = eT(0);
00220   
00221   for(u32 row=0; row<n_rows; ++row)
00222     {
00223     val += S_colptr[row];
00224     }
00225   
00226   return val;
00227   }