Classes | Functions

Op_sort

//! More...

Classes

class  arma_qsort_helper< eT >
class  arma_qsort_helper< std::complex< T > >
class  op_sort

Functions

template<typename eT >
static void op_sort::direct_sort (eT *X, const u32 N, const u32 sort_type=0)
template<typename T1 >
static void op_sort::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_sort > &in)

Detailed Description

//!


Function Documentation

template<typename eT >
void op_sort::direct_sort ( eT *  X,
const u32  N,
const u32  sort_type = 0 
) [inline, static, inherited]

Definition at line 150 of file op_sort_meat.hpp.

Referenced by apply().

  {
  arma_extra_debug_sigprint();
  
  if(sort_type == 0)
    {
    std::qsort(X, n_elem, sizeof(eT), arma_qsort_helper<eT>::ascend_compare);
    }
  else
    {
    std::qsort(X, n_elem, sizeof(eT), arma_qsort_helper<eT>::descend_compare);
    }
  }

template<typename T1 >
void op_sort::apply ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_sort > &  in 
) [inline, static, inherited]

Definition at line 169 of file op_sort_meat.hpp.

References Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Op< T1, op_type >::aux_u32_b, Mat< eT >::colptr(), Mat< eT >::copy_size(), direct_sort(), Mat< eT >::is_finite(), unwrap< T1 >::M, Op< T1, op_type >::m, Mat< eT >::memptr(), podarray< eT >::memptr(), Mat< eT >::n_cols, Mat< eT >::n_elem, and Mat< eT >::n_rows.

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const unwrap<T1>   tmp(in.m);
  const Mat<eT>& X = tmp.M;
  
  const u32 sort_type = in.aux_u32_a;
  const u32 dim       = in.aux_u32_b;
  
  arma_debug_check( (X.is_finite() == false), "sort(): given object has non-finite elements"     );
  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"      );
  
  
  if(dim == 0)  // column-wise
    {
    arma_extra_debug_print("op_sort::apply(), dim = 0");
    
    out = X;
    
    for(u32 col=0; col<out.n_cols; ++col)
      {
      op_sort::direct_sort( out.colptr(col), out.n_rows, sort_type );
      }
    }
  else
  if(dim == 1)  // row-wise
    {
    if(X.n_rows != 1)  // not a row vector
      {
      arma_extra_debug_print("op_sort::apply(), dim = 1, generic");
      
      //out.set_size(X.n_rows, X.n_cols);
      out.copy_size(X);
      
      podarray<eT> tmp_array(X.n_cols);
      
      for(u32 row=0; row<out.n_rows; ++row)
        {
        
        for(u32 col=0; col<out.n_cols; ++col)
          {
          tmp_array[col] = X.at(row,col);
          }
        
        op_sort::direct_sort( tmp_array.memptr(), out.n_cols, sort_type );
        
        for(u32 col=0; col<out.n_cols; ++col)
          {
          out.at(row,col) = tmp_array[col];
          }
        
        }
      }
    else  // a row vector
      {
      arma_extra_debug_print("op_sort::apply(), dim = 1, vector specific");
      
      out = X;
      op_sort::direct_sort(out.memptr(), out.n_elem, sort_type);
      }
    }
  
  }