max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup fn_accu max@0: //! @{ max@0: max@0: max@0: max@0: //! accumulate the elements of a matrix max@0: template max@0: arma_hot max@0: inline max@0: typename T1::elem_type max@0: accu(const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: typedef typename Proxy::ea_type ea_type; max@0: max@0: const Proxy A(X.get_ref()); max@0: max@0: if(Proxy::prefer_at_accessor == false) max@0: { max@0: ea_type P = A.get_ea(); max@0: const uword n_elem = A.get_n_elem(); max@0: max@0: eT val1 = eT(0); max@0: eT val2 = eT(0); max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j max@0: arma_inline max@0: arma_warn_unused max@0: uword max@0: accu(const mtOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const Proxy A(X.m); max@0: max@0: const uword n_elem = A.get_n_elem(); max@0: const eT val = X.aux; max@0: max@0: uword n_nonzero = 0; max@0: for(uword i=0; i max@0: arma_hot max@0: arma_warn_unused max@0: inline max@0: typename T1::elem_type max@0: accu(const BaseCube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: typedef typename ProxyCube::ea_type ea_type; max@0: max@0: const ProxyCube A(X.get_ref()); max@0: max@0: if(ProxyCube::prefer_at_accessor == false) max@0: { max@0: max@0: ea_type P = A.get_ea(); max@0: const uword n_elem = A.get_n_elem(); max@0: max@0: eT val1 = eT(0); max@0: eT val2 = eT(0); max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j max@0: arma_pure max@0: arma_warn_unused max@0: inline max@0: eT max@0: accu(const diagview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword n_elem = X.n_elem; max@0: max@0: eT val = eT(0); max@0: max@0: for(uword i=0; i max@0: arma_pure max@0: arma_warn_unused max@0: inline max@0: eT max@0: accu(const subview& S) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword S_n_rows = S.n_rows; max@0: const uword S_n_cols = S.n_cols; max@0: const uword S_n_elem = S.n_elem; max@0: max@0: eT val = eT(0); max@0: max@0: if(S_n_elem > 0) max@0: { max@0: for(uword col=0; col max@0: arma_pure max@0: arma_warn_unused max@0: inline max@0: eT max@0: accu(const subview_row& S) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat& X = S.m; max@0: max@0: const uword n_elem = S.n_elem; max@0: const uword row = S.aux_row1; max@0: const uword start_col = S.aux_col1; max@0: const uword end_col_p1 = start_col + S.n_cols; max@0: max@0: eT val = eT(0); max@0: max@0: if(n_elem > 0) max@0: { max@0: uword i,j; max@0: max@0: for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) max@0: { max@0: val += X.at(row,i); max@0: val += X.at(row,j); max@0: } max@0: max@0: if(i < end_col_p1) max@0: { max@0: val += X.at(row,i); max@0: } max@0: } max@0: max@0: return val; max@0: } max@0: max@0: max@0: max@0: //! accumulate the elements of a subview_col max@0: template max@0: arma_pure max@0: arma_warn_unused max@0: inline max@0: eT max@0: accu(const subview_col& S) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (S.n_elem > 0) ? arrayops::accumulate( S.colptr(0), S.n_rows ) : eT(0); max@0: } max@0: max@0: max@0: max@0: //! @}