Fn_sort_index

Classes

struct  arma_sort_index_packet_ascend< T1, T2 >
struct  arma_sort_index_packet_descend< T1, T2 >

Functions

template<typename T1 , typename T2 >
bool operator< (const arma_sort_index_packet_ascend< T1, T2 > &A, const arma_sort_index_packet_ascend< T1, T2 > &B)
template<typename T1 , typename T2 >
bool operator< (const arma_sort_index_packet_descend< T1, T2 > &A, const arma_sort_index_packet_descend< T1, T2 > &B)
template<typename umat_elem_type , typename packet_type , typename eT >
void sort_index_helper (umat_elem_type *out_mem, std::vector< packet_type > &packet_vec, const eT *in_mem)
template<typename T1 >
umat sort_index (const Base< typename T1::elem_type, T1 > &X, const u32 sort_type=0)

Function Documentation

template<typename T1 , typename T2 >
bool operator< ( const arma_sort_index_packet_ascend< T1, T2 > &  A,
const arma_sort_index_packet_ascend< T1, T2 > &  B 
) [inline]

Definition at line 44 of file fn_sort_index.hpp.

00045   {
00046   return A.val < B.val;
00047   }

template<typename T1 , typename T2 >
bool operator< ( const arma_sort_index_packet_descend< T1, T2 > &  A,
const arma_sort_index_packet_descend< T1, T2 > &  B 
) [inline]

Definition at line 54 of file fn_sort_index.hpp.

00055   {
00056   return A.val > B.val;
00057   }

template<typename umat_elem_type , typename packet_type , typename eT >
void sort_index_helper ( umat_elem_type *  out_mem,
std::vector< packet_type > &  packet_vec,
const eT *  in_mem 
) [inline]

Definition at line 64 of file fn_sort_index.hpp.

References sort().

Referenced by sort_index().

00065   {
00066   arma_extra_debug_sigprint();
00067   
00068   const u32 n_elem = packet_vec.size();
00069   
00070   for(u32 i=0; i<n_elem; ++i)
00071     {
00072     packet_vec[i].val   = in_mem[i];
00073     packet_vec[i].index = i;
00074     }
00075   
00076   std::sort( packet_vec.begin(), packet_vec.end() );
00077   
00078   for(u32 i=0; i<n_elem; ++i)
00079     {
00080     out_mem[i] = packet_vec[i].index;
00081     }
00082   }

template<typename T1 >
umat sort_index ( const Base< typename T1::elem_type, T1 > &  X,
const u32  sort_type = 0 
) [inline]

Definition at line 89 of file fn_sort_index.hpp.

References Base< elem_type, derived >::get_ref(), Mat< eT >::memptr(), and sort_index_helper().

00090   {
00091   arma_extra_debug_sigprint();
00092   
00093   typedef typename T1::elem_type eT;
00094   
00095   arma_type_check< is_complex<eT>::value == true>::apply();
00096   
00097   const unwrap<T1> tmp(X.get_ref());
00098   const Mat<eT>& A = tmp.M;
00099   
00100   arma_debug_check( (A.is_vec() == false), "sort_index(): currently only handles vectors");
00101   
00102   typedef typename umat::elem_type out_elem_type;
00103   
00104   umat out(A.n_rows, A.n_cols);
00105   
00106   if(sort_type == 0)
00107     {
00108     std::vector< arma_sort_index_packet_ascend<eT,out_elem_type> > packet_vec(A.n_elem);
00109     
00110     sort_index_helper(out.memptr(), packet_vec, A.mem);
00111     }
00112   else
00113     {
00114     std::vector< arma_sort_index_packet_descend<eT,out_elem_type> > packet_vec(A.n_elem);
00115     
00116     sort_index_helper(out.memptr(), packet_vec, A.mem);
00117     }
00118   
00119   return out;
00120   }