fn_min.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup fn_min
00018 //! @{
00019 
00020 //! \brief
00021 //! Delayed 'minimum values' operation.
00022 //! The dimension, along which the minima are found, is set via 'dim'.
00023 //! For dim = 0, the maximum value of each column is found (i.e. searches by traversing across rows).
00024 //! For dim = 1, the maximum value of each row is found (i.e. searches by traversing across columns).
00025 //! The default is dim = 0.
00026 //! NOTE: This function works differently than in Matlab/Octave.
00027 
00028 template<typename T1>
00029 arma_inline
00030 const Op<T1, op_min>
00031 min(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
00032   {
00033   arma_extra_debug_sigprint();
00034   
00035   return Op<T1, op_min>(X.get_ref(), dim, 0);
00036   }
00037 
00038 
00039 //! Immediate 'find the minimum value in a row vector' operation
00040 template<typename eT>
00041 inline
00042 arma_warn_unused
00043 eT
00044 min(const Row<eT>& A)
00045   {
00046   arma_extra_debug_sigprint();
00047   
00048   arma_debug_check( (A.n_elem == 0), "min(): given vector has no elements" );
00049   
00050   return op_min::direct_min(A.mem, A.n_elem);
00051   }
00052 
00053 
00054 
00055 //! Immediate 'find the minimum value in a column vector'
00056 template<typename eT>
00057 inline
00058 arma_warn_unused
00059 eT
00060 min(const Col<eT>& A)
00061   {
00062   arma_extra_debug_sigprint();
00063   
00064   arma_debug_check( (A.n_elem == 0), "min(): given vector has no elements" );
00065   
00066   return op_min::direct_min(A.mem, A.n_elem);
00067   }
00068 
00069 
00070 
00071 //! \brief
00072 //! Immediate 'find minimum value' operation,
00073 //! invoked, for example, by: min(min(A))
00074 template<typename T1>
00075 inline
00076 arma_warn_unused
00077 typename T1::elem_type
00078 min(const Op<T1, op_min>& in)
00079   {
00080   arma_extra_debug_sigprint();
00081   arma_extra_debug_print("min(): two consecutive min() calls detected");
00082   
00083   typedef typename T1::elem_type eT;
00084   
00085   const unwrap<T1> tmp1(in.m);
00086   const Mat<eT>& X = tmp1.M;
00087   
00088   arma_debug_check( (X.n_elem == 0), "min(): given matrix has no elements" );
00089   
00090   return op_min::direct_min(X.mem, X.n_elem);
00091   }
00092 
00093 
00094 
00095 template<typename T1>
00096 inline
00097 const Op< Op<T1, op_min>, op_min>
00098 min(const Op<T1, op_min>& in, const u32 dim)
00099   {
00100   arma_extra_debug_sigprint();
00101   
00102   return Op< Op<T1, op_min>, op_min>(in, dim, 0);
00103   }
00104 
00105 
00106 
00107 template<typename eT>
00108 inline
00109 arma_warn_unused
00110 eT
00111 min(const subview_row<eT>& A)
00112   {
00113   arma_extra_debug_sigprint();
00114   
00115   arma_debug_check( (A.n_elem == 0), "min(): given vector has no elements" );
00116   
00117   return op_min::direct_min(A);
00118   }
00119 
00120 
00121 
00122 template<typename eT>
00123 inline
00124 arma_warn_unused
00125 eT
00126 min(const subview_col<eT>& A)
00127   {
00128   arma_extra_debug_sigprint();
00129   
00130   arma_debug_check( (A.n_elem == 0), "min(): given vector has no elements" );
00131   
00132   return op_min::direct_min(A);
00133   }
00134 
00135 
00136 
00137 template<typename eT>
00138 inline
00139 arma_warn_unused
00140 eT
00141 min(const diagview<eT>& A)
00142   {
00143   arma_extra_debug_sigprint();
00144   
00145   arma_debug_check( (A.n_elem == 0), "min(): given vector has no elements" );
00146   
00147   return op_min::direct_min(A);
00148   }
00149 
00150 
00151 
00152 template<typename eT>
00153 inline
00154 arma_warn_unused
00155 eT
00156 min(const Op<subview<eT>, op_min>& in)
00157   {
00158   arma_extra_debug_sigprint();
00159   arma_extra_debug_print("max(): two consecutive max() calls detected");
00160   
00161   const subview<eT>& X = in.m;
00162   
00163   arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" );
00164   
00165   return op_min::direct_min(X);
00166   }
00167 
00168 
00169 
00170 //! @}