Classes | |
class | op_max |
Class for finding maximum values in a matrix. More... | |
Functions | |
template<typename eT > | |
static eT | op_max::direct_max (const eT *const X, const u32 N) |
find the maximum value in an array | |
template<typename eT > | |
static eT | op_max::direct_max (const subview< eT > &X) |
find the maximum value in a subview | |
template<typename eT > | |
static eT | op_max::direct_max (const diagview< eT > &X) |
find the maximum value in a diagview | |
template<typename T1 > | |
static void | op_max::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_max > &in) |
For each row or for each column, find the maximum value. The result is stored in a dense matrix that has either one column or one row. The dimension, for which the maxima are found, is set via the max() function. | |
template<typename T > | |
static std::complex< T > | op_max::direct_max (const std::complex< T > *const X, const u32 n_elem) |
Find the maximum value in an array (version for complex numbers). | |
template<typename T > | |
static std::complex< T > | op_max::direct_max (const subview< std::complex< T > > &X) |
Find the maximum value in a subview (version for complex numbers). | |
template<typename T > | |
static std::complex< T > | op_max::direct_max (const diagview< std::complex< T > > &X) |
Find the maximum value in a diagview (version for complex numbers). | |
template<typename T , typename T1 > | |
static void | op_max::apply (Mat< std::complex< T > > &out, const Op< T1, op_max > &in) |
Implementation for complex numbers. |
eT op_max::direct_max | ( | const eT *const | X, | |
const u32 | N | |||
) | [inline, static, inherited] |
find the maximum value in an array
Definition at line 24 of file op_max_meat.hpp.
Referenced by apply(), and max().
00025 { 00026 arma_extra_debug_sigprint(); 00027 00028 eT max_val = X[0]; 00029 00030 for(u32 i=1; i<n_elem; ++i) 00031 { 00032 const eT tmp_val = X[i]; 00033 00034 if(tmp_val > max_val) 00035 { 00036 max_val = tmp_val; 00037 } 00038 } 00039 00040 return max_val; 00041 }
eT op_max::direct_max | ( | const subview< eT > & | X | ) | [inline, static, inherited] |
find the maximum value in a subview
Definition at line 49 of file op_max_meat.hpp.
References subview< eT >::n_elem.
00050 { 00051 arma_extra_debug_sigprint(); 00052 00053 eT max_val = X[0]; 00054 00055 for(u32 i=1; i<X.n_elem; ++i) 00056 { 00057 eT tmp_val = X[i]; 00058 00059 if(tmp_val > max_val) 00060 { 00061 max_val = tmp_val; 00062 } 00063 } 00064 00065 return max_val; 00066 }
eT op_max::direct_max | ( | const diagview< eT > & | X | ) | [inline, static, inherited] |
find the maximum value in a diagview
Definition at line 74 of file op_max_meat.hpp.
References diagview< eT >::n_elem.
00075 { 00076 arma_extra_debug_sigprint(); 00077 00078 eT max_val = X[0]; 00079 00080 for(u32 i=1; i<X.n_elem; ++i) 00081 { 00082 eT tmp_val = X[i]; 00083 00084 if(tmp_val > max_val) 00085 { 00086 max_val = tmp_val; 00087 } 00088 } 00089 00090 return max_val; 00091 }
void op_max::apply | ( | Mat< typename T1::elem_type > & | out, | |
const Op< T1, op_max > & | in | |||
) | [inline, static, inherited] |
For each row or for each column, find the maximum value. The result is stored in a dense matrix that has either one column or one row. The dimension, for which the maxima are found, is set via the max() function.
Definition at line 102 of file op_max_meat.hpp.
References Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), direct_max(), Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().
00103 { 00104 arma_extra_debug_sigprint(); 00105 00106 typedef typename T1::elem_type eT; 00107 00108 const unwrap_check<T1> tmp(in.m, out); 00109 const Mat<eT>& X = tmp.M; 00110 00111 arma_debug_check( (X.n_elem == 0), "op_max::apply(): given matrix has no elements" ); 00112 00113 const u32 dim = in.aux_u32_a; 00114 arma_debug_check( (dim > 1), "op_max::apply(): incorrect usage. dim must be 0 or 1"); 00115 00116 00117 if(dim == 0) 00118 { 00119 arma_extra_debug_print("op_max::apply(), dim = 0"); 00120 00121 out.set_size(1, X.n_cols); 00122 00123 for(u32 col=0; col<X.n_cols; ++col) 00124 { 00125 out[col] = op_max::direct_max( X.colptr(col), X.n_rows ); 00126 } 00127 } 00128 else 00129 if(dim == 1) 00130 { 00131 arma_extra_debug_print("op_max::apply(), dim = 1"); 00132 00133 out.set_size(X.n_rows, 1); 00134 00135 for(u32 row=0; row<X.n_rows; ++row) 00136 { 00137 eT max_val = X.at(row,0); 00138 00139 for(u32 col=1; col<X.n_cols; ++col) 00140 { 00141 const eT tmp_val = X.at(row,col); 00142 00143 if(tmp_val > max_val) 00144 { 00145 max_val = tmp_val; 00146 } 00147 } 00148 00149 out[row] = max_val; 00150 00151 } 00152 00153 } 00154 00155 }
std::complex< T > op_max::direct_max | ( | const std::complex< T > *const | X, | |
const u32 | n_elem | |||
) | [inline, static, inherited] |
Find the maximum value in an array (version for complex numbers).
Definition at line 163 of file op_max_meat.hpp.
References abs().
00164 { 00165 arma_extra_debug_sigprint(); 00166 00167 u32 index = 0; 00168 T max_val = std::abs(X[index]); 00169 00170 for(u32 i=1; i<n_elem; ++i) 00171 { 00172 const T tmp_val = std::abs(X[i]); 00173 00174 if(tmp_val > max_val) 00175 { 00176 max_val = tmp_val; 00177 index = i; 00178 } 00179 } 00180 00181 return X[index]; 00182 }
std::complex< T > op_max::direct_max | ( | const subview< std::complex< T > > & | X | ) | [inline, static, inherited] |
Find the maximum value in a subview (version for complex numbers).
Definition at line 190 of file op_max_meat.hpp.
References abs().
00191 { 00192 arma_extra_debug_sigprint(); 00193 00194 u32 index = 0; 00195 T max_val = std::abs(X[index]); 00196 00197 for(u32 i=1; i<X.n_elem; ++i) 00198 { 00199 const T tmp_val = std::abs(X[i]); 00200 00201 if(tmp_val > max_val) 00202 { 00203 max_val = tmp_val; 00204 index = i; 00205 } 00206 } 00207 00208 return X[index]; 00209 }
std::complex< T > op_max::direct_max | ( | const diagview< std::complex< T > > & | X | ) | [inline, static, inherited] |
Find the maximum value in a diagview (version for complex numbers).
Definition at line 217 of file op_max_meat.hpp.
References abs().
00218 { 00219 arma_extra_debug_sigprint(); 00220 00221 u32 index = 0; 00222 T max_val = std::abs(X[index]); 00223 00224 for(u32 i=1; i<X.n_elem; ++i) 00225 { 00226 const T tmp_val = std::abs(X[i]); 00227 00228 if(tmp_val > max_val) 00229 { 00230 max_val = tmp_val; 00231 index = i; 00232 } 00233 } 00234 00235 return X[index]; 00236 }
void op_max::apply | ( | Mat< std::complex< T > > & | out, | |
const Op< T1, op_max > & | in | |||
) | [inline, static, inherited] |
Implementation for complex numbers.
Definition at line 242 of file op_max_meat.hpp.
References abs(), Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), direct_max(), Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, and Mat< eT >::n_rows.
00243 { 00244 arma_extra_debug_sigprint(); 00245 00246 typedef typename std::complex<T> eT; 00247 isnt_same_type<eT, typename T1::elem_type>::check(); 00248 00249 const unwrap_check<T1> tmp(in.m, out); 00250 const Mat<eT>& X = tmp.M; 00251 00252 arma_debug_check( (X.n_elem == 0), "op_max::apply(): given matrix has no elements" ); 00253 00254 const u32 dim = in.aux_u32_a; 00255 arma_debug_check( (dim > 1), "op_max::apply(): incorrect usage. dim must be 0 or 1"); 00256 00257 00258 if(dim == 0) // column-wise max 00259 { 00260 arma_extra_debug_print("op_max::apply(), dim = 0"); 00261 00262 out.set_size(1, X.n_cols); 00263 00264 for(u32 col=0; col<X.n_cols; ++col) 00265 { 00266 out[col] = op_max::direct_max( X.colptr(col), X.n_rows ); 00267 } 00268 } 00269 else 00270 if(dim == 1) // row-wise max 00271 { 00272 arma_extra_debug_print("op_max::apply(), dim = 1"); 00273 00274 out.set_size(X.n_rows, 1); 00275 00276 for(u32 row=0; row<X.n_rows; ++row) 00277 { 00278 u32 index = 0; 00279 T max_val = std::abs(X.at(row,index)); 00280 00281 for(u32 col=1; col<X.n_cols; ++col) 00282 { 00283 const T tmp_val = std::abs(X.at(row,col)); 00284 00285 if(tmp_val > max_val) 00286 { 00287 max_val = tmp_val; 00288 index = col; 00289 } 00290 } 00291 00292 out[row] = X.at(row,index); 00293 } 00294 00295 } 00296 00297 }