max@0: // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2009-2010 Conrad Sanderson max@0: // Copyright (C) 2009-2010 Dimitrios Bouzas max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup glue_kron max@0: //! @{ max@0: max@0: max@0: max@0: //! \brief max@0: //! both input matrices have the same element type max@0: template max@0: inline max@0: void max@0: glue_kron::direct_kron(Mat& out, const Mat& A, const Mat& B) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword A_rows = A.n_rows; max@0: const uword A_cols = A.n_cols; max@0: const uword B_rows = B.n_rows; max@0: const uword B_cols = B.n_cols; max@0: max@0: out.set_size(A_rows*B_rows, A_cols*B_cols); max@0: max@0: for(uword i = 0; i < A_rows; i++) max@0: { max@0: for(uword j = 0; j < A_cols; j++) max@0: { max@0: out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A(i,j) * B; max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: //! \brief max@0: //! different types of input matrices max@0: //! A -> complex, B -> basic element type max@0: template max@0: inline max@0: void max@0: glue_kron::direct_kron(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat& B) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename std::complex eT; max@0: max@0: const uword A_rows = A.n_rows; max@0: const uword A_cols = A.n_cols; max@0: const uword B_rows = B.n_rows; max@0: const uword B_cols = B.n_cols; max@0: max@0: out.set_size(A_rows*B_rows, A_cols*B_cols); max@0: max@0: Mat tmp_B = conv_to< Mat >::from(B); max@0: max@0: for(uword i = 0; i < A_rows; i++) max@0: { max@0: for(uword j = 0; j < A_cols; j++) max@0: { max@0: out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A(i,j) * tmp_B; max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: //! \brief max@0: //! different types of input matrices max@0: //! A -> basic element type, B -> complex max@0: template max@0: inline max@0: void max@0: glue_kron::direct_kron(Mat< std::complex >& out, const Mat& A, const Mat< std::complex >& B) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword A_rows = A.n_rows; max@0: const uword A_cols = A.n_cols; max@0: const uword B_rows = B.n_rows; max@0: const uword B_cols = B.n_cols; max@0: max@0: out.set_size(A_rows*B_rows, A_cols*B_cols); max@0: max@0: for(uword i = 0; i < A_rows; i++) max@0: { max@0: for(uword j = 0; j < A_cols; j++) max@0: { max@0: out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A(i,j) * B; max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: //! \brief max@0: //! apply Kronecker product for two objects with same element type max@0: template max@0: inline max@0: void max@0: glue_kron::apply(Mat& out, const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const unwrap_check A_tmp(X.A, out); max@0: const unwrap_check B_tmp(X.B, out); max@0: max@0: const Mat& A = A_tmp.M; max@0: const Mat& B = B_tmp.M; max@0: max@0: glue_kron::direct_kron(out, A, B); max@0: } max@0: max@0: max@0: max@0: //! @}