glue_conv_meat.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2010-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 
00019 
00020 template<typename T1, typename T2>
00021 inline
00022 void
00023 glue_conv::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_conv>& X)
00024   {
00025   arma_extra_debug_sigprint();
00026   
00027   typedef typename T1::elem_type eT;
00028   
00029   const unwrap_check<T1> A_tmp(X.A, out);
00030   const unwrap_check<T2> B_tmp(X.B, out);
00031   
00032   const Mat<eT>& A = A_tmp.M;
00033   const Mat<eT>& B = B_tmp.M;
00034   
00035   arma_debug_check( ( (A.is_vec() == false) || (B.is_vec() == false) ), "conv(): inputs must be vectors" );
00036   
00037   
00038   const Mat<eT>& h = (A.n_elem <= B.n_elem) ? A : B;
00039   const Mat<eT>& x = (A.n_elem <= B.n_elem) ? B : A;
00040   
00041   
00042   const uword   h_n_elem = h.n_elem;
00043   const uword   x_n_elem = x.n_elem;
00044   const uword out_n_elem = h_n_elem + x_n_elem - 1;
00045   
00046   
00047   if( (h_n_elem == 0) || (x_n_elem == 0) )
00048     {
00049     out.reset();
00050     return;
00051     }
00052   
00053   
00054   (A.n_cols == 1) ? out.set_size(out_n_elem, 1) : out.set_size(1, out_n_elem);
00055   
00056   
00057   const eT*   h_mem = h.memptr();
00058   const eT*   x_mem = x.memptr();
00059         eT* out_mem = out.memptr();
00060   
00061   
00062   for(uword out_i = 0; out_i < (h_n_elem-1); ++out_i)
00063     {
00064     eT acc = eT(0);
00065     
00066     uword h_i = out_i;
00067     
00068     for(uword x_i = 0; x_i <= out_i; ++x_i, --h_i)
00069       {
00070       acc += h_mem[h_i] * x_mem[x_i];
00071       }
00072     
00073     out_mem[out_i] = acc;
00074     }
00075   
00076   
00077   for(uword out_i = h_n_elem-1; out_i < out_n_elem - (h_n_elem-1); ++out_i)
00078     {
00079     eT acc = eT(0);
00080    
00081     uword h_i = h_n_elem - 1;
00082     
00083     for(uword x_i = out_i - h_n_elem + 1; x_i <= out_i; ++x_i, --h_i)
00084       {
00085       acc += h_mem[h_i] * x_mem[x_i];
00086       }
00087       
00088     out_mem[out_i] = acc;
00089     }
00090   
00091   
00092   for(uword out_i = out_n_elem - (h_n_elem-1); out_i < out_n_elem; ++out_i)
00093     {
00094     eT acc = eT(0);
00095     
00096     uword h_i = h_n_elem - 1;
00097     
00098     for(uword x_i = out_i - h_n_elem + 1; x_i < x_n_elem; ++x_i, --h_i)
00099       {
00100       acc += h_mem[h_i] * x_mem[x_i];
00101       }
00102     
00103     out_mem[out_i] = acc;
00104     }
00105   
00106   
00107   }
00108 
00109 
00110 


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