max@0: // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2010 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_sum max@0: //! @{ max@0: max@0: max@0: //! \brief max@0: //! Delayed sum of elements of a matrix along a specified dimension (either rows or columns). max@0: //! The result is stored in a dense matrix that has either one column or one row. max@0: //! For dim = 0, find the sum of each column. max@0: //! For dim = 1, find the sum of each row. max@0: //! The default is dim = 0. max@0: //! NOTE: this function works differently than in Matlab/Octave. max@0: max@0: template max@0: arma_inline max@0: const Op max@0: sum(const Base& X, const uword dim = 0) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Op(X.get_ref(), dim, 0); max@0: } max@0: max@0: max@0: //! \brief max@0: //! Immediate 'sum all values' operation for a row vector max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: sum(const Row& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return accu(X); max@0: } max@0: max@0: max@0: max@0: //! \brief max@0: //! Immediate 'sum all values' operation for a column vector max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: sum(const Col& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return accu(X); max@0: } max@0: max@0: max@0: max@0: //! \brief max@0: //! Immediate 'sum all values' operation, max@0: //! invoked, for example, by: sum(sum(A)) max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: typename T1::elem_type max@0: sum(const Op& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: arma_extra_debug_print("sum(): two consecutive sum() calls detected"); max@0: max@0: return accu(in.m); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: const Op, op_sum> max@0: sum(const Op& in, const uword dim) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Op, op_sum>(in, dim, 0); max@0: } max@0: max@0: max@0: max@0: //! sum all values of a subview_row max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: sum(const subview_row& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return accu(X); max@0: } max@0: max@0: max@0: max@0: //! sum all values of a subview_col max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: sum(const subview_col& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return accu(X); max@0: } max@0: max@0: max@0: max@0: //! sum all values of a diagview max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: sum(const diagview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return accu(X); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: sum(const subview_elem1& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return accu(A); max@0: } max@0: max@0: max@0: max@0: //! @}