fn_min.hpp

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