fn_mean.hpp
Go to the documentation of this file.
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-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 
19 template<typename T1>
21 const Op<T1, op_mean>
22 mean(const Base<typename T1::elem_type,T1>& X, const uword dim = 0)
23  {
25 
26  return Op<T1, op_mean>(X.get_ref(), dim, 0);
27  }
28 
29 
30 
32 template<typename eT>
33 inline
35 eT
36 mean(const Row<eT>& A)
37  {
39 
40  const uword A_n_elem = A.n_elem;
41 
42  arma_debug_check( (A_n_elem == 0), "mean(): given object has no elements" );
43 
44  return op_mean::direct_mean(A.mem, A_n_elem);
45  }
46 
47 
48 
50 template<typename eT>
51 inline
53 eT
54 mean(const Col<eT>& A)
55  {
57 
58  const uword A_n_elem = A.n_elem;
59 
60  arma_debug_check( (A_n_elem == 0), "mean(): given object has no elements" );
61 
62  return op_mean::direct_mean(A.mem, A_n_elem);
63  }
64 
65 
66 
70 template<typename T1>
71 inline
73 typename T1::elem_type
75  {
77  arma_extra_debug_print("mean(): two consecutive mean() calls detected");
78 
79  typedef typename T1::elem_type eT;
80 
81  const unwrap<T1> tmp1(in.m);
82  const Mat<eT>& X = tmp1.M;
83 
84  const uword X_n_elem = X.n_elem;
85 
86  arma_debug_check( (X_n_elem == 0), "mean(): given object has no elements" );
87 
88  return op_mean::direct_mean(X.mem, X_n_elem);
89  }
90 
91 
92 
93 template<typename T1>
96 mean(const Op<T1, op_mean>& in, const uword dim)
97  {
99 
100  return Op< Op<T1, op_mean>, op_mean>(in, dim, 0);
101  }
102 
103 
104 
105 template<typename eT>
106 inline
108 eT
110  {
112 
113  arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" );
114 
115  const eT mu = accu(A) / eT(A.n_cols);
116 
117  return is_finite(mu) ? mu : op_mean::direct_mean_robust(A);
118  }
119 
120 
121 
122 template<typename eT>
123 inline
125 eT
127  {
129 
130  arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" );
131 
132  return op_mean::direct_mean(A.colptr(0), A.n_rows);
133  }
134 
135 
136 
137 template<typename eT>
138 inline
140 eT
142  {
144  arma_extra_debug_print("mean(): two consecutive mean() calls detected");
145 
146  const subview<eT>& X = in.m;
147 
148  arma_debug_check( (X.n_elem == 0), "mean(): given object has no elements" );
149 
150  return op_mean::direct_mean(X);
151  }
152 
153 
154 
155 template<typename eT>
156 inline
158 eT
160  {
162 
163  arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" );
164 
165  return op_mean::direct_mean(A);
166  }
167 
168 
169 
170 template<typename eT, typename T1>
171 inline
173 eT
175  {
177 
178  const Mat<eT> X(A);
179 
180  const uword X_n_elem = X.n_elem;
181 
182  arma_debug_check( (X_n_elem == 0), "mean(): given object has no elements" );
183 
184  return op_mean::direct_mean(X.mem, X_n_elem);
185  }
186 
187 
188 
arma_inline const derived & get_ref() const
Definition: Base_meat.hpp:22
const uword n_cols
const uword n_rows
static eT direct_mean(const eT *const X, const uword N)
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
arma_inline arma_warn_unused bool is_finite(const eT x, const typename arma_scalar_only< eT >::result *junk=0)
Definition: fn_misc.hpp:132
arma_hot T1::elem_type accu(const Base< typename T1::elem_type, T1 > &X)
accumulate the elements of a matrix
Definition: fn_accu.hpp:24
arma_inline const Op< T1, op_mean > mean(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Definition: fn_mean.hpp:22
#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
const uword n_elem
u32 uword
Definition: typedef.hpp:85
Class for column vectors (matrices with only one column)
Definition: Col_bones.hpp:20
static eT direct_mean_robust(const eT *const X, const uword N)
#define arma_debug_check
Definition: debug.hpp:1084
const Mat< eT > M
Definition: unwrap.hpp:32
arma_aligned const Mat< eT > & m
arma_inline eT * colptr(const uword in_col)
Class for finding mean values of a matrix.
Class for row vectors (matrices with only one row)
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
#define arma_warn_unused
Dense matrix class.
#define arma_inline
const uword n_elem
arma_aligned const eT *const mem
pointer to the memory used by the matrix (memory is read-only)
Definition: Mat_bones.hpp:40
Class for storing data required to extract and set the diagonals of a matrix.


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