Esempio n. 1
0
inline
void
op_repelem::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_repelem>& in)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const uword copies_per_row = in.aux_uword_a;
  const uword copies_per_col = in.aux_uword_b;
  
  const quasi_unwrap<T1> U(in.m);
  
  if(U.is_alias(out))
    {
    Mat<eT> tmp;
    
    op_repelem::apply_noalias(tmp, U.M, copies_per_row, copies_per_col);
    
    out.steal_mem(tmp);
    }
  else
    {
    op_repelem::apply_noalias(out, U.M, copies_per_row, copies_per_col);
    }
  }
Esempio n. 2
0
inline
void
op_prod::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_prod>& in)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const uword dim = in.aux_uword_a;
  
  arma_debug_check( (dim > 1), "prod(): parameter 'dim' must be 0 or 1" );
  
  const quasi_unwrap<T1> U(in.m);
  
  if(U.is_alias(out))
    {
    Mat<eT> tmp;
    
    op_prod::apply_noalias(tmp, U.M, dim);
    
    out.steal_mem(tmp);
    }
  else
    {
    op_prod::apply_noalias(out, U.M, dim);
    }
  }
Esempio n. 3
0
inline
void
op_sort::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sort>& in)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const quasi_unwrap<T1> U(in.m);
  
  const Mat<eT>& X = U.M;
  
  const uword sort_type = in.aux_uword_a;
  const uword dim       = in.aux_uword_b;
  
  arma_debug_check( (sort_type > 1),          "sort(): incorrect usage. sort_type must be 0 or 1");
  arma_debug_check( (dim > 1),                "sort(): incorrect usage. dim must be 0 or 1"      );
  arma_debug_check( (X.is_finite() == false), "sort(): given object has non-finite elements"     );
  
  if(U.is_alias(out))
    {
    Mat<eT> out2;
    
    op_sort::apply_noalias(out2, X, sort_type, dim);
    
    out.steal_mem(out2);
    }
  else
    {
    apply_noalias(out, X, sort_type, dim);
    }
  }
Esempio n. 4
0
inline
void
op_cumprod_vec::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cumprod_vec>& in)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const quasi_unwrap<T1> U(in.m);
  
  const uword dim = (T1::is_xvec) ? uword(U.M.is_rowvec() ? 1 : 0) : uword((T1::is_row) ? 1 : 0);
  
  if(U.is_alias(out))
    {
    Mat<eT> tmp;
    
    op_cumprod::apply_noalias(tmp, U.M, dim);
    
    out.steal_mem(tmp);
    }
  else
    {
    op_cumprod::apply_noalias(out, U.M, dim);
    }
  }
Esempio n. 5
0
inline
void
glue_hist::apply(Mat<uword>& out, const mtGlue<uword,T1,T2,glue_hist>& expr)
  {
  arma_extra_debug_sigprint();
  
  const uword dim = expr.aux_uword;
  
  arma_debug_check( (dim > 1), "hist(): parameter 'dim' must be 0 or 1" );
  
  const quasi_unwrap<T1> UA(expr.A);
  const quasi_unwrap<T2> UB(expr.B);
  
  if(UA.is_alias(out) || UB.is_alias(out))
    {
    Mat<uword> tmp;
    
    glue_hist::apply_noalias(tmp, UA.M, UB.M, dim);
    
    out.steal_mem(tmp);
    }
  else
    {
    glue_hist::apply_noalias(out, UA.M, UB.M, dim);
    }
  }
Esempio n. 6
0
inline
void
op_sort_default::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sort_default>& in)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const quasi_unwrap<T1> U(in.m);
  
  const Mat<eT>& X = U.M;
  
  const uword sort_type = in.aux_uword_a;
  const uword dim       = (T1::is_row) ? 1 : 0;
  
  if(U.is_alias(out))
    {
    Mat<eT> tmp;
    
    op_sort::apply_noalias(tmp, X, sort_type, dim);
    
    out.steal_mem(tmp);
    }
  else
    {
    op_sort::apply_noalias(out, X, sort_type, dim);
    }
  }
Esempio n. 7
0
inline
void
glue_histc_default::apply(Mat<uword>& C, const mtGlue<uword,T1,T2,glue_histc_default>& expr)
  {
  arma_extra_debug_sigprint();
  
  const quasi_unwrap<T1> UA(expr.A);
  const quasi_unwrap<T2> UB(expr.B);
  
  //const uword dim = ( (T1::is_row) || ((UA.M.vec_state == 0) && (UA.M.n_elem <= 1) && (C.vec_state == 2)) ) ? 1 : 0;
  const uword dim = (T1::is_row) ? 1 : 0;
  
  if(UA.is_alias(C) || UB.is_alias(C))
    {
    Mat<uword> tmp;
    
    glue_histc::apply_noalias(tmp, UA.M, UB.M, dim);
    
    C.steal_mem(tmp);
    }
  else
    {
    glue_histc::apply_noalias(C, UA.M, UB.M, dim);
    }
  }
