op_dotext_meat.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup op_dotext
00018 //! @{
00019 
00020 
00021 
00022 template<typename eT>
00023 inline
00024 eT
00025 op_dotext::direct_rowvec_mat_colvec
00026   (
00027   const eT*      A_mem,
00028   const Mat<eT>& B,
00029   const eT*      C_mem
00030   )
00031   {
00032   arma_extra_debug_sigprint();
00033   
00034   const u32 cost_AB = B.n_cols;
00035   const u32 cost_BC = B.n_rows;
00036   
00037   if(cost_AB <= cost_BC)
00038     {
00039     podarray<eT> tmp(B.n_cols);
00040     
00041     for(u32 col=0; col<B.n_cols; ++col)
00042       {
00043       const eT* B_coldata = B.colptr(col);
00044       
00045       eT val = eT(0);
00046       for(u32 i=0; i<B.n_rows; ++i)
00047         {
00048         val += A_mem[i] * B_coldata[i];
00049         }
00050         
00051       tmp[col] = val;
00052       }
00053     
00054     return op_dot::direct_dot(B.n_cols, tmp.mem, C_mem);
00055     }
00056   else
00057     {
00058     podarray<eT> tmp(B.n_rows);
00059     
00060     for(u32 row=0; row<B.n_rows; ++row)
00061       {
00062       eT val = eT(0);
00063       for(u32 col=0; col<B.n_cols; ++col)
00064         {
00065         val += B.at(row,col) * C_mem[col];
00066         }
00067       
00068       tmp[row] = val;
00069       }
00070     
00071     return op_dot::direct_dot(B.n_rows, A_mem, tmp.mem);
00072     }
00073   
00074   
00075   }
00076 
00077 
00078 
00079 template<typename eT>
00080 inline
00081 eT
00082 op_dotext::direct_rowvec_transmat_colvec
00083   (
00084   const eT*      A_mem,
00085   const Mat<eT>& B,
00086   const eT*      C_mem
00087   )
00088   {
00089   arma_extra_debug_sigprint();
00090   
00091   const u32 cost_AB = B.n_rows;
00092   const u32 cost_BC = B.n_cols;
00093   
00094   if(cost_AB <= cost_BC)
00095     {
00096     podarray<eT> tmp(B.n_rows);
00097     
00098     for(u32 row=0; row<B.n_rows; ++row)
00099       {
00100       eT val = eT(0);
00101       
00102       for(u32 i=0; i<B.n_cols; ++i)
00103         {
00104         val += A_mem[i] * B.at(row,i);
00105         }
00106         
00107       tmp[row] = val;
00108       }
00109     
00110     return op_dot::direct_dot(B.n_rows, tmp.mem, C_mem);
00111     }
00112   else
00113     {
00114     podarray<eT> tmp(B.n_cols);
00115     
00116     for(u32 col=0; col<B.n_cols; ++col)
00117       {
00118       const eT* B_coldata = B.colptr(col);
00119       
00120       eT val = eT(0);
00121       
00122       for(u32 i=0; i<B.n_rows; ++i)
00123         {
00124         val += B_coldata[i] * C_mem[i];
00125         }
00126       
00127       tmp[col] = val;
00128       }
00129     
00130     return op_dot::direct_dot(B.n_cols, A_mem, tmp.mem);
00131     }
00132   
00133   
00134   }
00135 
00136 
00137 
00138 template<typename eT>
00139 inline
00140 eT
00141 op_dotext::direct_rowvec_diagmat_colvec
00142   (
00143   const eT*      A_mem,
00144   const Mat<eT>& B,
00145   const eT*      C_mem
00146   )
00147   {
00148   arma_extra_debug_sigprint();
00149   
00150   eT val = eT(0);
00151 
00152   for(u32 i=0; i<B.n_rows; ++i)
00153     {
00154     val += A_mem[i] * B.at(i,i) * C_mem[i];
00155     }
00156 
00157   return val;
00158   }
00159 
00160 
00161 
00162 template<typename eT>
00163 inline
00164 eT
00165 op_dotext::direct_rowvec_invdiagmat_colvec
00166   (
00167   const eT*      A_mem,
00168   const Mat<eT>& B,
00169   const eT*      C_mem
00170   )
00171   {
00172   arma_extra_debug_sigprint();
00173   
00174   eT val = eT(0);
00175 
00176   for(u32 i=0; i<B.n_rows; ++i)
00177     {
00178     val += (A_mem[i] * C_mem[i]) / B.at(i,i);
00179     }
00180 
00181   return val;
00182   }
00183 
00184 
00185 
00186 template<typename eT>
00187 inline
00188 eT
00189 op_dotext::direct_rowvec_invdiagvec_colvec
00190   (
00191   const eT*      A_mem,
00192   const Mat<eT>& B,
00193   const eT*      C_mem
00194   )
00195   {
00196   arma_extra_debug_sigprint();
00197   
00198   const eT* B_mem = B.mem;
00199   
00200   eT val = eT(0);
00201 
00202   for(u32 i=0; i<B.n_elem; ++i)
00203     {
00204     val += (A_mem[i] * C_mem[i]) / B_mem[i];
00205     }
00206 
00207   return val;
00208   }
00209 
00210 
00211 
00212 //! @}