eGlue_meat.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 eGlue
  16. //! @{
  17. template<typename T1, typename T2, typename eglue_type>
  18. arma_inline
  19. eGlue<T1,T2,eglue_type>::~eGlue()
  20. {
  21. arma_extra_debug_sigprint();
  22. }
  23. template<typename T1, typename T2, typename eglue_type>
  24. arma_inline
  25. eGlue<T1,T2,eglue_type>::eGlue(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( P1, P2, eglue_type::text() );
  31. arma_debug_assert_same_size
  32. (
  33. P1.get_n_rows(), P1.get_n_cols(),
  34. P2.get_n_rows(), P2.get_n_cols(),
  35. eglue_type::text()
  36. );
  37. }
  38. template<typename T1, typename T2, typename eglue_type>
  39. arma_inline
  40. uword
  41. eGlue<T1,T2,eglue_type>::get_n_rows() const
  42. {
  43. return is_row ? 1 : P1.get_n_rows();
  44. }
  45. template<typename T1, typename T2, typename eglue_type>
  46. arma_inline
  47. uword
  48. eGlue<T1,T2,eglue_type>::get_n_cols() const
  49. {
  50. return is_col ? 1 : P1.get_n_cols();
  51. }
  52. template<typename T1, typename T2, typename eglue_type>
  53. arma_inline
  54. uword
  55. eGlue<T1,T2,eglue_type>::get_n_elem() const
  56. {
  57. return P1.get_n_elem();
  58. }
  59. template<typename T1, typename T2, typename eglue_type>
  60. arma_inline
  61. typename T1::elem_type
  62. eGlue<T1,T2,eglue_type>::operator[] (const uword ii) const
  63. {
  64. // the optimiser will keep only one return statement
  65. typedef typename T1::elem_type eT;
  66. if(is_same_type<eglue_type, eglue_plus >::yes) { return P1[ii] + P2[ii]; }
  67. else if(is_same_type<eglue_type, eglue_minus>::yes) { return P1[ii] - P2[ii]; }
  68. else if(is_same_type<eglue_type, eglue_div >::yes) { return P1[ii] / P2[ii]; }
  69. else if(is_same_type<eglue_type, eglue_schur>::yes) { return P1[ii] * P2[ii]; }
  70. else return eT(0);
  71. }
  72. template<typename T1, typename T2, typename eglue_type>
  73. arma_inline
  74. typename T1::elem_type
  75. eGlue<T1,T2,eglue_type>::at(const uword row, const uword col) 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.at(row,col) + P2.at(row,col); }
  80. else if(is_same_type<eglue_type, eglue_minus>::yes) { return P1.at(row,col) - P2.at(row,col); }
  81. else if(is_same_type<eglue_type, eglue_div >::yes) { return P1.at(row,col) / P2.at(row,col); }
  82. else if(is_same_type<eglue_type, eglue_schur>::yes) { return P1.at(row,col) * P2.at(row,col); }
  83. else return eT(0);
  84. }
  85. template<typename T1, typename T2, typename eglue_type>
  86. arma_inline
  87. typename T1::elem_type
  88. eGlue<T1,T2,eglue_type>::at_alt(const uword ii) 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_alt(ii) + P2.at_alt(ii); }
  93. else if(is_same_type<eglue_type, eglue_minus>::yes) { return P1.at_alt(ii) - P2.at_alt(ii); }
  94. else if(is_same_type<eglue_type, eglue_div >::yes) { return P1.at_alt(ii) / P2.at_alt(ii); }
  95. else if(is_same_type<eglue_type, eglue_schur>::yes) { return P1.at_alt(ii) * P2.at_alt(ii); }
  96. else return eT(0);
  97. }
  98. //! @}