Esempio n. 8
0
inline
bool
glue_polyfit::apply_direct(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type,T1>& X_expr, const Base<typename T1::elem_type, T2>& Y_expr, const uword N)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const quasi_unwrap<T1> UX(X_expr.get_ref());
  const quasi_unwrap<T2> UY(Y_expr.get_ref());
  
  const Mat<eT>& X = UX.M;
  const Mat<eT>& Y = UY.M;
  
  arma_debug_check
    (
    ( ((X.is_vec() == false) && (X.is_empty() == false)) || ((Y.is_vec() == false) && (Y.is_empty() == false)) ),
    "polyfit(): given object is not a vector"
    );
  
  arma_debug_check( (X.n_elem != Y.n_elem), "polyfit(): given vectors must have the same number of elements" );
  
  if(X.n_elem == 0)
    {
    out.reset();
    return true;
    }
  
  arma_debug_check( (N >= X.n_elem), "polyfit(): N must be less than the number of elements in X" );
  
  const Col<eT> X_as_colvec( const_cast<eT*>(X.memptr()), X.n_elem, false, false);
  const Col<eT> Y_as_colvec( const_cast<eT*>(Y.memptr()), Y.n_elem, false, false);
  
  bool status = false;
  
  if(UX.is_alias(out) || UY.is_alias(out))
    {
    Mat<eT> tmp;
    status = glue_polyfit::apply_noalias(tmp, X_as_colvec, Y_as_colvec, N);
    out.steal_mem(tmp);
    }
  else
    {
    status = glue_polyfit::apply_noalias(out, X_as_colvec, Y_as_colvec, N);
    }
  
  return status;
  }
Esempio n. 9
0
inline
typename
enable_if2
  <
  is_real<typename T1::elem_type>::value,
  void
  >::result
interp1
  (
  const Base<typename T1::elem_type, T1>& X,
  const Base<typename T1::elem_type, T2>& Y,
  const Base<typename T1::elem_type, T3>& XI,
         Mat<typename T1::elem_type>&     YI,
  const char*                             method     = "linear",
  const typename T1::elem_type            extrap_val = Datum<typename T1::elem_type>::nan
  )
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  uword sig = 0;
  
  if(method    != NULL   )
  if(method[0] != char(0))
  if(method[1] != char(0))
    {
    const char c1 = method[0];
    const char c2 = method[1];
    
         if(c1 == 'n')  { sig = 10; }  // nearest neighbour
    else if(c1 == 'l')  { sig = 20; }  // linear
    else
      {
      if( (c1 == '*') && (c2 == 'n') )  { sig = 11; }  // nearest neighour, assume monotonic increase in X and XI
      if( (c1 == '*') && (c2 == 'l') )  { sig = 21; }  // linear, assume monotonic increase in X and XI
      }
    }
  
  arma_debug_check( (sig == 0), "interp1(): unsupported interpolation type" ); 
  
  const quasi_unwrap<T1>  X_tmp( X.get_ref());
  const quasi_unwrap<T2>  Y_tmp( Y.get_ref());
  const quasi_unwrap<T3> XI_tmp(XI.get_ref());
  
  if( X_tmp.is_alias(YI) || Y_tmp.is_alias(YI) || XI_tmp.is_alias(YI) )
    {
    Mat<eT> tmp;
    
    interp1_helper(X_tmp.M, Y_tmp.M, XI_tmp.M, tmp, sig, extrap_val);
    
    YI.steal_mem(tmp);
    }
  else
    {
    interp1_helper(X_tmp.M, Y_tmp.M, XI_tmp.M, YI, sig, extrap_val);
    }
  }
Esempio n. 10
0
inline
void
glue_hist_default::apply(Mat<uword>& out, const mtGlue<uword,T1,T2,glue_hist_default>& expr)
  {
  arma_extra_debug_sigprint();
  
  const quasi_unwrap<T1> UA(expr.A);
  const quasi_unwrap<T2> UB(expr.B);
  
  const uword dim = (T1::is_xvec) ? uword(UA.M.is_rowvec() ? 1 : 0) : uword((T1::is_row) ? 1 : 0);
  
  if(UA.is_alias(out) || UB.is_alias(out))
    {
    Mat<uword> tmp;
    
    glue_hist::apply_noalias(tmp, UA.M, UB.M, dim);
    
    out.steal_mem(tmp);
    }
  else
    {
    glue_hist::apply_noalias(out, UA.M, UB.M, dim);
    }
  }