fn_reshape.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 fn_reshape
  16. //! @{
  17. template<typename T1>
  18. arma_warn_unused
  19. inline
  20. typename enable_if2< is_arma_type<T1>::value, const Op<T1, op_reshape> >::result
  21. reshape(const T1& X, const uword in_n_rows, const uword in_n_cols)
  22. {
  23. arma_extra_debug_sigprint();
  24. return Op<T1, op_reshape>(X, in_n_rows, in_n_cols);
  25. }
  26. template<typename T1>
  27. arma_warn_unused
  28. inline
  29. typename enable_if2< is_arma_type<T1>::value, const Op<T1, op_reshape> >::result
  30. reshape(const T1& X, const SizeMat& s)
  31. {
  32. arma_extra_debug_sigprint();
  33. return Op<T1, op_reshape>(X, s.n_rows, s.n_cols);
  34. }
  35. //! NOTE: don't use this form: it will be removed
  36. template<typename T1>
  37. arma_deprecated
  38. inline
  39. const Op<T1, op_reshape_ext>
  40. reshape(const Base<typename T1::elem_type,T1>& X, const uword in_n_rows, const uword in_n_cols, const uword dim) //!< NOTE: don't use this form: it will be removed
  41. {
  42. arma_extra_debug_sigprint();
  43. arma_debug_check( (dim > 1), "reshape(): parameter 'dim' must be 0 or 1" );
  44. // arma_debug_warn("this form of reshape() is deprecated and will be removed");
  45. return Op<T1, op_reshape_ext>(X.get_ref(), in_n_rows, in_n_cols, dim, 'j');
  46. }
  47. template<typename T1>
  48. arma_warn_unused
  49. inline
  50. const OpCube<T1, op_reshape_ext>
  51. reshape(const BaseCube<typename T1::elem_type,T1>& X, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
  52. {
  53. arma_extra_debug_sigprint();
  54. return OpCube<T1, op_reshape_ext>(X.get_ref(), in_n_rows, in_n_cols, in_n_slices, uword(0), 'j');
  55. }
  56. //! NOTE: don't use this form: it will be removed
  57. template<typename T1>
  58. arma_deprecated
  59. inline
  60. const OpCube<T1, op_reshape_ext>
  61. reshape(const BaseCube<typename T1::elem_type,T1>& X, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices, const uword dim) //!< NOTE: don't use this form: it will be removed
  62. {
  63. arma_extra_debug_sigprint();
  64. arma_debug_check( (dim > 1), "reshape(): parameter 'dim' must be 0 or 1" );
  65. // arma_debug_warn("this form of reshape() is deprecated and will be removed");
  66. return OpCube<T1, op_reshape_ext>(X.get_ref(), in_n_rows, in_n_cols, in_n_slices, dim, 'j');
  67. }
  68. template<typename T1>
  69. arma_warn_unused
  70. inline
  71. const OpCube<T1, op_reshape_ext>
  72. reshape(const BaseCube<typename T1::elem_type,T1>& X, const SizeCube& s)
  73. {
  74. arma_extra_debug_sigprint();
  75. return OpCube<T1, op_reshape_ext>(X.get_ref(), s.n_rows, s.n_cols, s.n_slices, uword(0), 'j');
  76. }
  77. //! NOTE: don't use this form: it will be removed
  78. template<typename T1>
  79. arma_deprecated
  80. inline
  81. const OpCube<T1, op_reshape_ext>
  82. reshape(const BaseCube<typename T1::elem_type,T1>& X, const SizeCube& s, const uword dim) //!< NOTE: don't use this form: it will be removed
  83. {
  84. arma_extra_debug_sigprint();
  85. arma_debug_check( (dim > 1), "reshape(): parameter 'dim' must be 0 or 1" );
  86. // arma_debug_warn("this form of reshape() is deprecated and will be removed");
  87. return OpCube<T1, op_reshape_ext>(X.get_ref(), s.n_rows, s.n_cols, s.n_slices, dim, 'j');
  88. }
  89. template<typename T1>
  90. arma_warn_unused
  91. inline
  92. const SpOp<T1, spop_reshape>
  93. reshape(const SpBase<typename T1::elem_type, T1>& X, const uword in_n_rows, const uword in_n_cols)
  94. {
  95. arma_extra_debug_sigprint();
  96. return SpOp<T1, spop_reshape>(X.get_ref(), in_n_rows, in_n_cols);
  97. }
  98. template<typename T1>
  99. arma_warn_unused
  100. inline
  101. const SpOp<T1, spop_reshape>
  102. reshape(const SpBase<typename T1::elem_type, T1>& X, const SizeMat& s)
  103. {
  104. arma_extra_debug_sigprint();
  105. return SpOp<T1, spop_reshape>(X.get_ref(), s.n_rows, s.n_cols);
  106. }
  107. //! @}