glue_toeplitz_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 // Copyright (C) 2011 Alcatel Lucent
00004 // Copyright (C) 2011 Gerhard Schreiber
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 
00019 
00020 
00021 
00022 template<typename T1, typename T2>
00023 inline
00024 void
00025 glue_toeplitz::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_toeplitz>& in)
00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   typedef typename T1::elem_type eT;
00030   
00031   if( ((void*)(&in.A)) == ((void*)(&in.B)) )
00032     {
00033     arma_extra_debug_print("glue_toeplitz::apply(): one argument version");
00034     
00035     const unwrap_check<T1>  tmp(in.A, out);
00036     const Mat<eT>& A      = tmp.M;
00037     
00038     arma_debug_check( (A.is_vec() == false), "toeplitz(): input argument must be a vector" );
00039     
00040     const uword N     = A.n_elem;
00041     const eT* A_mem = A.memptr();
00042     
00043     out.set_size(N,N);
00044     
00045     for(uword col=0; col<N; ++col)
00046       {
00047       eT* col_mem = out.colptr(col);
00048       
00049       uword i;
00050       
00051       i = col;
00052       for(uword row=0; row<col; ++row, --i)
00053         {
00054         col_mem[row] = A_mem[i];
00055         }
00056       
00057       i = 0;
00058       for(uword row=col; row<N; ++row, ++i)
00059         {
00060         col_mem[row] = A_mem[i];
00061         }      
00062       }
00063     }
00064   else
00065     {
00066     arma_extra_debug_print("glue_toeplitz::apply(): two argument version");
00067     
00068     const unwrap_check<T1> tmp1(in.A, out);
00069     const unwrap_check<T2> tmp2(in.B, out);
00070     
00071     const Mat<eT>& A = tmp1.M;
00072     const Mat<eT>& B = tmp2.M;
00073     
00074     arma_debug_check( ( (A.is_vec() == false) || (B.is_vec() == false) ), "toeplitz(): input arguments must be vectors" );
00075     
00076     const uword A_N = A.n_elem;
00077     const uword B_N = B.n_elem;
00078     
00079     const eT* A_mem = A.memptr();
00080     const eT* B_mem = B.memptr();
00081     
00082     out.set_size(A_N, B_N);
00083     
00084     if( out.is_empty() )
00085       {
00086       return;
00087       }
00088     
00089     for(uword col=0; col<B_N; ++col)
00090       {
00091       eT* col_mem = out.colptr(col);
00092       
00093       uword i = 0;
00094       for(uword row=col; row<A_N; ++row, ++i)
00095         {
00096         col_mem[row] = A_mem[i];
00097         }
00098       }
00099     
00100     for(uword row=0; row<A_N; ++row)
00101       {
00102       uword i = 1;
00103       for(uword col=(row+1); col<B_N; ++col, ++i)
00104         {
00105         out.at(row,col) = B_mem[i];
00106         }
00107       }
00108     
00109     }
00110   
00111   
00112   }
00113 
00114 
00115 
00116 template<typename T1, typename T2>
00117 inline
00118 void
00119 glue_toeplitz_circ::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_toeplitz_circ>& in)
00120   {
00121   arma_extra_debug_sigprint();
00122   
00123   typedef typename T1::elem_type eT;
00124   
00125   if( ((void*)(&in.A)) == ((void*)(&in.B)) )
00126     {
00127     arma_extra_debug_print("glue_toeplitz_circ::apply(): one argument version");
00128     
00129     const unwrap_check<T1>  tmp(in.A, out);
00130     const Mat<eT>& A      = tmp.M;
00131     
00132     arma_debug_check( (A.is_vec() == false), "toeplitz(): input argument must be a vector" );
00133     
00134     const uword N     = A.n_elem;
00135     const eT* A_mem = A.memptr();
00136     
00137     out.set_size(N,N);
00138     
00139     
00140     if(A.is_colvec())
00141       {
00142       // A is interpreted as colvec
00143       
00144       for(uword col=0; col<N; ++col)
00145         {
00146         eT* col_mem = out.colptr(col);
00147         
00148         
00149         uword i = col;
00150         
00151         for(uword row=0; row<col; ++row, --i)
00152           {
00153           col_mem[row] = A_mem[N-i];
00154           }
00155         
00156         
00157         i = 0;
00158         
00159         for(uword row=col; row<N; ++row, ++i)
00160           {
00161           col_mem[row] = A_mem[i];
00162           }      
00163         }
00164       
00165       }
00166     else
00167       {
00168       // A is interpreted as rowvec - probably not the computationally most efficient way to do this ;-)
00169       
00170       for(uword row=0; row<N; ++row)
00171         {
00172         uword i = row;
00173          
00174         for(uword col=0; col<row; ++col, --i)
00175           {
00176           out.at(row,col) = A_mem[N-i];
00177           }
00178          
00179         i = 0;
00180          
00181         for(uword col=row; col<N; ++col, ++i)
00182           {
00183           out.at(row,col) = A_mem[i];
00184           }
00185         }
00186       }
00187     }
00188   }
00189 
00190 
00191 


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