Classes | Functions

Fn_sort_index

//! More...

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)

Detailed Description

//!


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.

  {
  return A.val < B.val;
  }

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.

  {
  return A.val > B.val;
  }

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().

  {
  arma_extra_debug_sigprint();
  
  const u32 n_elem = packet_vec.size();
  
  for(u32 i=0; i<n_elem; ++i)
    {
    packet_vec[i].val   = in_mem[i];
    packet_vec[i].index = i;
    }
  
  std::sort( packet_vec.begin(), packet_vec.end() );
  
  for(u32 i=0; i<n_elem; ++i)
    {
    out_mem[i] = packet_vec[i].index;
    }
  }

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().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  arma_type_check< is_complex<eT>::value == true>::apply();
  
  const unwrap<T1> tmp(X.get_ref());
  const Mat<eT>& A = tmp.M;
  
  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;
  }