inline void op_sort::apply_noalias(Mat<eT>& out, const Mat<eT>& X, const uword sort_type, const uword dim) { arma_extra_debug_sigprint(); if( (X.n_rows * X.n_cols) <= 1 ) { out = X; return; } if(dim == 0) // sort the contents of each column { arma_extra_debug_print("op_sort::apply(), dim = 0"); out = X; const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; for(uword col=0; col < n_cols; ++col) { op_sort::direct_sort( out.colptr(col), n_rows, sort_type ); } } else if(dim == 1) // sort the contents of each row { if(X.n_rows == 1) // 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); } else // not a row vector { arma_extra_debug_print("op_sort::apply(), dim = 1, generic"); out.copy_size(X); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; podarray<eT> tmp_array(n_cols); for(uword row=0; row < n_rows; ++row) { op_sort::copy_row(tmp_array.memptr(), X, row); op_sort::direct_sort( tmp_array.memptr(), n_cols, sort_type ); op_sort::copy_row(out, tmp_array.memptr(), row); } } } }
inline void op_sort::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sort>& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check<T1> tmp(in.m, out); const Mat<eT>& X = tmp.M; const uword sort_type = in.aux_uword_a; const uword dim = in.aux_uword_b; 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" ); arma_debug_check( (X.is_finite() == false), "sort(): given object has non-finite elements" ); if( (X.n_rows * X.n_cols) <= 1 ) { out = X; return; } if(dim == 0) // sort the contents of each column { arma_extra_debug_print("op_sort::apply(), dim = 0"); out = X; const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; for(uword col=0; col < n_cols; ++col) { op_sort::direct_sort( out.colptr(col), n_rows, sort_type ); } } else if(dim == 1) // sort the contents of each row { if(X.n_rows == 1) // 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); } else // not a row vector { arma_extra_debug_print("op_sort::apply(), dim = 1, generic"); out.copy_size(X); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; podarray<eT> tmp_array(n_cols); for(uword row=0; row < n_rows; ++row) { op_sort::copy_row(tmp_array.memptr(), X, row); op_sort::direct_sort( tmp_array.memptr(), n_cols, sort_type ); op_sort::copy_row(out, tmp_array.memptr(), row); } } } }
inline void op_sort::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sort>& in) { 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); } } }