Ejemplo n.º 1
0
sp_mat VoronoiBasis::get_basis() const{
  umat loc = umat(2,n_points);
  uvec P = col_argmin(m_dist); // Partition assignment
  loc.row(0) = regspace<urowvec>(0,n_points-1).eval();
  loc.row(1) = P.t();
  vec data = ones(n_points);
  sp_mat basis = sp_mat(loc,data);
  return sp_normalise(basis,2,0); // l2 normalize each column
}
Ejemplo n.º 2
0
inline
typename
enable_if2
  <
  ( (is_arma_type<T1>::value == true) && (is_same_type<T2, char>::value == true) && (is_cx<typename T1::elem_type>::value == false) ),
  umat
  >::result
stable_sort_index
  (
  const T1& X,
  const T2* sort_direction
  )
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const unwrap<T1>   tmp(X);
  const Mat<eT>& A = tmp.M;
  
  if(A.is_empty() == true)
    {
    return umat();
    }
  
  arma_debug_check( (A.is_vec() == false), "stable_sort_index(): currently only handles vectors");
  
  const char sig = (sort_direction != NULL) ? sort_direction[0] : char(0);
  
  arma_debug_check( ((sig != 'a') && (sig != 'd')), "stable_sort_index(): unknown sort direction" );
  
  typedef typename umat::elem_type out_elem_type;
  
  umat out(A.n_rows, A.n_cols);
  
  if(sig == 'a')
    {
    sort_index_helper<out_elem_type, eT, 0, 1>(out.memptr(), A.mem, A.n_elem);
    }
  else
    {
    sort_index_helper<out_elem_type, eT, 1, 1>(out.memptr(), A.mem, A.n_elem);
    }
  
  return out;
  }
inline
umat
sort_index
  (
  const Base<typename T1::elem_type,T1>& X,
  const uword sort_type = 0,
  const typename arma_not_cx<typename T1::elem_type>::result* junk = 0
  )
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const unwrap<T1>   tmp(X.get_ref());
  const Mat<eT>& A = tmp.M;
  
  if(A.is_empty() == true)
    {
    return umat();
    }
  
  arma_debug_check( (A.is_vec() == false), "sort_index(): currently only handles vectors");
  
  typedef typename umat::elem_type out_elem_type;
  
  umat out(A.n_rows, A.n_cols);
  
  if(sort_type == 0)
    {
    std::vector< arma_sort_index_packet_ascend<eT,out_elem_type> > packet_vec(A.n_elem);
    
    sort_index_helper(out.memptr(), packet_vec, A.mem);
    }
  else
    {
    std::vector< arma_sort_index_packet_descend<eT,out_elem_type> > packet_vec(A.n_elem);
    
    sort_index_helper(out.memptr(), packet_vec, A.mem);
    }
  
  return out;
  }
Ejemplo n.º 4
0
sp_mat build_convolution_matrix(uint N, const vec & v){
  int n = v.n_elem;
  assert(1 == n %2); // Odd vectors only
  assert(n <= N);
  int n_2 = n / 2;

  umat loc = umat(2,n*N);
  vec data = vec(n*N);
  uint I = 0;
  for(int c = 0; c < N; c++){
    for(int i = 0; i < n; i++){
      int r = (N + c + i - n_2) % N;
      loc(0,I) = r;
      loc(1,I) = c;
      //cout << size(r,c) << endl;
      data(I++) = v(i);
    }
  }
  return sp_mat(loc,data,N,N);
}
inline
umat
stable_sort_index
  (
  const Base<typename T1::elem_type,T1>& X,
  const uword sort_direction = 0,
  const typename arma_not_cx<typename T1::elem_type>::result* junk = 0
  )
  {
  arma_extra_debug_sigprint();
  arma_ignore(junk);
  
  typedef typename T1::elem_type eT;
  
  const unwrap<T1>   tmp(X.get_ref());
  const Mat<eT>& A = tmp.M;
  
  if(A.is_empty() == true)
    {
    return umat();
    }
  
  arma_debug_check( (A.is_vec() == false), "stable_sort_index(): currently only handles vectors");
  
  typedef typename umat::elem_type out_elem_type;
  
  umat out(A.n_rows, A.n_cols);
  
  if(sort_direction == 0)
    {
    sort_index_helper<out_elem_type, eT, 0, 1>(out.memptr(), A.mem, A.n_elem);
    }
  else
    {
    sort_index_helper<out_elem_type, eT, 1, 1>(out.memptr(), A.mem, A.n_elem);
    }
  
  return out;
  }