Functions

Fn_accu

//! More...

Functions

template<typename T1 >
arma_hot T1::elem_type accu_unwrap (const Base< typename T1::elem_type, T1 > &X)
template<typename T1 >
arma_hot T1::elem_type accu_proxy (const Base< typename T1::elem_type, T1 > &X)
template<typename T1 >
arma_inline arma_warn_unused
T1::elem_type 
accu (const Base< typename T1::elem_type, T1 > &X)
 accumulate the elements of a matrix
template<typename T1 >
arma_inline arma_warn_unused u32 accu (const mtOp< u32, T1, op_rel_noteq > &X)
 explicit handling of Hamming norm (also known as zero norm)
template<typename T1 >
arma_hot arma_warn_unused
T1::elem_type 
accu (const BaseCube< typename T1::elem_type, T1 > &X)
 accumulate the elements of a cube
template<typename eT >
arma_pure arma_warn_unused eT accu (const diagview< eT > &X)
 accumulate the elements of a diagview
template<typename eT >
arma_pure arma_warn_unused eT accu (const subview< eT > &S)
 accumulate the elements of a subview (submatrix)
template<typename eT >
arma_pure arma_warn_unused eT accu (const subview_row< eT > &S)
 accumulate the elements of a subview_row
template<typename eT >
arma_pure arma_warn_unused eT accu (const subview_col< eT > &S)
 accumulate the elements of a subview_col

Detailed Description

//!


Function Documentation

template<typename T1 >
arma_hot T1::elem_type accu_unwrap ( const Base< typename T1::elem_type, T1 > &  X  )  [inline]

Definition at line 26 of file fn_accu.hpp.

References Base< elem_type, derived >::get_ref().

Referenced by accu().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const unwrap<T1>   tmp(X.get_ref());
  const Mat<eT>& A = tmp.M;
  
  const eT* A_mem = A.memptr();
  const u32 N     = A.n_elem;
  
  eT val1 = eT(0);
  eT val2 = eT(0);
  
  u32 i,j;
  
  for(i=0, j=1; j<N; i+=2, j+=2)
    {
    val1 += A_mem[i];
    val2 += A_mem[j];
    }
  
  if(i < N)
    {
    val1 += A_mem[i];
    }
  
  return val1 + val2;
  }

template<typename T1 >
arma_hot T1::elem_type accu_proxy ( const Base< typename T1::elem_type, T1 > &  X  )  [inline]

Definition at line 63 of file fn_accu.hpp.

References Base< elem_type, derived >::get_ref().

Referenced by accu().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const Proxy<T1> A(X.get_ref());
  
  const u32 N = A.n_elem;
  
  eT val = eT(0);
  
  for(u32 i=0; i<N; ++i)
    {
    val += A[i];
    }
  
  return val;
  }

template<typename T1 >
arma_inline arma_warn_unused T1::elem_type accu ( const Base< typename T1::elem_type, T1 > &  X  ) 

accumulate the elements of a matrix

Definition at line 90 of file fn_accu.hpp.

References accu_proxy(), and accu_unwrap().

Referenced by sum().

  {
  arma_extra_debug_sigprint();
  
  return (is_Mat<T1>::value == true) ? accu_unwrap(X) : accu_proxy(X);
  }

template<typename T1 >
arma_inline arma_warn_unused u32 accu ( const mtOp< u32, T1, op_rel_noteq > &  X  ) 

explicit handling of Hamming norm (also known as zero norm)

Definition at line 104 of file fn_accu.hpp.

References mtOp< out_eT, T1, op_type >::aux, and mtOp< out_eT, T1, op_type >::m.

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const Proxy<T1> A(X.m);
  
  const u32 n_elem = A.n_elem;
  const eT  val    = X.aux;
  
  u32 n_nonzero = 0;
  for(u32 i=0; i<n_elem; ++i)
    {
    if(A[i] != val)
      {
      ++n_nonzero;
      }
    }
  
  return n_nonzero;
  }

template<typename T1 >
arma_hot arma_warn_unused T1::elem_type accu ( const BaseCube< typename T1::elem_type, T1 > &  X  )  [inline]

accumulate the elements of a cube

Definition at line 135 of file fn_accu.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const ProxyCube<T1> A(X.get_ref());
  
  const u32 n_elem = A.n_elem;
  
  eT val = eT(0);
  
  for(u32 i=0; i<n_elem; ++i)
    {
    val += A[i];
    }
  
  return val;
  }

template<typename eT >
arma_pure arma_warn_unused eT accu ( const diagview< eT > &  X  )  [inline]

accumulate the elements of a diagview

Definition at line 163 of file fn_accu.hpp.

References diagview< eT >::n_elem.

  {
  arma_extra_debug_sigprint();  
  
  const u32 n_elem = X.n_elem;
  eT val = eT(0);
  
  for(u32 i=0; i<n_elem; ++i)
    {
    val += X[i];
    }
  
  return val;
  }

template<typename eT >
arma_pure arma_warn_unused eT accu ( const subview< eT > &  S  )  [inline]

accumulate the elements of a subview (submatrix)

Definition at line 186 of file fn_accu.hpp.

References subview< eT >::colptr(), subview< eT >::n_cols, and subview< eT >::n_rows.

  {
  arma_extra_debug_sigprint();  
  
  eT val = eT(0);
  
  for(u32 col=0; col<S.n_cols; ++col)
    {
    const eT* coldata = S.colptr(col);
    
    for(u32 row=0; row<S.n_rows; ++row)
      {
      val += coldata[row];
      }
    
    }
  
  return val;
  }

template<typename eT >
arma_pure arma_warn_unused eT accu ( const subview_row< eT > &  S  )  [inline]

accumulate the elements of a subview_row

Definition at line 214 of file fn_accu.hpp.

References Mat< eT >::at(), subview< eT >::aux_col1, subview< eT >::aux_col2, subview< eT >::aux_row1, and subview< eT >::m.

  {
  arma_extra_debug_sigprint();  
  
  const Mat<eT>& X = S.m;
  
  const u32 row       = S.aux_row1;
  const u32 start_col = S.aux_col1;
  const u32 end_col   = S.aux_col2;
  
  eT val = eT(0);
  
  for(u32 col=start_col; col<=end_col; ++col)
    {
    val += X.at(row,col);
    }
  
  return val;
  }

template<typename eT >
arma_pure arma_warn_unused eT accu ( const subview_col< eT > &  S  )  [inline]

accumulate the elements of a subview_col

Definition at line 242 of file fn_accu.hpp.

References subview< eT >::colptr(), and subview< eT >::n_rows.

  {
  arma_extra_debug_sigprint();
  
  const eT* S_colptr = S.colptr(0);
  const u32 n_rows   = S.n_rows;
  
  eT val = eT(0);
  
  for(u32 row=0; row<n_rows; ++row)
    {
    val += S_colptr[row];
    }
  
  return val;
  }