glue_toeplitz_meat.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup glue_toeplitz
  16. //! @{
  17. template<typename T1, typename T2>
  18. inline
  19. void
  20. glue_toeplitz::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_toeplitz>& in)
  21. {
  22. arma_extra_debug_sigprint();
  23. typedef typename T1::elem_type eT;
  24. const unwrap_check<T1> tmp1(in.A, out);
  25. const unwrap_check<T2> tmp2(in.B, out);
  26. const Mat<eT>& A = tmp1.M;
  27. const Mat<eT>& B = tmp2.M;
  28. arma_debug_check
  29. (
  30. ( ((A.is_vec() == false) && (A.is_empty() == false)) || ((B.is_vec() == false) && (B.is_empty() == false)) ),
  31. "toeplitz(): given object is not a vector"
  32. );
  33. const uword A_N = A.n_elem;
  34. const uword B_N = B.n_elem;
  35. const eT* A_mem = A.memptr();
  36. const eT* B_mem = B.memptr();
  37. out.set_size(A_N, B_N);
  38. if( out.is_empty() ) { return; }
  39. for(uword col=0; col < B_N; ++col)
  40. {
  41. eT* col_mem = out.colptr(col);
  42. uword i = 0;
  43. for(uword row=col; row < A_N; ++row, ++i) { col_mem[row] = A_mem[i]; }
  44. }
  45. for(uword row=0; row < A_N; ++row)
  46. {
  47. uword i = 1;
  48. for(uword col=(row+1); col < B_N; ++col, ++i) { out.at(row,col) = B_mem[i]; }
  49. }
  50. }
  51. //! @}