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