fn_prod.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2009-2011 Conrad Sanderson
00003 // 
00004 // This file is part of the Armadillo C++ library.
00005 // It is provided without any warranty of fitness
00006 // for any purpose. You can redistribute this file
00007 // and/or modify it under the terms of the GNU
00008 // Lesser General Public License (LGPL) as published
00009 // by the Free Software Foundation, either version 3
00010 // of the License or (at your option) any later version.
00011 // (see http://www.opensource.org/licenses for more info)
00012 
00013 
00016 
00017 
00025 
00026 template<typename T1>
00027 arma_inline
00028 const Op<T1, op_prod>
00029 prod(const Base<typename T1::elem_type,T1>& X, const uword dim = 0)
00030   {
00031   arma_extra_debug_sigprint();
00032   
00033   return Op<T1, op_prod>(X.get_ref(), dim, 0);
00034   }
00035 
00036 
00037 
00040 template<typename eT>
00041 inline
00042 arma_warn_unused
00043 eT
00044 prod(const Row<eT>& X)
00045   {
00046   arma_extra_debug_sigprint();
00047   
00048   return arrayops::product(X.memptr(), X.n_elem);
00049   }
00050 
00051 
00052 
00055 template<typename eT>
00056 inline
00057 arma_warn_unused
00058 eT
00059 prod(const Col<eT>& X)
00060   {
00061   arma_extra_debug_sigprint();
00062   
00063   return arrayops::product(X.memptr(), X.n_elem);
00064   }
00065 
00066 
00067 
00071 
00072 template<typename T1>
00073 inline
00074 typename T1::elem_type
00075 prod(const Op<T1, op_prod>& in)
00076   {
00077   arma_extra_debug_sigprint();
00078   arma_extra_debug_print("prod(): two consecutive prod() calls detected");
00079   
00080   typedef typename T1::elem_type eT;
00081   
00082   const unwrap<T1>   tmp(in.m);
00083   const Mat<eT>& X = tmp.M;
00084   
00085   return arrayops::product( X.memptr(), X.n_elem );
00086   }
00087 
00088 
00089 
00090 template<typename T1>
00091 inline
00092 const Op<Op<T1, op_prod>, op_prod>
00093 prod(const Op<T1, op_prod>& in, const uword dim)
00094   {
00095   arma_extra_debug_sigprint();
00096   
00097   return Op<Op<T1, op_prod>, op_prod>(in, dim, 0);
00098   }
00099 
00100 
00101 
00103 template<typename eT>
00104 inline
00105 arma_warn_unused
00106 eT
00107 prod(const subview_row<eT>& S)
00108   {
00109   arma_extra_debug_sigprint();
00110   
00111   const Mat<eT>& X = S.m;
00112   
00113   const uword n_elem         = S.n_elem;
00114   const uword row            = S.aux_row1;
00115   const uword start_col      = S.aux_col1;
00116   const uword end_col_plus_1 = start_col + S.n_cols;
00117   
00118   eT val = eT(1);
00119   
00120   if(n_elem > 0)
00121     {
00122     for(uword col=start_col; col<end_col_plus_1; ++col)
00123       {
00124       val *= X.at(row,col);
00125       }
00126     }
00127   
00128   return val;
00129   }
00130 
00131 
00132 
00134 template<typename eT>
00135 inline
00136 arma_warn_unused
00137 eT
00138 prod(const subview_col<eT>& S)
00139   {
00140   arma_extra_debug_sigprint();
00141   
00142   return (S.n_elem > 0) ? arrayops::product( S.colptr(0), S.n_rows ) : eT(1);
00143   }
00144 
00145 
00146 
00148 template<typename eT>
00149 arma_warn_unused
00150 inline
00151 eT
00152 prod(const diagview<eT>& X)
00153   {
00154   arma_extra_debug_sigprint();
00155   
00156   const uword X_n_elem = X.n_elem;
00157   
00158   eT val = eT(1);
00159   
00160   for(uword i=0; i<X_n_elem; ++i)
00161     {
00162     val *= X[i];
00163     }
00164   
00165   return val;
00166   }
00167 
00168 
00169 
00170 template<typename eT, typename T1>
00171 inline
00172 arma_warn_unused
00173 eT
00174 prod(const subview_elem1<eT,T1>& A)
00175   {
00176   arma_extra_debug_sigprint();
00177   
00178   const Col<eT> X(A);
00179   
00180   return prod(X);
00181   }
00182 
00183 
00184 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:04