Functions

Fn_prod

//! More...

Functions

template<typename T1 >
arma_inline 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

Detailed Description

//!


Function Documentation

template<typename T1 >
arma_inline const Op<T1, op_prod> prod ( 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.

Definition at line 32 of file fn_prod.hpp.

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

  {
  arma_extra_debug_sigprint();
  
  return Op<T1, op_prod>(X.get_ref(), dim, 0);
  }

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

//! Immediate 'product of all values' operation for a row vector

Definition at line 46 of file fn_prod.hpp.

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

  {
  arma_extra_debug_sigprint();
  
  arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
  
  const u32 n_elem = X.n_elem;
  const eT* X_mem  = X.memptr();
  
  eT val = X_mem[0];
  
  for(u32 i=1; i<n_elem; ++i)
    {
    val *= X_mem[i];
    }
  
  return val;
  }

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

//! Immediate 'product of all values' operation for a column vector

Definition at line 72 of file fn_prod.hpp.

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

  {
  arma_extra_debug_sigprint();
  
  arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
  
  const u32 n_elem = X.n_elem;
  const eT* X_mem  = X.memptr();
  
  eT val = X_mem[0];
  
  for(u32 i=1; i<n_elem; ++i)
    {
    val *= X_mem[i];
    }
  
  return val;
  }

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 100 of file fn_prod.hpp.

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

  {
  arma_extra_debug_sigprint();
  arma_extra_debug_print("prod(): two consecutive prod() calls detected");
  
  typedef typename T1::elem_type eT;
  
  const unwrap<T1>   tmp(in.m);
  const Mat<eT>& X = tmp.M;
  
  arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
  
  const u32 n_elem = X.n_elem;
  const eT* X_mem  = X.memptr();
  
  eT val = X_mem[0];
  
  for(u32 i=1; i<n_elem; ++i)
    {
    val *= X_mem[i];
    }
  
  return val;
  }

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 130 of file fn_prod.hpp.

  {
  arma_extra_debug_sigprint();
  
  return Op<Op<T1, op_prod>, op_prod>(in, dim, 0);
  }

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

product of all values of a subview_row

Definition at line 143 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.

  {
  arma_extra_debug_sigprint();
  
  arma_debug_check( (S.n_elem < 1), "prod(): given object has no elements" );
  
  const Mat<eT>& X = S.m;
  
  const u32 row       = S.aux_row1;
  const u32 start_col = S.aux_col1;
  const u32 end_col   = S.aux_col2;
  
  eT val = X.at(row,start_col);
  
  for(u32 col=start_col+1; col<=end_col; ++col)
    {
    val *= X.at(row,col);
    }
  
  return val;
  }

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

product of all values of a subview_col

Definition at line 171 of file fn_prod.hpp.

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

  {
  arma_extra_debug_sigprint();
  
  arma_debug_check( (S.n_elem < 1), "prod(): given object has no elements" );
  
  const eT* S_colptr = S.colptr(0);
  const u32 n_rows   = S.n_rows;
  
  eT val = S_colptr[0];
  
  for(u32 row=1; row<n_rows; ++row)
    {
    val *= S_colptr[row];
    }
  
  return val;
  }

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

product of all values of a diagview

Definition at line 196 of file fn_prod.hpp.

References diagview< eT >::n_elem.

  {
  arma_extra_debug_sigprint();
  
  arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
  
  const u32 n_elem = X.n_elem;
  
  eT val = X[0];
  
  for(u32 i=1; i<n_elem; ++i)
    {
    val *= X[i];
    }
  
  return val;
  }