glue_times_bones.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 glue_times
  16. //! @{
  17. //! \brief
  18. //! Template metaprogram depth_lhs
  19. //! calculates the number of Glue<Tx,Ty, glue_type> instances on the left hand side argument of Glue<Tx,Ty, glue_type>
  20. //! i.e. it recursively expands each Tx, until the type of Tx is not "Glue<..,.., glue_type>" (i.e the "glue_type" changes)
  21. template<typename glue_type, typename T1>
  22. struct depth_lhs
  23. {
  24. static const uword num = 0;
  25. };
  26. template<typename glue_type, typename T1, typename T2>
  27. struct depth_lhs< glue_type, Glue<T1,T2,glue_type> >
  28. {
  29. static const uword num = 1 + depth_lhs<glue_type, T1>::num;
  30. };
  31. template<bool do_inv_detect>
  32. struct glue_times_redirect2_helper
  33. {
  34. template<typename T1, typename T2>
  35. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_times>& X);
  36. };
  37. template<>
  38. struct glue_times_redirect2_helper<true>
  39. {
  40. template<typename T1, typename T2>
  41. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_times>& X);
  42. };
  43. template<bool do_inv_detect>
  44. struct glue_times_redirect3_helper
  45. {
  46. template<typename T1, typename T2, typename T3>
  47. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Glue<T1,T2,glue_times>,T3,glue_times>& X);
  48. };
  49. template<>
  50. struct glue_times_redirect3_helper<true>
  51. {
  52. template<typename T1, typename T2, typename T3>
  53. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Glue<T1,T2,glue_times>,T3,glue_times>& X);
  54. };
  55. template<uword N>
  56. struct glue_times_redirect
  57. {
  58. template<typename T1, typename T2>
  59. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_times>& X);
  60. };
  61. template<>
  62. struct glue_times_redirect<2>
  63. {
  64. template<typename T1, typename T2>
  65. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_times>& X);
  66. };
  67. template<>
  68. struct glue_times_redirect<3>
  69. {
  70. template<typename T1, typename T2, typename T3>
  71. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Glue<T1,T2,glue_times>,T3,glue_times>& X);
  72. };
  73. template<>
  74. struct glue_times_redirect<4>
  75. {
  76. template<typename T1, typename T2, typename T3, typename T4>
  77. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Glue< Glue<T1,T2,glue_times>, T3, glue_times>, T4, glue_times>& X);
  78. };
  79. //! Class which implements the immediate multiplication of two or more matrices
  80. class glue_times
  81. {
  82. public:
  83. template<typename T1, typename T2>
  84. struct traits
  85. {
  86. static const bool is_row = T1::is_row;
  87. static const bool is_col = T2::is_col;
  88. static const bool is_xvec = false;
  89. };
  90. template<typename T1, typename T2>
  91. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_times>& X);
  92. template<typename T1>
  93. arma_hot inline static void apply_inplace(Mat<typename T1::elem_type>& out, const T1& X);
  94. template<typename T1, typename T2>
  95. arma_hot inline static void apply_inplace_plus(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_times>& X, const sword sign);
  96. //
  97. template<typename eT, const bool do_trans_A, const bool do_trans_B, typename TA, typename TB>
  98. arma_inline static uword mul_storage_cost(const TA& A, const TB& B);
  99. template<typename eT, const bool do_trans_A, const bool do_trans_B, const bool do_scalar_times, typename TA, typename TB>
  100. arma_hot inline static void apply(Mat<eT>& out, const TA& A, const TB& B, const eT val);
  101. template<typename eT, const bool do_trans_A, const bool do_trans_B, const bool do_trans_C, const bool do_scalar_times, typename TA, typename TB, typename TC>
  102. arma_hot inline static void apply(Mat<eT>& out, const TA& A, const TB& B, const TC& C, const eT val);
  103. template<typename eT, const bool do_trans_A, const bool do_trans_B, const bool do_trans_C, const bool do_trans_D, const bool do_scalar_times, typename TA, typename TB, typename TC, typename TD>
  104. arma_hot inline static void apply(Mat<eT>& out, const TA& A, const TB& B, const TC& C, const TD& D, const eT val);
  105. };
  106. class glue_times_diag
  107. {
  108. public:
  109. template<typename T1, typename T2>
  110. struct traits
  111. {
  112. static const bool is_row = T1::is_row;
  113. static const bool is_col = T2::is_col;
  114. static const bool is_xvec = false;
  115. };
  116. template<typename T1, typename T2>
  117. arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_times_diag>& X);
  118. };
  119. //! @}