Op_min

Classes

class  op_min
 Class for finding minimum values in a matrix. More...

Functions

template<typename eT >
static eT op_min::direct_min (const eT *const X, const u32 N)
 Find the minimum value in an array.
template<typename eT >
static eT op_min::direct_min (const subview< eT > &X)
 find the minimum value in a subview
template<typename eT >
static eT op_min::direct_min (const diagview< eT > &X)
 find the minimum value in a diagview
template<typename T1 >
static void op_min::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_min > &in)
 For each row or for each column, find the minimum value. The result is stored in a dense matrix that has either one column or one row. The dimension, for which the minima are found, is set via the min() function.
template<typename T >
static std::complex< T > op_min::direct_min (const std::complex< T > *const X, const u32 n_elem)
 Find the minimum value in an array (version for complex numbers).
template<typename T >
static std::complex< T > op_min::direct_min (const subview< std::complex< T > > &X)
 Find the minimum value in a subview (version for complex numbers).
template<typename T >
static std::complex< T > op_min::direct_min (const diagview< std::complex< T > > &X)
 Find the minimum value in a diagview (version for complex numbers).
template<typename T , typename T1 >
static void op_min::apply (Mat< std::complex< T > > &out, const Op< T1, op_min > &in)
 Implementation for complex numbers.

Function Documentation

template<typename eT >
eT op_min::direct_min ( const eT *const   X,
const u32  N 
) [inline, static, inherited]

Find the minimum value in an array.

Definition at line 25 of file op_min_meat.hpp.

Referenced by apply(), and min().

00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   eT min_val = X[0];
00030   
00031   for(u32 i=1; i<n_elem; ++i)
00032     {
00033     const eT tmp_val = X[i];
00034     
00035     if(tmp_val < min_val)
00036       {
00037       min_val = tmp_val;
00038       }
00039     }
00040   
00041   return min_val;
00042   }

template<typename eT >
eT op_min::direct_min ( const subview< eT > &  X  )  [inline, static, inherited]

find the minimum value in a subview

Definition at line 50 of file op_min_meat.hpp.

References subview< eT >::n_elem.

00051   {
00052   arma_extra_debug_sigprint();
00053   
00054   eT min_val = X[0];
00055   
00056   for(u32 i=1; i<X.n_elem; ++i)
00057     {
00058     eT tmp_val = X[i];
00059     
00060     if(tmp_val < min_val)
00061       {
00062       min_val = tmp_val;
00063       }
00064     }
00065   
00066   return min_val;
00067   }

template<typename eT >
eT op_min::direct_min ( const diagview< eT > &  X  )  [inline, static, inherited]

find the minimum value in a diagview

Definition at line 75 of file op_min_meat.hpp.

References diagview< eT >::n_elem.

00076   {
00077   arma_extra_debug_sigprint();
00078   
00079   eT min_val = X[0];
00080   
00081   for(u32 i=1; i<X.n_elem; ++i)
00082     {
00083     eT tmp_val = X[i];
00084     
00085     if(tmp_val < min_val)
00086       {
00087       min_val = tmp_val;
00088       }
00089     }
00090   
00091   return min_val;
00092   }

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

For each row or for each column, find the minimum value. The result is stored in a dense matrix that has either one column or one row. The dimension, for which the minima are found, is set via the min() function.

Definition at line 101 of file op_min_meat.hpp.

References Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), direct_min(), unwrap_check< T1 >::M, Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().

00102   {
00103   arma_extra_debug_sigprint();
00104   
00105   typedef typename T1::elem_type eT;
00106   
00107   const unwrap_check<T1> tmp(in.m, out);
00108   const Mat<eT>& X = tmp.M;
00109   
00110   arma_debug_check( (X.n_elem == 0), "min(): given matrix has no elements" );
00111   
00112   const u32 dim = in.aux_u32_a;
00113   arma_debug_check( (dim > 1), "min(): incorrect usage. dim must be 0 or 1");
00114   
00115   
00116   if(dim == 0)  // column-wise min
00117     {
00118     arma_extra_debug_print("op_min::apply(), dim = 0");
00119     
00120     out.set_size(1, X.n_cols);
00121     
00122     for(u32 col=0; col<X.n_cols; ++col)
00123       {
00124       out[col] = op_min::direct_min( X.colptr(col), X.n_rows );
00125       }
00126     }
00127   else
00128   if(dim == 1)  // row-wise min
00129     {
00130     arma_extra_debug_print("op_min::apply(), dim = 1");
00131     
00132     out.set_size(X.n_rows, 1);
00133     
00134     for(u32 row=0; row<X.n_rows; ++row)
00135       {
00136       eT min_val = X.at(row,0);
00137       
00138       for(u32 col=1; col<X.n_cols; ++col)
00139         {
00140         const eT tmp_val = X.at(row,col);
00141         
00142         if(tmp_val < min_val)
00143           {
00144           min_val = tmp_val;
00145           }
00146         }
00147       
00148       out[row] = min_val;
00149       
00150       }
00151     
00152     }
00153   
00154   }

