glue_kron_meat.hpp
Go to the documentation of this file.
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 
17 
18 
19 
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  {
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 
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  {
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 
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  {
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 
109 template<typename T1, typename T2>
110 inline
111 void
113  {
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 
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
Definition: Mat_meat.hpp:4211
arma_inline subview< eT > submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2)
creation of subview (submatrix)
Definition: Mat_meat.hpp:2092
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
static void direct_kron(Mat< eT > &out, const Mat< eT > &A, const Mat< eT > &B)
both input matrices have the same element type
u32 uword
Definition: typedef.hpp:85
const T1 & A
first operand
Definition: Glue_bones.hpp:44
const T2 & B
second operand
Definition: Glue_bones.hpp:45
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
Dense matrix class.
static void apply(Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_kron > &X)
apply Kronecker product for two objects with same element type
const Mat< eT > M
Definition: unwrap.hpp:142


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:57