fn_max.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_max
00017 //! @{
00018 
00019 
00020 //! \brief
00021 //! Delayed 'maximum values' operation.
00022 //! The dimension, along which the maxima are found, is set via 'dim'.
00023 //! For dim = 0, the maximum value of each column is found.
00024 //! For dim = 1, the maximum value of each row is found.
00025 //! The default is dim = 0.
00026 //! NOTE: This function works differently than in Matlab/Octave.
00027 
00028 template<typename T1>
00029 inline
00030 const Op<T1, op_max>
00031 max(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
00032   {
00033   arma_extra_debug_sigprint();
00034 
00035   return Op<T1, op_max>(X.get_ref(), dim, 0);
00036   }
00037 
00038 
00039 //! Immediate 'find the maximum value in a row vector' operation
00040 template<typename eT>
00041 inline
00042 eT
00043 max(const Row<eT>& A)
00044   {
00045   arma_extra_debug_sigprint();
00046   
00047   arma_debug_check( (A.n_elem == 0), "max(): given vector has no elements" );
00048   
00049   return op_max::direct_max(A.mem, A.n_elem);
00050   }
00051 
00052 
00053 
00054 //! Immediate 'find the maximum value in a column vector' operation
00055 template<typename eT>
00056 inline
00057 eT
00058 max(const Col<eT>& A)
00059   {
00060   arma_extra_debug_sigprint();
00061   
00062   arma_debug_check( (A.n_elem == 0), "max(): given vector has no elements" );
00063   
00064   return op_max::direct_max(A.mem, A.n_elem);
00065   }
00066 
00067 
00068 
00069 //! \brief
00070 //! Immediate 'find maximum value' operation,
00071 //! invoked, for example, by: max(max(A))
00072 template<typename T1>
00073 inline
00074 typename T1::elem_type
00075 max(const Op<T1, op_max>& in)
00076   {
00077   arma_extra_debug_sigprint();
00078   arma_extra_debug_print("max(): two consecutive max() calls detected");
00079   
00080   typedef typename T1::elem_type eT;
00081   
00082   const unwrap<T1> tmp1(in.m);
00083   const Mat<eT>& X = tmp1.M;
00084   
00085   arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" );
00086   
00087   return op_max::direct_max(X.mem, X.n_elem);
00088   }
00089 
00090 
00091 
00092 template<typename T1>
00093 inline
00094 const Op< Op<T1, op_max>, op_max>
00095 max(const Op<T1, op_max>& in, const u32 dim)
00096   {
00097   arma_extra_debug_sigprint();
00098   
00099   return Op< Op<T1, op_max>, op_max>(in, dim, 0);
00100   }
00101 
00102 
00103 
00104 template<typename eT>
00105 inline
00106 eT
00107 max(const subview_row<eT>& A)
00108   {
00109   arma_extra_debug_sigprint();
00110   
00111   arma_debug_check( (A.n_elem == 0), "max(): given vector has no elements" );
00112   
00113   return op_max::direct_max(A);
00114   }
00115 
00116 
00117 
00118 template<typename eT>
00119 inline
00120 eT
00121 max(const subview_col<eT>& A)
00122   {
00123   arma_extra_debug_sigprint();
00124   
00125   arma_debug_check( (A.n_elem == 0), "max(): given vector has no elements" );
00126   
00127   return op_max::direct_max(A);
00128   }
00129 
00130 
00131 
00132 template<typename eT>
00133 inline
00134 eT
00135 max(const Op<subview<eT>, op_max>& in)
00136   {
00137   arma_extra_debug_sigprint();
00138   arma_extra_debug_print("max(): two consecutive max() calls detected");
00139   
00140   const subview<eT>& X = in.m;
00141   
00142   arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" );
00143   
00144   return op_max::direct_max(X);
00145   }
00146 
00147 
00148 
00149 template<typename eT>
00150 inline
00151 eT
00152 max(const diagview<eT>& A)
00153   {
00154   arma_extra_debug_sigprint();
00155   
00156   arma_debug_check( (A.n_elem == 0), "max(): given vector has no elements" );
00157   
00158   return op_max::direct_max(A);
00159   }
00160 
00161 
00162 
00163 //! @}