op_dotext_meat.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2008-2010 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 
00018 
00019 template<typename eT>
00020 inline
00021 eT
00022 op_dotext::direct_rowvec_mat_colvec
00023   (
00024   const eT*      A_mem,
00025   const Mat<eT>& B,
00026   const eT*      C_mem
00027   )
00028   {
00029   arma_extra_debug_sigprint();
00030   
00031   const uword cost_AB = B.n_cols;
00032   const uword cost_BC = B.n_rows;
00033   
00034   if(cost_AB <= cost_BC)
00035     {
00036     podarray<eT> tmp(B.n_cols);
00037     
00038     for(uword col=0; col<B.n_cols; ++col)
00039       {
00040       const eT* B_coldata = B.colptr(col);
00041       
00042       eT val = eT(0);
00043       for(uword i=0; i<B.n_rows; ++i)
00044         {
00045         val += A_mem[i] * B_coldata[i];
00046         }
00047         
00048       tmp[col] = val;
00049       }
00050     
00051     return op_dot::direct_dot(B.n_cols, tmp.mem, C_mem);
00052     }
00053   else
00054     {
00055     podarray<eT> tmp(B.n_rows);
00056     
00057     for(uword row=0; row<B.n_rows; ++row)
00058       {
00059       eT val = eT(0);
00060       for(uword col=0; col<B.n_cols; ++col)
00061         {
00062         val += B.at(row,col) * C_mem[col];
00063         }
00064       
00065       tmp[row] = val;
00066       }
00067     
00068     return op_dot::direct_dot(B.n_rows, A_mem, tmp.mem);
00069     }
00070   
00071   
00072   }
00073 
00074 
00075 
00076 template<typename eT>
00077 inline
00078 eT
00079 op_dotext::direct_rowvec_transmat_colvec
00080   (
00081   const eT*      A_mem,
00082   const Mat<eT>& B,
00083   const eT*      C_mem
00084   )
00085   {
00086   arma_extra_debug_sigprint();
00087   
00088   const uword cost_AB = B.n_rows;
00089   const uword cost_BC = B.n_cols;
00090   
00091   if(cost_AB <= cost_BC)
00092     {
00093     podarray<eT> tmp(B.n_rows);
00094     
00095     for(uword row=0; row<B.n_rows; ++row)
00096       {
00097       eT val = eT(0);
00098       
00099       for(uword i=0; i<B.n_cols; ++i)
00100         {
00101         val += A_mem[i] * B.at(row,i);
00102         }
00103         
00104       tmp[row] = val;
00105       }
00106     
00107     return op_dot::direct_dot(B.n_rows, tmp.mem, C_mem);
00108     }
00109   else
00110     {
00111     podarray<eT> tmp(B.n_cols);
00112     
00113     for(uword col=0; col<B.n_cols; ++col)
00114       {
00115       const eT* B_coldata = B.colptr(col);
00116       
00117       eT val = eT(0);
00118       
00119       for(uword i=0; i<B.n_rows; ++i)
00120         {
00121         val += B_coldata[i] * C_mem[i];
00122         }
00123       
00124       tmp[col] = val;
00125       }
00126     
00127     return op_dot::direct_dot(B.n_cols, A_mem, tmp.mem);
00128     }
00129   
00130   
00131   }
00132 
00133 
00134 
00135 template<typename eT>
00136 inline
00137 eT
00138 op_dotext::direct_rowvec_diagmat_colvec
00139   (
00140   const eT*      A_mem,
00141   const Mat<eT>& B,
00142   const eT*      C_mem
00143   )
00144   {
00145   arma_extra_debug_sigprint();
00146   
00147   eT val = eT(0);
00148 
00149   for(uword i=0; i<B.n_rows; ++i)
00150     {
00151     val += A_mem[i] * B.at(i,i) * C_mem[i];
00152     }
00153 
00154   return val;
00155   }
00156 
00157 
00158 
00159 template<typename eT>
00160 inline
00161 eT
00162 op_dotext::direct_rowvec_invdiagmat_colvec
00163   (
00164   const eT*      A_mem,
00165   const Mat<eT>& B,
00166   const eT*      C_mem
00167   )
00168   {
00169   arma_extra_debug_sigprint();
00170   
00171   eT val = eT(0);
00172 
00173   for(uword i=0; i<B.n_rows; ++i)
00174     {
00175     val += (A_mem[i] * C_mem[i]) / B.at(i,i);
00176     }
00177 
00178   return val;
00179   }
00180 
00181 
00182 
00183 template<typename eT>
00184 inline
00185 eT
00186 op_dotext::direct_rowvec_invdiagvec_colvec
00187   (
00188   const eT*      A_mem,
00189   const Mat<eT>& B,
00190   const eT*      C_mem
00191   )
00192   {
00193   arma_extra_debug_sigprint();
00194   
00195   const eT* B_mem = B.mem;
00196   
00197   eT val = eT(0);
00198 
00199   for(uword i=0; i<B.n_elem; ++i)
00200     {
00201     val += (A_mem[i] * C_mem[i]) / B_mem[i];
00202     }
00203 
00204   return val;
00205   }
00206 
00207 
00208 


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