35 for(i=0, j=1; j<n_elem; i+=2, j+=2)
40 const eT tmpi = acc1 - Xi;
41 const eT tmpj = acc1 - Xj;
43 acc2 += tmpi*tmpi + tmpj*tmpj;
51 const eT tmpi = acc1 - Xi;
57 const eT norm_val = (norm_type == 0) ? eT(n_elem-1) : eT(n_elem);
58 const eT var_val = (acc2 - acc3*acc3/eT(n_elem)) / norm_val;
78 typedef typename std::complex<T> eT;
87 for(
uword i=0; i<n_elem; ++i)
89 const eT tmp = acc1 - X[i];
95 const T norm_val = (norm_type == 0) ? T(n_elem-1) : T(n_elem);
96 const T var_val = (acc2 -
std::norm(acc3)/T(n_elem)) / norm_val;
109 template<
typename eT>
120 eT* tmp_mem = tmp.
memptr();
122 for(
uword i=0; i<n_elem; ++i)
133 template<
typename eT>
146 template<
typename eT>
157 eT* tmp_mem = tmp.
memptr();
159 for(
uword i=0; i<n_elem; ++i)
173 template<
typename T1>
180 typedef typename T1::elem_type in_eT;
181 typedef typename T1::pod_type out_eT;
189 arma_debug_check( (norm_type > 1),
"var(): incorrect usage. norm_type must be 0 or 1");
190 arma_debug_check( (dim > 1),
"var(): incorrect usage. dim must be 0 or 1" );
203 out_eT* out_mem = out.
memptr();
205 for(
uword col=0; col<X_n_cols; ++col)
215 arma_debug_check( (X_n_cols == 0),
"var(): given object has zero columns" );
221 in_eT* tmp_mem = tmp.
memptr();
222 out_eT* out_mem = out.
memptr();
224 for(
uword row=0; row<X_n_rows; ++row)
236 template<
typename eT>
248 for(
uword i=1; i<n_elem; ++i)
250 const eT tmp = X[i] - r_mean;
251 const eT i_plus_1 = eT(i+1);
253 r_var = eT(i-1)/eT(i) * r_var + (tmp*tmp)/i_plus_1;
255 r_mean = r_mean + tmp/i_plus_1;
258 return (norm_type == 0) ? r_var : (eT(n_elem-1)/eT(n_elem)) * r_var;
276 typedef typename std::complex<T> eT;
283 for(
uword i=1; i<n_elem; ++i)
285 const eT tmp = X[i] - r_mean;
286 const T i_plus_1 = T(i+1);
288 r_var = T(i-1)/T(i) * r_var +
std::norm(tmp)/i_plus_1;
290 r_mean = r_mean + tmp/i_plus_1;
293 return (norm_type == 0) ? r_var : (T(n_elem-1)/T(n_elem)) * r_var;
arma_hot void copy_row(const Mat< eT > &A, const uword row)
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
arma_aligned uword aux_uword_b
storage of auxiliary data, uword format
A lightweight array for POD types. If the amount of memory requested is small, the stack is used...
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
arma_aligned const T1 & m
storage of reference to the operand (eg. a matrix)
const uword n_cols
number of columns in the matrix (read-only)
static eT direct_mean(const eT *const X, const uword N)
const uword n_rows
number of rows in the matrix (read-only)
arma_warn_unused T1::pod_type norm(const Base< typename T1::elem_type, T1 > &X, const uword k, const typename arma_float_or_cx_only< typename T1::elem_type >::result *junk=0)
#define arma_extra_debug_print
arma_inline arma_warn_unused eT * colptr(const uword in_col)
returns a pointer to array of eTs for a specified column; no bounds check
static eT direct_var(const eT *const X, const uword N, const uword norm_type=0)
find the variance of an array
static eT direct_var_robust(const eT *const X, const uword N, const uword norm_type=0)
find the variance of an array (robust but slow)
arma_inline eT * colptr(const uword in_col)
#define arma_extra_debug_sigprint
arma_inline eT * memptr()
static void apply(Mat< typename T1::pod_type > &out, const mtOp< typename T1::pod_type, T1, op_var > &in)
For each row or for each column, find the variance. The result is stored in a dense matrix that has e...
arma_aligned uword aux_uword_a
storage of auxiliary data, uword format
Class for storing data required to extract and set the diagonals of a matrix.
arma_inline bool arma_isfinite(eT val)