コード例 #1
0
ファイル: fn_accu.hpp プロジェクト: 2003pro/armadillo
arma_hot
arma_pure
arma_warn_unused
inline
eT
accu(const subview<eT>& X)
  {
  arma_extra_debug_sigprint();  
  
  const uword X_n_rows = X.n_rows;
  const uword X_n_cols = X.n_cols;
  
  eT val = eT(0);
  
  if(X_n_rows == 1)
    {
    const Mat<eT>& A = X.m;
    
    const uword start_row = X.aux_row1;
    const uword start_col = X.aux_col1;
    
    const uword end_col_p1 = start_col + X_n_cols;
    
    uword i,j;
    for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2)
      {
      val += A.at(start_row, i);
      val += A.at(start_row, j);
      }
    
    if(i < end_col_p1)
      {
      val += A.at(start_row, i);
      }
    }
  else
  if(X_n_cols == 1)
    {
    val = arrayops::accumulate( X.colptr(0), X_n_rows );
    }
  else
    {
    for(uword col=0; col < X_n_cols; ++col)
      {
      val += arrayops::accumulate( X.colptr(col), X_n_rows );
      }
    }
  
  return val;
  }
コード例 #2
0
inline
void
Gen<T1, gen_type>::apply(subview<typename T1::elem_type>& out) const
  {
  arma_extra_debug_sigprint();
  
  // NOTE: we're assuming that the submatrix has the same dimensions as the Gen object
  // this is checked by subview::operator=()
  
       if(is_same_type<gen_type, gen_eye  >::yes) { out.eye();   }
  else if(is_same_type<gen_type, gen_ones >::yes) { out.ones();  }
  else if(is_same_type<gen_type, gen_zeros>::yes) { out.zeros(); }
  else if(is_same_type<gen_type, gen_randu>::yes) { out.randu(); }
  else if(is_same_type<gen_type, gen_randn>::yes) { out.randn(); }
  }
コード例 #3
0
inline
void
op_vectorise_col::apply_subview(Mat<eT>& out, const subview<eT>& sv)
  {
  arma_extra_debug_sigprint();
  
  const bool is_alias = (&out == &(sv.m));
  
  if(is_alias == false)
    {
    const uword sv_n_rows = sv.n_rows;
    const uword sv_n_cols = sv.n_cols;
    
    out.set_size(sv.n_elem, 1);
    
    eT* out_mem = out.memptr();
    
    for(uword col=0; col < sv_n_cols; ++col)
      {
      arrayops::copy(out_mem, sv.colptr(col), sv_n_rows);
      
      out_mem += sv_n_rows;
      }
    }
  else
    {
    Mat<eT> tmp;
    
    op_vectorise_col::apply_subview(tmp, sv);
    
    out.steal_mem(tmp);
    }
  }
コード例 #4
0
ファイル: op_min_meat.hpp プロジェクト: JD26/ICE
inline
eT
op_min::min(const subview<eT>& X)
  {
  arma_extra_debug_sigprint();
  
  if(X.n_elem == 0)
    {
    arma_debug_check(true, "min(): object has no elements");
    
    return Datum<eT>::nan;
    }
    
  const uword X_n_rows = X.n_rows;
  const uword X_n_cols = X.n_cols;
  
  eT min_val = priv::most_pos<eT>();
  
  if(X_n_rows == 1)
    {
    const Mat<eT>& A = X.m;
    
    const uword start_row = X.aux_row1;
    const uword start_col = X.aux_col1;
    
    const uword end_col_p1 = start_col + X_n_cols;
  
    uword i,j;
    for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2)
      {
      const eT tmp_i = A.at(start_row, i);
      const eT tmp_j = A.at(start_row, j);
      
      if(tmp_i < min_val) { min_val = tmp_i; }
      if(tmp_j < min_val) { min_val = tmp_j; }
      }
    
    if(i < end_col_p1)
      {
      const eT tmp_i = A.at(start_row, i);
      
      if(tmp_i < min_val) { min_val = tmp_i; }
      }
    }
  else
    {
    for(uword col=0; col < X_n_cols; ++col)
      {
      min_val = (std::min)(min_val, op_min::direct_min(X.colptr(col), X_n_rows));
      }
    }
  
  return min_val;
  }
