fn_kron.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
00007 // 
00008 // This file is part of the Armadillo C++ library.
00009 // It is provided without any warranty of fitness
00010 // for any purpose. You can redistribute this file
00011 // and/or modify it under the terms of the GNU
00012 // Lesser General Public License (LGPL) as published
00013 // by the Free Software Foundation, either version 3
00014 // of the License or (at your option) any later version.
00015 // (see http://www.opensource.org/licenses for more info)
00016 
00017 
00018 //! \addtogroup fn_kron
00019 //! @{
00020 
00021 
00022 
00023 //! \brief
00024 //! kronecker product of two matrices,
00025 //! with the matrices having the same element type
00026 template<typename T1, typename T2>
00027 arma_inline
00028 const Glue<T1,T2,glue_kron>
00029 kron(const Base<typename T1::elem_type,T1>& A, const Base<typename T1::elem_type,T2>& B)
00030   {
00031   arma_extra_debug_sigprint();
00032 
00033   return Glue<T1, T2, glue_kron>(A.get_ref(), B.get_ref());
00034   }
00035 
00036 
00037 
00038 //! \brief
00039 //! kronecker product of two matrices,
00040 //! with the matrices having different element types
00041 template<typename T, typename T1, typename T2>
00042 inline
00043 Mat<typename eT_promoter<T1,T2>::eT>
00044 kron(const Base<std::complex<T>,T1>& X, const Base<T,T2>& Y)
00045   {
00046   arma_extra_debug_sigprint();
00047 
00048   typedef typename std::complex<T> eT1;
00049 
00050   promote_type<eT1,T>::check();
00051   
00052   const unwrap<T1> tmp1(X.get_ref());
00053   const unwrap<T2> tmp2(Y.get_ref());
00054   
00055   const Mat<eT1>& A = tmp1.M;
00056   const Mat<T  >& B = tmp2.M;
00057 
00058   Mat<eT1> out;
00059   
00060   glue_kron::direct_kron(out, A, B);
00061   
00062   return out;
00063   }
00064 
00065 
00066 
00067 //! \brief
00068 //! kronecker product of two matrices,
00069 //! with the matrices having different element types
00070 template<typename T, typename T1, typename T2>
00071 inline
00072 Mat<typename eT_promoter<T1,T2>::eT>
00073 kron(const Base<T,T1>& X, const Base<std::complex<T>,T2>& Y)
00074   {
00075   arma_extra_debug_sigprint();
00076 
00077   typedef typename std::complex<T> eT2;  
00078 
00079   promote_type<T,eT2>::check();
00080   
00081   const unwrap<T1> tmp1(X.get_ref());
00082   const unwrap<T2> tmp2(Y.get_ref());
00083   
00084   const Mat<T  >& A = tmp1.M;
00085   const Mat<eT2>& B = tmp2.M;
00086 
00087   Mat<eT2> out;
00088   
00089   glue_kron::direct_kron(out, A, B);
00090   
00091   return out;
00092   }
00093 
00094 
00095 
00096 //! @}