max@0: // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2009-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_mean max@0: //! @{ max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: const Op max@0: mean(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: max@0: //! Immediate 'find the mean value of a row vector' operation max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: mean(const Row& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword A_n_elem = A.n_elem; max@0: max@0: arma_debug_check( (A_n_elem == 0), "mean(): given object has no elements" ); max@0: max@0: return op_mean::direct_mean(A.mem, A_n_elem); max@0: } max@0: max@0: max@0: max@0: //! Immediate 'find the mean value of a column vector' operation max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: mean(const Col& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword A_n_elem = A.n_elem; max@0: max@0: arma_debug_check( (A_n_elem == 0), "mean(): given object has no elements" ); max@0: max@0: return op_mean::direct_mean(A.mem, A_n_elem); max@0: } max@0: max@0: max@0: max@0: //! \brief max@0: //! Immediate 'find mean value' operation, max@0: //! invoked, for example, by: mean(mean(A)) max@0: template max@0: inline max@0: arma_warn_unused max@0: typename T1::elem_type max@0: mean(const Op& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: arma_extra_debug_print("mean(): two consecutive mean() calls detected"); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const unwrap tmp1(in.m); max@0: const Mat& X = tmp1.M; max@0: max@0: const uword X_n_elem = X.n_elem; max@0: max@0: arma_debug_check( (X_n_elem == 0), "mean(): given object has no elements" ); max@0: max@0: return op_mean::direct_mean(X.mem, X_n_elem); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: const Op< Op, op_mean> max@0: mean(const Op& in, const uword dim) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Op< Op, op_mean>(in, dim, 0); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: mean(const subview_row& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" ); max@0: max@0: const eT mu = accu(A) / eT(A.n_cols); max@0: max@0: return is_finite(mu) ? mu : op_mean::direct_mean_robust(A); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: mean(const subview_col& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" ); max@0: max@0: return op_mean::direct_mean(A.colptr(0), A.n_rows); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: mean(const Op, op_mean>& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: arma_extra_debug_print("mean(): two consecutive mean() calls detected"); max@0: max@0: const subview& X = in.m; max@0: max@0: arma_debug_check( (X.n_elem == 0), "mean(): given object has no elements" ); max@0: max@0: return op_mean::direct_mean(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: mean(const diagview& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" ); max@0: max@0: return op_mean::direct_mean(A); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: mean(const subview_elem1& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat X(A); max@0: max@0: const uword X_n_elem = X.n_elem; max@0: max@0: arma_debug_check( (X_n_elem == 0), "mean(): given object has no elements" ); max@0: max@0: return op_mean::direct_mean(X.mem, X_n_elem); max@0: } max@0: max@0: max@0: max@0: //! @}