fn_kron.hpp 2.4 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 fn_kron
  16. //! @{
  17. template<typename T1, typename T2>
  18. arma_warn_unused
  19. arma_inline
  20. const Glue<T1,T2,glue_kron>
  21. kron(const Base<typename T1::elem_type,T1>& A, const Base<typename T1::elem_type,T2>& B)
  22. {
  23. arma_extra_debug_sigprint();
  24. return Glue<T1, T2, glue_kron>(A.get_ref(), B.get_ref());
  25. }
  26. template<typename T, typename T1, typename T2>
  27. arma_warn_unused
  28. inline
  29. Mat<typename eT_promoter<T1,T2>::eT>
  30. kron(const Base<std::complex<T>,T1>& X, const Base<T,T2>& Y)
  31. {
  32. arma_extra_debug_sigprint();
  33. typedef typename std::complex<T> eT1;
  34. promote_type<eT1,T>::check();
  35. const quasi_unwrap<T1> tmp1(X.get_ref());
  36. const quasi_unwrap<T2> tmp2(Y.get_ref());
  37. const Mat<eT1>& A = tmp1.M;
  38. const Mat<T >& B = tmp2.M;
  39. Mat<eT1> out;
  40. glue_kron::direct_kron(out, A, B);
  41. return out;
  42. }
  43. template<typename T, typename T1, typename T2>
  44. arma_warn_unused
  45. inline
  46. Mat<typename eT_promoter<T1,T2>::eT>
  47. kron(const Base<T,T1>& X, const Base<std::complex<T>,T2>& Y)
  48. {
  49. arma_extra_debug_sigprint();
  50. typedef typename std::complex<T> eT2;
  51. promote_type<T,eT2>::check();
  52. const quasi_unwrap<T1> tmp1(X.get_ref());
  53. const quasi_unwrap<T2> tmp2(Y.get_ref());
  54. const Mat<T >& A = tmp1.M;
  55. const Mat<eT2>& B = tmp2.M;
  56. Mat<eT2> out;
  57. glue_kron::direct_kron(out, A, B);
  58. return out;
  59. }
  60. template<typename T1, typename T2>
  61. arma_warn_unused
  62. arma_inline
  63. const SpGlue<T1, T2, spglue_kron>
  64. kron(const SpBase<typename T1::elem_type,T1>& A, const SpBase<typename T1::elem_type,T2>& B)
  65. {
  66. arma_extra_debug_sigprint();
  67. return SpGlue<T1, T2, spglue_kron>(A.get_ref(), B.get_ref());
  68. }
  69. //! @}