comparison armadillo-2.4.4/include/armadillo_bits/glue_kron_meat.hpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8b6102e2a9b0
1 // Copyright (C) 2009-2010 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-2010 Conrad Sanderson
3 // Copyright (C) 2009-2010 Dimitrios Bouzas
4 //
5 // This file is part of the Armadillo C++ library.
6 // It is provided without any warranty of fitness
7 // for any purpose. You can redistribute this file
8 // and/or modify it under the terms of the GNU
9 // Lesser General Public License (LGPL) as published
10 // by the Free Software Foundation, either version 3
11 // of the License or (at your option) any later version.
12 // (see http://www.opensource.org/licenses for more info)
13
14
15 //! \addtogroup glue_kron
16 //! @{
17
18
19
20 //! \brief
21 //! both input matrices have the same element type
22 template<typename eT>
23 inline
24 void
25 glue_kron::direct_kron(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B)
26 {
27 arma_extra_debug_sigprint();
28
29 const uword A_rows = A.n_rows;
30 const uword A_cols = A.n_cols;
31 const uword B_rows = B.n_rows;
32 const uword B_cols = B.n_cols;
33
34 out.set_size(A_rows*B_rows, A_cols*B_cols);
35
36 for(uword i = 0; i < A_rows; i++)
37 {
38 for(uword j = 0; j < A_cols; j++)
39 {
40 out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A(i,j) * B;
41 }
42 }
43 }
44
45
46
47 //! \brief
48 //! different types of input matrices
49 //! A -> complex, B -> basic element type
50 template<typename T>
51 inline
52 void
53 glue_kron::direct_kron(Mat< std::complex<T> >& out, const Mat< std::complex<T> >& A, const Mat<T>& B)
54 {
55 arma_extra_debug_sigprint();
56
57 typedef typename std::complex<T> eT;
58
59 const uword A_rows = A.n_rows;
60 const uword A_cols = A.n_cols;
61 const uword B_rows = B.n_rows;
62 const uword B_cols = B.n_cols;
63
64 out.set_size(A_rows*B_rows, A_cols*B_cols);
65
66 Mat<eT> tmp_B = conv_to< Mat<eT> >::from(B);
67
68 for(uword i = 0; i < A_rows; i++)
69 {
70 for(uword j = 0; j < A_cols; j++)
71 {
72 out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A(i,j) * tmp_B;
73 }
74 }
75 }
76
77
78
79 //! \brief
80 //! different types of input matrices
81 //! A -> basic element type, B -> complex
82 template<typename T>
83 inline
84 void
85 glue_kron::direct_kron(Mat< std::complex<T> >& out, const Mat<T>& A, const Mat< std::complex<T> >& B)
86 {
87 arma_extra_debug_sigprint();
88
89 const uword A_rows = A.n_rows;
90 const uword A_cols = A.n_cols;
91 const uword B_rows = B.n_rows;
92 const uword B_cols = B.n_cols;
93
94 out.set_size(A_rows*B_rows, A_cols*B_cols);
95
96 for(uword i = 0; i < A_rows; i++)
97 {
98 for(uword j = 0; j < A_cols; j++)
99 {
100 out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A(i,j) * B;
101 }
102 }
103 }
104
105
106
107 //! \brief
108 //! apply Kronecker product for two objects with same element type
109 template<typename T1, typename T2>
110 inline
111 void
112 glue_kron::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_kron>& X)
113 {
114 arma_extra_debug_sigprint();
115
116 typedef typename T1::elem_type eT;
117
118 const unwrap_check<T1> A_tmp(X.A, out);
119 const unwrap_check<T2> B_tmp(X.B, out);
120
121 const Mat<eT>& A = A_tmp.M;
122 const Mat<eT>& B = B_tmp.M;
123
124 glue_kron::direct_kron(out, A, B);
125 }
126
127
128
129 //! @}