Classes | |
class | op_prod |
Class for finding products of values in a matrix (e.g. along rows or columns). More... | |
Functions | |
template<typename T1 > | |
static void | op_prod::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_prod > &in) |
Immediate product of elements of a matrix along a specified dimension (either rows or columns). The result is stored in a dense matrix that has either one column or one row. See the prod() function for more details. |
void op_prod::apply | ( | Mat< typename T1::elem_type > & | out, | |
const Op< T1, op_prod > & | in | |||
) | [inline, static, inherited] |
Immediate product of elements of a matrix along a specified dimension (either rows or columns). The result is stored in a dense matrix that has either one column or one row. See the prod() function for more details.
Definition at line 26 of file op_prod_meat.hpp.
References Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().
00027 { 00028 arma_extra_debug_sigprint(); 00029 00030 typedef typename T1::elem_type eT; 00031 00032 const u32 dim = in.aux_u32_a; 00033 arma_debug_check( (dim > 1), "prod(): incorrect usage. dim must be 0 or 1"); 00034 00035 const unwrap_check<T1> tmp(in.m, out); 00036 const Mat<eT>& X = tmp.M; 00037 00038 arma_debug_check( (X.n_elem < 1), "prod(): give object has no elements"); 00039 00040 00041 if(dim == 0) // traverse across rows (i.e. find the product in each column) 00042 { 00043 out.set_size(1, X.n_cols); 00044 00045 for(u32 col=0; col<X.n_cols; ++col) 00046 { 00047 const eT* X_colptr = X.colptr(col); 00048 00049 eT val = X_colptr[0]; 00050 00051 for(u32 row=1; row < X.n_rows; ++row) 00052 { 00053 val *= X_colptr[row]; 00054 } 00055 00056 out.at(0,col) = val; 00057 } 00058 } 00059 else // traverse across columns (i.e. find the product in each row) 00060 { 00061 out.set_size(X.n_rows, 1); 00062 00063 for(u32 row=0; row < X.n_rows; ++row) 00064 { 00065 eT val = X.at(row,0); 00066 00067 for(u32 col=1; col < X.n_cols; ++col) 00068 { 00069 val *= X.at(row,col); 00070 } 00071 00072 out.at(row,0) = val; 00073 } 00074 00075 } 00076 00077 }