op_toeplitz_meat.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 op_toeplitz
  16. //! @{
  17. template<typename T1>
  18. inline
  19. void
  20. op_toeplitz::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_toeplitz>& in)
  21. {
  22. arma_extra_debug_sigprint();
  23. typedef typename T1::elem_type eT;
  24. const unwrap_check<T1> tmp(in.m, out);
  25. const Mat<eT>& X = tmp.M;
  26. arma_debug_check( ((X.is_vec() == false) && (X.is_empty() == false)), "toeplitz(): given object is not a vector" );
  27. const uword N = X.n_elem;
  28. const eT* X_mem = X.memptr();
  29. out.set_size(N,N);
  30. for(uword col=0; col < N; ++col)
  31. {
  32. eT* col_mem = out.colptr(col);
  33. uword i;
  34. i = col;
  35. for(uword row=0; row < col; ++row, --i) { col_mem[row] = X_mem[i]; }
  36. i = 0;
  37. for(uword row=col; row < N; ++row, ++i) { col_mem[row] = X_mem[i]; }
  38. }
  39. }
  40. template<typename T1>
  41. inline
  42. void
  43. op_toeplitz_c::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_toeplitz_c>& in)
  44. {
  45. arma_extra_debug_sigprint();
  46. typedef typename T1::elem_type eT;
  47. const unwrap_check<T1> tmp(in.m, out);
  48. const Mat<eT>& X = tmp.M;
  49. arma_debug_check( ((X.is_vec() == false) && (X.is_empty() == false)), "circ_toeplitz(): given object is not a vector" );
  50. const uword N = X.n_elem;
  51. const eT* X_mem = X.memptr();
  52. out.set_size(N,N);
  53. if(X.is_rowvec() == true)
  54. {
  55. for(uword row=0; row < N; ++row)
  56. {
  57. uword i;
  58. i = row;
  59. for(uword col=0; col < row; ++col, --i) { out.at(row,col) = X_mem[N-i]; }
  60. i = 0;
  61. for(uword col=row; col < N; ++col, ++i) { out.at(row,col) = X_mem[i]; }
  62. }
  63. }
  64. else
  65. {
  66. for(uword col=0; col < N; ++col)
  67. {
  68. eT* col_mem = out.colptr(col);
  69. uword i;
  70. i = col;
  71. for(uword row=0; row < col; ++row, --i) { col_mem[row] = X_mem[N-i]; }
  72. i = 0;
  73. for(uword row=col; row < N; ++row, ++i) { col_mem[row] = X_mem[i]; }
  74. }
  75. }
  76. }
  77. //! @}