Fn_prod

Functions

template<typename T1 >
const Op< T1, op_prodprod (const Base< typename T1::elem_type, T1 > &X, const u32 dim=0)
 Delayed 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. For dim = 0, find the sum of each column (i.e. traverse across rows) For dim = 1, find the sum of each row (i.e. traverse across columns) The default is dim = 0. NOTE: this function works differently than in Matlab/Octave.
template<typename eT >
eT prod (const Row< eT > &X)
 Immediate 'product of all values' operation for a row vector.
template<typename eT >
eT prod (const Col< eT > &X)
 Immediate 'product of all values' operation for a column vector.
template<typename T1 >
T1::elem_type prod (const Op< T1, op_prod > &in)
 Immediate 'product of all values' operation, invoked, for example, by: prod(prod(A)).
template<typename T1 >
const Op< Op< T1, op_prod >
, op_prod
prod (const Op< T1, op_prod > &in, const u32 dim)
template<typename eT >
eT prod (const subview_row< eT > &S)
 product of all values of a subview_row
template<typename eT >
eT prod (const subview_col< eT > &S)
 product of all values of a subview_col
template<typename eT >
eT prod (const diagview< eT > &X)
 product of all values of a diagview

Function Documentation

template<typename T1 >
const Op<T1, op_prod> prod ( const Base< typename T1::elem_type, T1 > &  X,
const u32  dim = 0 
) [inline]

Delayed 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. For dim = 0, find the sum of each column (i.e. traverse across rows) For dim = 1, find the sum of each row (i.e. traverse across columns) The default is dim = 0. NOTE: this function works differently than in Matlab/Octave.

Definition at line 31 of file fn_prod.hpp.

References Base< elem_type, derived >::get_ref().

00032   {
00033   arma_extra_debug_sigprint();
00034   
00035   return Op<T1, op_prod>(X.get_ref(), dim, 0);
00036   }

template<typename eT >
eT prod ( const Row< eT > &  X  )  [inline]

Immediate 'product of all values' operation for a row vector.

Definition at line 45 of file fn_prod.hpp.

References Mat< eT >::memptr(), and Mat< eT >::n_elem.

00046   {
00047   arma_extra_debug_sigprint();
00048   
00049   arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
00050   
00051   const u32 n_elem = X.n_elem;
00052   const eT* X_mem  = X.memptr();
00053   
00054   eT val = X_mem[0];
00055   
00056   for(u32 i=1; i<n_elem; ++i)
00057     {
00058     val *= X_mem[i];
00059     }
00060   
00061   return val;
00062   }

template<typename eT >
eT prod ( const Col< eT > &  X  )  [inline]

Immediate 'product of all values' operation for a column vector.

Definition at line 71 of file fn_prod.hpp.

References Mat< eT >::memptr(), and Mat< eT >::n_elem.

00072   {
00073   arma_extra_debug_sigprint();
00074   
00075   arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
00076   
00077   const u32 n_elem = X.n_elem;
00078   const eT* X_mem  = X.memptr();
00079   
00080   eT val = X_mem[0];
00081   
00082   for(u32 i=1; i<n_elem; ++i)
00083     {
00084     val *= X_mem[i];
00085     }
00086   
00087   return val;
00088   }

template<typename T1 >
T1::elem_type prod ( const Op< T1, op_prod > &  in  )  [inline]

Immediate 'product of all values' operation, invoked, for example, by: prod(prod(A)).

Definition at line 99 of file fn_prod.hpp.

References Op< T1, op_type >::m, Mat< eT >::memptr(), and Mat< eT >::n_elem.

00100   {
00101   arma_extra_debug_sigprint();
00102   arma_extra_debug_print("prod(): two consecutive prod() calls detected");
00103   
00104   typedef typename T1::elem_type eT;
00105   
00106   const unwrap<T1>   tmp(in.m);
00107   const Mat<eT>& X = tmp.M;
00108   
00109   arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
00110   
00111   const u32 n_elem = X.n_elem;
00112   const eT* X_mem  = X.memptr();
00113   
00114   eT val = X_mem[0];
00115   
00116   for(u32 i=1; i<n_elem; ++i)
00117     {
00118     val *= X_mem[i];
00119     }
00120   
00121   return val;
00122   }

template<typename T1 >
const Op<Op<T1, op_prod>, op_prod> prod ( const Op< T1, op_prod > &  in,
const u32  dim 
) [inline]

Definition at line 129 of file fn_prod.hpp.

00130   {
00131   arma_extra_debug_sigprint();
00132   
00133   return Op<Op<T1, op_prod>, op_prod>(in, dim, 0);
00134   }

template<typename eT >
eT prod ( const subview_row< eT > &  S  )  [inline]

product of all values of a subview_row

Definition at line 142 of file fn_prod.hpp.

References Mat< eT >::at(), subview< eT >::aux_col1, subview< eT >::aux_col2, subview< eT >::aux_row1, subview< eT >::m, and subview< eT >::n_elem.

00143   {
00144   arma_extra_debug_sigprint();
00145   
00146   arma_debug_check( (S.n_elem < 1), "prod(): given object has no elements" );
00147   
00148   const Mat<eT>& X = S.m;
00149   
00150   const u32 row       = S.aux_row1;
00151   const u32 start_col = S.aux_col1;
00152   const u32 end_col   = S.aux_col2;
00153   
00154   eT val = X.at(row,start_col);
00155   
00156   for(u32 col=start_col+1; col<=end_col; ++col)
00157     {
00158     val *= X.at(row,col);
00159     }
00160   
00161   return val;
00162   }

template<typename eT >
eT prod ( const subview_col< eT > &  S  )  [inline]

product of all values of a subview_col

Definition at line 170 of file fn_prod.hpp.

References subview< eT >::colptr(), subview< eT >::n_elem, and subview< eT >::n_rows.

00171   {
00172   arma_extra_debug_sigprint();
00173   
00174   arma_debug_check( (S.n_elem < 1), "prod(): given object has no elements" );
00175   
00176   const eT* S_colptr = S.colptr(0);
00177   const u32 n_rows   = S.n_rows;
00178   
00179   eT val = S_colptr[0];
00180   
00181   for(u32 row=1; row<n_rows; ++row)
00182     {
00183     val *= S_colptr[row];
00184     }
00185   
00186   return val;
00187   }

template<typename eT >
eT prod ( const diagview< eT > &  X  )  [inline]

product of all values of a diagview

Definition at line 195 of file fn_prod.hpp.

References diagview< eT >::n_elem.

00196   {
00197   arma_extra_debug_sigprint();
00198   
00199   arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
00200   
00201   const u32 n_elem = X.n_elem;
00202   
00203   eT val = X[0];
00204   
00205   for(u32 i=1; i<n_elem; ++i)
00206     {
00207     val *= X[i];
00208     }
00209   
00210   return val;
00211   }