コード例 #5
0
inline
eT
op_mean::mean_all(const subview<eT>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename get_pod_type<eT>::result T;
  
  const uword X_n_rows = X.n_rows;
  const uword X_n_cols = X.n_cols;
  const uword X_n_elem = X.n_elem;
  
  if(X_n_elem == 0)
    {
    arma_debug_check(true, "mean(): object has no elements");
    
    return Datum<eT>::nan;
    }
  
  eT val = eT(0);
  
  if(X_n_rows == 1)
    {
    const Mat<eT>& A = X.m;
    
    const uword start_row = X.aux_row1;
    const uword start_col = X.aux_col1;
    
    const uword end_col_p1 = start_col + X_n_cols;
    
    uword i,j;
    for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2)
      {
      val += A.at(start_row, i);
      val += A.at(start_row, j);
      }
    
    if(i < end_col_p1)
      {
      val += A.at(start_row, i);
      }
    }
  else
    {
    for(uword col=0; col < X_n_cols; ++col)
      {
      val += arrayops::accumulate(X.colptr(col), X_n_rows);
      }
    }
  
  const eT result = val / T(X_n_elem);
  
  return arma_isfinite(result) ? result : op_mean::mean_all_robust(X);
  }
コード例 #6
0
inline
eT
op_max::max(const subview<eT>& X)
  {
  arma_extra_debug_sigprint();
  
  arma_debug_check( (X.n_elem == 0), "max(): given object has no elements" );

  const uword X_n_rows = X.n_rows;
  const uword X_n_cols = X.n_cols;
  
  eT max_val = priv::most_neg<eT>();
  
  if(X_n_rows == 1)
    {
    const Mat<eT>& A = X.m;
    
    const uword start_row = X.aux_row1;
    const uword start_col = X.aux_col1;
    
    const uword end_col_p1 = start_col + X_n_cols;
  
    uword i,j;
    for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2)
      {
      const eT tmp_i = A.at(start_row, i);
      const eT tmp_j = A.at(start_row, j);
      
      if(tmp_i > max_val) { max_val = tmp_i; }
      if(tmp_j > max_val) { max_val = tmp_j; }
      }
    
    if(i < end_col_p1)
      {
      const eT tmp_i = A.at(start_row, i);
      
      if(tmp_i > max_val) { max_val = tmp_i; }
      }
    }
  else
    {
    for(uword col=0; col < X_n_cols; ++col)
      {
      eT tmp_val = op_max::direct_max(X.colptr(col), X_n_rows);
      
      if(tmp_val > max_val) { max_val = tmp_val; }
      }
    }
  
  return max_val;
  }
コード例 #7
0
ファイル: op_prod_meat.hpp プロジェクト: daceville/atom_imsrg
inline
eT
op_prod::prod(const subview<eT>& X)
  {
  arma_extra_debug_sigprint();
  
  eT val = eT(1);
  
  const uword X_n_rows = X.n_rows;
  const uword X_n_cols = X.n_cols;
  
  if(X_n_rows == 1)
    {
    const Mat<eT>& A = X.m;
  
    const uword start_row = X.aux_row1;
    const uword start_col = X.aux_col1;
    
    const uword end_col_p1 = start_col + X_n_cols;
    
    uword i,j;
    for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2)
      {
      val *= A.at(start_row, i);
      val *= A.at(start_row, j);
      }
    
    if(i < end_col_p1)
      {
      val *= A.at(start_row, i);
      }
    }
  else
    {
    for(uword col=0; col < X_n_cols; ++col)
      {
      val *= arrayops::product( X.colptr(col), X_n_rows );
      }
    }
  
  return val;
  }
コード例 #8
0
arma_pure
arma_warn_unused
inline
eT
accu(const subview<eT>& S)
  {
  arma_extra_debug_sigprint();  
  
  const u32 S_n_rows = S.n_rows;
  const u32 S_n_cols = S.n_cols;
  
  eT val = eT(0);
  
  for(u32 col=0; col<S_n_cols; ++col)
    {
    val += arrayops::accumulate( S.colptr(col), S_n_rows );
    }
  
  return val;
  }