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 25 of file op_max_meat.hpp.
Referenced by apply(), and max().
00026 { 00027 arma_extra_debug_sigprint(); 00028 00029 eT max_val = X[0]; 00030 00031 for(u32 i=1; i<n_elem; ++i) 00032 { 00033 const eT tmp_val = X[i]; 00034 00035 if(tmp_val > max_val) 00036 { 00037 max_val = tmp_val; 00038 } 00039 } 00040 00041 return max_val; 00042 }
eT op_max::direct_max | ( | const subview< eT > & | X | ) | [inline, static, inherited] |
find the maximum value in a subview
Definition at line 50 of file op_max_meat.hpp.
References subview< eT >::n_elem.
eT op_max::direct_max | ( | const diagview< eT > & | X | ) | [inline, static, inherited] |
find the maximum value in a diagview
Definition at line 75 of file op_max_meat.hpp.
References diagview< eT >::n_elem.
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 103 of file op_max_meat.hpp.
References Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), direct_max(), unwrap_check< T1 >::M, Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().
00104 { 00105 arma_extra_debug_sigprint(); 00106 00107 typedef typename T1::elem_type eT; 00108 00109 const unwrap_check<T1> tmp(in.m, out); 00110 const Mat<eT>& X = tmp.M; 00111 00112 arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" ); 00113 00114 const u32 dim = in.aux_u32_a; 00115 arma_debug_check( (dim > 1), "max(): incorrect usage. dim must be 0 or 1"); 00116 00117 00118 if(dim == 0) 00119 { 00120 arma_extra_debug_print("op_max::apply(), dim = 0"); 00121 00122 out.set_size(1, X.n_cols); 00123 00124 for(u32 col=0; col<X.n_cols; ++col) 00125 { 00126 out[col] = op_max::direct_max( X.colptr(col), X.n_rows ); 00127 } 00128 } 00129 else 00130 if(dim == 1) 00131 { 00132 arma_extra_debug_print("op_max::apply(), dim = 1"); 00133 00134 out.set_size(X.n_rows, 1); 00135 00136 for(u32 row=0; row<X.n_rows; ++row) 00137 { 00138 eT max_val = X.at(row,0); 00139 00140 for(u32 col=1; col<X.n_cols; ++col) 00141 { 00142 const eT tmp_val = X.at(row,col); 00143 00144 if(tmp_val > max_val) 00145 { 00146 max_val = tmp_val; 00147 } 00148 } 00149 00150 out[row] = max_val; 00151 00152 } 00153 00154 } 00155 00156 }
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 164 of file op_max_meat.hpp.
References abs().
00165 { 00166 arma_extra_debug_sigprint(); 00167 00168 u32 index = 0; 00169 T max_val = std::abs(X[index]); 00170 00171 for(u32 i=1; i<n_elem; ++i) 00172 { 00173 const T tmp_val = std::abs(X[i]); 00174 00175 if(tmp_val > max_val) 00176 { 00177 max_val = tmp_val; 00178 index = i; 00179 } 00180 } 00181 00182 return X[index]; 00183 }
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 191 of file op_max_meat.hpp.
References abs().
00192 { 00193 arma_extra_debug_sigprint(); 00194 00195 u32 index = 0; 00196 T max_val = std::abs(X[index]); 00197 00198 for(u32 i=1; i<X.n_elem; ++i) 00199 { 00200 const T tmp_val = std::abs(X[i]); 00201 00202 if(tmp_val > max_val) 00203 { 00204 max_val = tmp_val; 00205 index = i; 00206 } 00207 } 00208 00209 return X[index]; 00210 }
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 218 of file op_max_meat.hpp.
References abs().
00219 { 00220 arma_extra_debug_sigprint(); 00221 00222 u32 index = 0; 00223 T max_val = std::abs(X[index]); 00224 00225 for(u32 i=1; i<X.n_elem; ++i) 00226 { 00227 const T tmp_val = std::abs(X[i]); 00228 00229 if(tmp_val > max_val) 00230 { 00231 max_val = tmp_val; 00232 index = i; 00233 } 00234 } 00235 00236 return X[index]; 00237 }
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 243 of file op_max_meat.hpp.
References abs(), Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), direct_max(), unwrap_check< T1 >::M, Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, and Mat< eT >::n_rows.
00244 { 00245 arma_extra_debug_sigprint(); 00246 00247 typedef typename std::complex<T> eT; 00248 isnt_same_type<eT, typename T1::elem_type>::check(); 00249 00250 const unwrap_check<T1> tmp(in.m, out); 00251 const Mat<eT>& X = tmp.M; 00252 00253 arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" ); 00254 00255 const u32 dim = in.aux_u32_a; 00256 arma_debug_check( (dim > 1), "max(): incorrect usage. dim must be 0 or 1"); 00257 00258 00259 if(dim == 0) // column-wise max 00260 { 00261 arma_extra_debug_print("op_max::apply(), dim = 0"); 00262 00263 out.set_size(1, X.n_cols); 00264 00265 for(u32 col=0; col<X.n_cols; ++col) 00266 { 00267 out[col] = op_max::direct_max( X.colptr(col), X.n_rows ); 00268 } 00269 } 00270 else 00271 if(dim == 1) // row-wise max 00272 { 00273 arma_extra_debug_print("op_max::apply(), dim = 1"); 00274 00275 out.set_size(X.n_rows, 1); 00276 00277 for(u32 row=0; row<X.n_rows; ++row) 00278 { 00279 u32 index = 0; 00280 T max_val = std::abs(X.at(row,index)); 00281 00282 for(u32 col=1; col<X.n_cols; ++col) 00283 { 00284 const T tmp_val = std::abs(X.at(row,col)); 00285 00286 if(tmp_val > max_val) 00287 { 00288 max_val = tmp_val; 00289 index = col; 00290 } 00291 } 00292 00293 out[row] = X.at(row,index); 00294 } 00295 00296 } 00297 00298 }