Op_sort

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)

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

00151   {
00152   arma_extra_debug_sigprint();
00153   
00154   if(sort_type == 0)
00155     {
00156     std::qsort(X, n_elem, sizeof(eT), arma_qsort_helper<eT>::ascend_compare);
00157     }
00158   else
00159     {
00160     std::qsort(X, n_elem, sizeof(eT), arma_qsort_helper<eT>::descend_compare);
00161     }
00162   }

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.

00170   {
00171   arma_extra_debug_sigprint();
00172   
00173   typedef typename T1::elem_type eT;
00174   
00175   const unwrap<T1>   tmp(in.m);
00176   const Mat<eT>& X = tmp.M;
00177   
00178   const u32 sort_type = in.aux_u32_a;
00179   const u32 dim       = in.aux_u32_b;
00180   
00181   arma_debug_check( (X.is_finite() == false), "sort(): given object has non-finite elements"     );
00182   arma_debug_check( (sort_type > 1),          "sort(): incorrect usage. sort_type must be 0 or 1");
00183   arma_debug_check( (dim > 1),                "sort(): incorrect usage. dim must be 0 or 1"      );
00184   
00185   
00186   if(dim == 0)  // column-wise
00187     {
00188     arma_extra_debug_print("op_sort::apply(), dim = 0");
00189     
00190     out = X;
00191     
00192     for(u32 col=0; col<out.n_cols; ++col)
00193       {
00194       op_sort::direct_sort( out.colptr(col), out.n_rows, sort_type );
00195       }
00196     }
00197   else
00198   if(dim == 1)  // row-wise
00199     {
00200     if(X.n_rows != 1)  // not a row vector
00201       {
00202       arma_extra_debug_print("op_sort::apply(), dim = 1, generic");
00203       
00204       //out.set_size(X.n_rows, X.n_cols);
00205       out.copy_size(X);
00206       
00207       podarray<eT> tmp_array(X.n_cols);
00208       
00209       for(u32 row=0; row<out.n_rows; ++row)
00210         {
00211         
00212         for(u32 col=0; col<out.n_cols; ++col)
00213           {
00214           tmp_array[col] = X.at(row,col);
00215           }
00216         
00217         op_sort::direct_sort( tmp_array.memptr(), out.n_cols, sort_type );
00218         
00219         for(u32 col=0; col<out.n_cols; ++col)
00220           {
00221           out.at(row,col) = tmp_array[col];
00222           }
00223         
00224         }
00225       }
00226     else  // a row vector
00227       {
00228       arma_extra_debug_print("op_sort::apply(), dim = 1, vector specific");
00229       
00230       out = X;
00231       op_sort::direct_sort(out.memptr(), out.n_elem, sort_type);
00232       }
00233     }
00234   
00235   }