glue_toeplitz_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 
00018 //! \addtogroup glue_toeplitz
00019 //! @{
00020 
00021 
00022 
00023 template<typename T1, typename T2>
00024 inline
00025 void
00026 glue_toeplitz::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_toeplitz>& in)
00027   {
00028   arma_extra_debug_sigprint();
00029   
00030   typedef typename T1::elem_type eT;
00031   
00032   if( ((void*)(&in.A)) == ((void*)(&in.B)) )
00033     {
00034     arma_extra_debug_print("glue_toeplitz::apply(): one argument version");
00035     
00036     const unwrap_check<T1>  tmp(in.A, out);
00037     const Mat<eT>& A      = tmp.M;
00038     
00039     arma_debug_check( (A.is_vec() == false), "toeplitz(): input argument must be a vector" );
00040     
00041     const u32 N     = A.n_elem;
00042     const eT* A_mem = A.memptr();
00043     
00044     out.set_size(N,N);
00045     
00046     for(u32 col=0; col<N; ++col)
00047       {
00048       eT* col_mem = out.colptr(col);
00049       
00050       u32 i;
00051       
00052       i = col;
00053       for(u32 row=0; row<col; ++row, --i)
00054         {
00055         col_mem[row] = A_mem[i];
00056         }
00057       
00058       i = 0;
00059       for(u32 row=col; row<N; ++row, ++i)
00060         {
00061         col_mem[row] = A_mem[i];
00062         }      
00063       }
00064     }
00065   else
00066     {
00067     arma_extra_debug_print("glue_toeplitz::apply(): two argument version");
00068     
00069     const unwrap_check<T1> tmp1(in.A, out);
00070     const unwrap_check<T2> tmp2(in.B, out);
00071     
00072     const Mat<eT>& A = tmp1.M;
00073     const Mat<eT>& B = tmp2.M;
00074     
00075     arma_debug_check( ( (A.is_vec() == false) || (B.is_vec() == false) ), "toeplitz(): input arguments must be vectors" );
00076     
00077     const u32 A_N = A.n_elem;
00078     const u32 B_N = B.n_elem;
00079     
00080     const eT* A_mem = A.memptr();
00081     const eT* B_mem = B.memptr();
00082     
00083     out.set_size(A_N, B_N);
00084     
00085     for(u32 col=0; col<B_N; ++col)
00086       {
00087       eT* col_mem = out.colptr(col);
00088       
00089       u32 i = 0;
00090       for(u32 row=col; row<A_N; ++row, ++i)
00091         {
00092         col_mem[row] = A_mem[i];
00093         }
00094       }
00095     
00096     for(u32 row=0; row<A_N; ++row)
00097       {
00098       u32 i = 1;
00099       for(u32 col=(row+1); col<B_N; ++col, ++i)
00100         {
00101         out.at(row,col) = B_mem[i];
00102         }
00103       }
00104     
00105     }
00106   
00107   
00108   }
00109 
00110 
00111 
00112 //! @}