template<typename T >
std::complex< T > op_min::direct_min ( const std::complex< T > *const   X,
const u32  n_elem 
) [inline, static, inherited]

Find the minimum value in an array (version for complex numbers).

Definition at line 162 of file op_min_meat.hpp.

References abs().

00163   {
00164   arma_extra_debug_sigprint();
00165   
00166   u32 index   = 0;
00167   T   min_val = std::abs(X[index]);
00168   
00169   for(u32 i=1; i<n_elem; ++i)
00170     {
00171     const T tmp_val = std::abs(X[i]);
00172     
00173     if(tmp_val < min_val)
00174       {
00175       min_val = tmp_val;
00176       index   = i;
00177       }
00178     }
00179   
00180   return X[index];
00181   }

template<typename T >
std::complex< T > op_min::direct_min ( const subview< std::complex< T > > &  X  )  [inline, static, inherited]

Find the minimum value in a subview (version for complex numbers).

Definition at line 189 of file op_min_meat.hpp.

References abs().

00190   {
00191   arma_extra_debug_sigprint();
00192   
00193   u32 index   = 0;
00194   T   min_val = std::abs(X[index]);
00195   
00196   for(u32 i=1; i<X.n_elem; ++i)
00197     {
00198     const T tmp_val = std::abs(X[i]);
00199     
00200     if(tmp_val < min_val)
00201       {
00202       min_val = tmp_val;
00203       index   = i;
00204       }
00205     }
00206   
00207   return X[index];
00208   }

template<typename T >
std::complex< T > op_min::direct_min ( const diagview< std::complex< T > > &  X  )  [inline, static, inherited]

Find the minimum value in a diagview (version for complex numbers).

Definition at line 216 of file op_min_meat.hpp.

References abs().

00217   {
00218   arma_extra_debug_sigprint();
00219   
00220   u32 index   = 0;
00221   T   min_val = std::abs(X[index]);
00222   
00223   for(u32 i=1; i<X.n_elem; ++i)
00224     {
00225     const T tmp_val = std::abs(X[i]);
00226     
00227     if(tmp_val < min_val)
00228       {
00229       min_val = tmp_val;
00230       index   = i;
00231       }
00232     }
00233   
00234   return X[index];
00235   }

template<typename T , typename T1 >
void op_min::apply ( Mat< std::complex< T > > &  out,
const Op< T1, op_min > &  in 
) [inline, static, inherited]

Implementation for complex numbers.

Definition at line 241 of file op_min_meat.hpp.

References abs(), Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), direct_min(), unwrap_check< T1 >::M, Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, and Mat< eT >::n_rows.

00242   {
00243   arma_extra_debug_sigprint();
00244   
00245   typedef typename std::complex<T> eT;
00246   isnt_same_type<eT, typename T1::elem_type>::check();
00247   
00248   const unwrap_check<T1> tmp(in.m, out);
00249   const Mat<eT>& X = tmp.M;
00250   
00251   arma_debug_check( (X.n_elem == 0), "min(): given matrix has no elements" );
00252   
00253   const u32 dim = in.aux_u32_a;
00254   arma_debug_check( (dim > 1), "min(): incorrect usage. dim must be 0 or 1");
00255   
00256   
00257   if(dim == 0)  // column-wise min
00258     {
00259     arma_extra_debug_print("op_min::apply(), dim = 0");
00260     
00261     out.set_size(1, X.n_cols);
00262     
00263     for(u32 col=0; col<X.n_cols; ++col)
00264       {
00265       out[col] = op_min::direct_min( X.colptr(col), X.n_rows );
00266       }
00267     }
00268   else
00269   if(dim == 1)  // row-wise min
00270     {
00271     arma_extra_debug_print("op_min::apply(), dim = 1");
00272     
00273     out.set_size(X.n_rows, 1);
00274     
00275     for(u32 row=0; row<X.n_rows; ++row)
00276       {
00277       u32 index   = 0;
00278       T   min_val = std::abs(X.at(row,index));
00279       
00280       for(u32 col=1; col<X.n_cols; ++col)
00281         {
00282         const T tmp_val = std::abs(X.at(row,col));
00283         
00284         if(tmp_val < min_val)
00285           {
00286           min_val = tmp_val;
00287           index   = col;
00288           }
00289         }
00290       
00291       out[row] = X.at(row,index);
00292       }
00293     
00294     }
00295   
00296   }