op_prod_meat.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 
00021 template<typename T1>
00022 inline
00023 void
00024 op_prod::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_prod>& in)
00025   {
00026   arma_extra_debug_sigprint();
00027   
00028   typedef typename T1::elem_type eT;
00029   
00030   const uword dim = in.aux_uword_a;
00031   arma_debug_check( (dim > 1), "prod(): incorrect usage. dim must be 0 or 1");
00032   
00033   const unwrap_check<T1> tmp(in.m, out);
00034   const Mat<eT>& X     = tmp.M;
00035   
00036   const uword X_n_rows = X.n_rows;
00037   const uword X_n_cols = X.n_cols;
00038     
00039   if(dim == 0)  // traverse across rows (i.e. find the product in each column)
00040     {
00041     out.set_size(1, X_n_cols);
00042     
00043     eT* out_mem = out.memptr();
00044     
00045     for(uword col=0; col<X_n_cols; ++col)
00046       {
00047       out_mem[col] = arrayops::product(X.colptr(col), X_n_rows);
00048       }
00049     }
00050   else  // traverse across columns (i.e. find the product in each row)
00051     {
00052     out.set_size(X_n_rows, 1);
00053     
00054     eT* out_mem = out.memptr();
00055     
00056     for(uword row=0; row<X_n_rows; ++row)
00057       {
00058       eT val = eT(1);
00059       
00060       for(uword col=0; col<X_n_cols; ++col)
00061         {
00062         val *= X.at(row,col);
00063         }
00064       
00065       out_mem[row] = val;
00066       }
00067     }
00068   }
00069 
00070 
00071 


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:05