op_reverse_meat.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_reverse
  16. //! @{
  17. template<typename T1>
  18. inline
  19. void
  20. op_reverse::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_reverse>& in)
  21. {
  22. arma_extra_debug_sigprint();
  23. const uword dim = in.aux_uword_a;
  24. arma_debug_check( (dim > 1), "reverse(): parameter 'dim' must be 0 or 1" );
  25. const Proxy<T1> P(in.m);
  26. if(is_Mat<typename Proxy<T1>::stored_type>::value || P.is_alias(out))
  27. {
  28. const unwrap<typename Proxy<T1>::stored_type> U(P.Q);
  29. if(dim == 0)
  30. {
  31. op_flipud::apply_direct(out, U.M);
  32. }
  33. else
  34. if(dim == 1)
  35. {
  36. op_fliplr::apply_direct(out, U.M);
  37. }
  38. }
  39. else
  40. {
  41. if(dim == 0)
  42. {
  43. op_flipud::apply_proxy_noalias(out, P);
  44. }
  45. else
  46. if(dim == 1)
  47. {
  48. op_fliplr::apply_proxy_noalias(out, P);
  49. }
  50. }
  51. }
  52. template<typename T1>
  53. inline
  54. void
  55. op_reverse_vec::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_reverse_vec>& in)
  56. {
  57. arma_extra_debug_sigprint();
  58. const Proxy<T1> P(in.m);
  59. if(is_Mat<typename Proxy<T1>::stored_type>::value || P.is_alias(out))
  60. {
  61. const unwrap<typename Proxy<T1>::stored_type> U(P.Q);
  62. if((T1::is_xvec) ? bool(U.M.is_rowvec()) : bool(T1::is_row))
  63. {
  64. op_fliplr::apply_direct(out, U.M);
  65. }
  66. else
  67. {
  68. op_flipud::apply_direct(out, U.M);
  69. }
  70. }
  71. else
  72. {
  73. if((T1::is_xvec) ? bool(P.get_n_rows() == 1) : bool(T1::is_row))
  74. {
  75. op_fliplr::apply_proxy_noalias(out, P);
  76. }
  77. else
  78. {
  79. op_flipud::apply_proxy_noalias(out, P);
  80. }
  81. }
  82. }
  83. //! @}