annotate armadillo-2.4.4/include/armadillo_bits/glue_toeplitz_meat.hpp @ 18:8d046a9d36aa slimline

Back out rev 13:ac07c60aa798. Like an idiot, I committed a whole pile of unrelated changes in the guise of a single typo fix. Will re-commit in stages
author Chris Cannam
date Thu, 10 May 2012 10:45:44 +0100
parents 8b6102e2a9b0
children
rev   line source
max@0 1 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
max@0 2 // Copyright (C) 2010-2011 Conrad Sanderson
max@0 3 // Copyright (C) 2011 Alcatel Lucent
max@0 4 // Copyright (C) 2011 Gerhard Schreiber
max@0 5 //
max@0 6 // This file is part of the Armadillo C++ library.
max@0 7 // It is provided without any warranty of fitness
max@0 8 // for any purpose. You can redistribute this file
max@0 9 // and/or modify it under the terms of the GNU
max@0 10 // Lesser General Public License (LGPL) as published
max@0 11 // by the Free Software Foundation, either version 3
max@0 12 // of the License or (at your option) any later version.
max@0 13 // (see http://www.opensource.org/licenses for more info)
max@0 14
max@0 15
max@0 16
max@0 17 //! \addtogroup glue_toeplitz
max@0 18 //! @{
max@0 19
max@0 20
max@0 21
max@0 22 template<typename T1, typename T2>
max@0 23 inline
max@0 24 void
max@0 25 glue_toeplitz::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_toeplitz>& in)
max@0 26 {
max@0 27 arma_extra_debug_sigprint();
max@0 28
max@0 29 typedef typename T1::elem_type eT;
max@0 30
max@0 31 if( ((void*)(&in.A)) == ((void*)(&in.B)) )
max@0 32 {
max@0 33 arma_extra_debug_print("glue_toeplitz::apply(): one argument version");
max@0 34
max@0 35 const unwrap_check<T1> tmp(in.A, out);
max@0 36 const Mat<eT>& A = tmp.M;
max@0 37
max@0 38 arma_debug_check( (A.is_vec() == false), "toeplitz(): input argument must be a vector" );
max@0 39
max@0 40 const uword N = A.n_elem;
max@0 41 const eT* A_mem = A.memptr();
max@0 42
max@0 43 out.set_size(N,N);
max@0 44
max@0 45 for(uword col=0; col<N; ++col)
max@0 46 {
max@0 47 eT* col_mem = out.colptr(col);
max@0 48
max@0 49 uword i;
max@0 50
max@0 51 i = col;
max@0 52 for(uword row=0; row<col; ++row, --i)
max@0 53 {
max@0 54 col_mem[row] = A_mem[i];
max@0 55 }
max@0 56
max@0 57 i = 0;
max@0 58 for(uword row=col; row<N; ++row, ++i)
max@0 59 {
max@0 60 col_mem[row] = A_mem[i];
max@0 61 }
max@0 62 }
max@0 63 }
max@0 64 else
max@0 65 {
max@0 66 arma_extra_debug_print("glue_toeplitz::apply(): two argument version");
max@0 67
max@0 68 const unwrap_check<T1> tmp1(in.A, out);
max@0 69 const unwrap_check<T2> tmp2(in.B, out);
max@0 70
max@0 71 const Mat<eT>& A = tmp1.M;
max@0 72 const Mat<eT>& B = tmp2.M;
max@0 73
max@0 74 arma_debug_check( ( (A.is_vec() == false) || (B.is_vec() == false) ), "toeplitz(): input arguments must be vectors" );
max@0 75
max@0 76 const uword A_N = A.n_elem;
max@0 77 const uword B_N = B.n_elem;
max@0 78
max@0 79 const eT* A_mem = A.memptr();
max@0 80 const eT* B_mem = B.memptr();
max@0 81
max@0 82 out.set_size(A_N, B_N);
max@0 83
max@0 84 if( out.is_empty() )
max@0 85 {
max@0 86 return;
max@0 87 }
max@0 88
max@0 89 for(uword col=0; col<B_N; ++col)
max@0 90 {
max@0 91 eT* col_mem = out.colptr(col);
max@0 92
max@0 93 uword i = 0;
max@0 94 for(uword row=col; row<A_N; ++row, ++i)
max@0 95 {
max@0 96 col_mem[row] = A_mem[i];
max@0 97 }
max@0 98 }
max@0 99
max@0 100 for(uword row=0; row<A_N; ++row)
max@0 101 {
max@0 102 uword i = 1;
max@0 103 for(uword col=(row+1); col<B_N; ++col, ++i)
max@0 104 {
max@0 105 out.at(row,col) = B_mem[i];
max@0 106 }
max@0 107 }
max@0 108
max@0 109 }
max@0 110
max@0 111
max@0 112 }
max@0 113
max@0 114
max@0 115
max@0 116 template<typename T1, typename T2>
max@0 117 inline
max@0 118 void
max@0 119 glue_toeplitz_circ::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_toeplitz_circ>& in)
max@0 120 {
max@0 121 arma_extra_debug_sigprint();
max@0 122
max@0 123 typedef typename T1::elem_type eT;
max@0 124
max@0 125 if( ((void*)(&in.A)) == ((void*)(&in.B)) )
max@0 126 {
max@0 127 arma_extra_debug_print("glue_toeplitz_circ::apply(): one argument version");
max@0 128
max@0 129 const unwrap_check<T1> tmp(in.A, out);
max@0 130 const Mat<eT>& A = tmp.M;
max@0 131
max@0 132 arma_debug_check( (A.is_vec() == false), "toeplitz(): input argument must be a vector" );
max@0 133
max@0 134 const uword N = A.n_elem;
max@0 135 const eT* A_mem = A.memptr();
max@0 136
max@0 137 out.set_size(N,N);
max@0 138
max@0 139
max@0 140 if(A.is_colvec())
max@0 141 {
max@0 142 // A is interpreted as colvec
max@0 143
max@0 144 for(uword col=0; col<N; ++col)
max@0 145 {
max@0 146 eT* col_mem = out.colptr(col);
max@0 147
max@0 148
max@0 149 uword i = col;
max@0 150
max@0 151 for(uword row=0; row<col; ++row, --i)
max@0 152 {
max@0 153 col_mem[row] = A_mem[N-i];
max@0 154 }
max@0 155
max@0 156
max@0 157 i = 0;
max@0 158
max@0 159 for(uword row=col; row<N; ++row, ++i)
max@0 160 {
max@0 161 col_mem[row] = A_mem[i];
max@0 162 }
max@0 163 }
max@0 164
max@0 165 }
max@0 166 else
max@0 167 {
max@0 168 // A is interpreted as rowvec - probably not the computationally most efficient way to do this ;-)
max@0 169
max@0 170 for(uword row=0; row<N; ++row)
max@0 171 {
max@0 172 uword i = row;
max@0 173
max@0 174 for(uword col=0; col<row; ++col, --i)
max@0 175 {
max@0 176 out.at(row,col) = A_mem[N-i];
max@0 177 }
max@0 178
max@0 179 i = 0;
max@0 180
max@0 181 for(uword col=row; col<N; ++col, ++i)
max@0 182 {
max@0 183 out.at(row,col) = A_mem[i];
max@0 184 }
max@0 185 }
max@0 186 }
max@0 187 }
max@0 188 }
max@0 189
max@0 190
max@0 191
max@0 192 //! @}