eGlueCube_meat.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 eGlueCube
  16. //! @{
  17. template<typename T1, typename T2, typename eglue_type>
  18. arma_inline
  19. eGlueCube<T1,T2,eglue_type>::~eGlueCube()
  20. {
  21. arma_extra_debug_sigprint();
  22. }
  23. template<typename T1, typename T2, typename eglue_type>
  24. arma_inline
  25. eGlueCube<T1,T2,eglue_type>::eGlueCube(const T1& in_A, const T2& in_B)
  26. : P1(in_A)
  27. , P2(in_B)
  28. {
  29. arma_extra_debug_sigprint();
  30. arma_debug_assert_same_size
  31. (
  32. P1.get_n_rows(), P1.get_n_cols(), P1.get_n_slices(),
  33. P2.get_n_rows(), P2.get_n_cols(), P2.get_n_slices(),
  34. eglue_type::text()
  35. );
  36. }
  37. template<typename T1, typename T2, typename eglue_type>
  38. arma_inline
  39. uword
  40. eGlueCube<T1,T2,eglue_type>::get_n_rows() const
  41. {
  42. return P1.get_n_rows();
  43. }
  44. template<typename T1, typename T2, typename eglue_type>
  45. arma_inline
  46. uword
  47. eGlueCube<T1,T2,eglue_type>::get_n_cols() const
  48. {
  49. return P1.get_n_cols();
  50. }
  51. template<typename T1, typename T2, typename eglue_type>
  52. arma_inline
  53. uword
  54. eGlueCube<T1,T2,eglue_type>::get_n_slices() const
  55. {
  56. return P1.get_n_slices();
  57. }
  58. template<typename T1, typename T2, typename eglue_type>
  59. arma_inline
  60. uword
  61. eGlueCube<T1,T2,eglue_type>::get_n_elem_slice() const
  62. {
  63. return P1.get_n_elem_slice();
  64. }
  65. template<typename T1, typename T2, typename eglue_type>
  66. arma_inline
  67. uword
  68. eGlueCube<T1,T2,eglue_type>::get_n_elem() const
  69. {
  70. return P1.get_n_elem();
  71. }
  72. template<typename T1, typename T2, typename eglue_type>
  73. arma_inline
  74. typename T1::elem_type
  75. eGlueCube<T1,T2,eglue_type>::operator[] (const uword i) const
  76. {
  77. // the optimiser will keep only one return statement
  78. typedef typename T1::elem_type eT;
  79. if(is_same_type<eglue_type, eglue_plus >::yes) { return P1[i] + P2[i]; }
  80. else if(is_same_type<eglue_type, eglue_minus>::yes) { return P1[i] - P2[i]; }
  81. else if(is_same_type<eglue_type, eglue_div >::yes) { return P1[i] / P2[i]; }
  82. else if(is_same_type<eglue_type, eglue_schur>::yes) { return P1[i] * P2[i]; }
  83. else return eT(0);
  84. }
  85. template<typename T1, typename T2, typename eglue_type>
  86. arma_inline
  87. typename T1::elem_type
  88. eGlueCube<T1,T2,eglue_type>::at(const uword row, const uword col, const uword slice) const
  89. {
  90. // the optimiser will keep only one return statement
  91. typedef typename T1::elem_type eT;
  92. if(is_same_type<eglue_type, eglue_plus >::yes) { return P1.at(row,col,slice) + P2.at(row,col,slice); }
  93. else if(is_same_type<eglue_type, eglue_minus>::yes) { return P1.at(row,col,slice) - P2.at(row,col,slice); }
  94. else if(is_same_type<eglue_type, eglue_div >::yes) { return P1.at(row,col,slice) / P2.at(row,col,slice); }
  95. else if(is_same_type<eglue_type, eglue_schur>::yes) { return P1.at(row,col,slice) * P2.at(row,col,slice); }
  96. else return eT(0);
  97. }
  98. template<typename T1, typename T2, typename eglue_type>
  99. arma_inline
  100. typename T1::elem_type
  101. eGlueCube<T1,T2,eglue_type>::at_alt(const uword i) const
  102. {
  103. // the optimiser will keep only one return statement
  104. typedef typename T1::elem_type eT;
  105. if(is_same_type<eglue_type, eglue_plus >::yes) { return P1.at_alt(i) + P2.at_alt(i); }
  106. else if(is_same_type<eglue_type, eglue_minus>::yes) { return P1.at_alt(i) - P2.at_alt(i); }
  107. else if(is_same_type<eglue_type, eglue_div >::yes) { return P1.at_alt(i) / P2.at_alt(i); }
  108. else if(is_same_type<eglue_type, eglue_schur>::yes) { return P1.at_alt(i) * P2.at_alt(i); }
  109. else return eT(0);
  110. }
  111. //! @}