comparison armadillo-2.4.4/include/armadillo_bits/op_htrans_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) 2008-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12
13
14 //! \addtogroup op_htrans
15 //! @{
16
17
18
19 template<typename eT>
20 arma_inline
21 void
22 op_htrans::apply_noalias(Mat<eT>& out, const Mat<eT>& A, const typename arma_not_cx<eT>::result* junk)
23 {
24 arma_extra_debug_sigprint();
25 arma_ignore(junk);
26
27 op_strans::apply_noalias(out, A);
28 }
29
30
31
32 template<typename eT>
33 inline
34 void
35 op_htrans::apply_noalias(Mat<eT>& out, const Mat<eT>& A, const typename arma_cx_only<eT>::result* junk)
36 {
37 arma_extra_debug_sigprint();
38 arma_ignore(junk);
39
40 const uword A_n_rows = A.n_rows;
41 const uword A_n_cols = A.n_cols;
42
43 out.set_size(A_n_cols, A_n_rows);
44
45 for(uword in_row = 0; in_row < A_n_rows; ++in_row)
46 {
47 const uword out_col = in_row;
48
49 for(uword in_col = 0; in_col < A_n_cols; ++in_col)
50 {
51 const uword out_row = in_col;
52 out.at(out_row, out_col) = std::conj( A.at(in_row, in_col) );
53 }
54 }
55
56 }
57
58
59
60 template<typename eT>
61 arma_inline
62 void
63 op_htrans::apply(Mat<eT>& out, const Mat<eT>& A, const typename arma_not_cx<eT>::result* junk)
64 {
65 arma_extra_debug_sigprint();
66 arma_ignore(junk);
67
68 op_strans::apply(out, A);
69 }
70
71
72
73 template<typename eT>
74 inline
75 void
76 op_htrans::apply(Mat<eT>& out, const Mat<eT>& A, const typename arma_cx_only<eT>::result* junk)
77 {
78 arma_extra_debug_sigprint();
79 arma_ignore(junk);
80
81 if(&out != &A)
82 {
83 op_htrans::apply_noalias(out, A);
84 }
85 else
86 {
87 if(out.n_rows == out.n_cols)
88 {
89 arma_extra_debug_print("doing in-place hermitian transpose of a square matrix");
90
91 const uword n_rows = out.n_rows;
92 const uword n_cols = out.n_cols;
93
94 for(uword col=0; col<n_cols; ++col)
95 {
96 eT* coldata = out.colptr(col);
97
98 out.at(col,col) = std::conj( out.at(col,col) );
99
100 for(uword row=(col+1); row<n_rows; ++row)
101 {
102 const eT val1 = std::conj(coldata[row]);
103 const eT val2 = std::conj(out.at(col,row));
104
105 out.at(col,row) = val1;
106 coldata[row] = val2;
107 }
108 }
109 }
110 else
111 {
112 Mat<eT> tmp;
113 op_strans::apply_noalias(tmp, A);
114
115 out.steal_mem(tmp);
116 }
117 }
118
119 }
120
121
122
123 template<typename T1>
124 inline
125 void
126 op_htrans::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_htrans>& in)
127 {
128 arma_extra_debug_sigprint();
129
130 typedef typename T1::elem_type eT;
131
132 const unwrap<T1> tmp(in.m);
133 const Mat<eT>& A = tmp.M;
134
135 op_htrans::apply(out, A);
136 }
137
138
139
140 template<typename T1>
141 inline
142 void
143 op_htrans::apply(Mat<typename T1::elem_type>& out, const Op< Op<T1, op_trimat>, op_htrans>& in)
144 {
145 arma_extra_debug_sigprint();
146
147 typedef typename T1::elem_type eT;
148
149 const unwrap<T1> tmp(in.m.m);
150 const Mat<eT>& A = tmp.M;
151
152 const bool upper = in.m.aux_uword_a;
153
154 op_trimat::apply_htrans(out, A, upper);
155 }
156
157
158
159 template<typename T1>
160 inline
161 void
162 op_htrans2::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_htrans2>& in)
163 {
164 arma_extra_debug_sigprint();
165
166 typedef typename T1::elem_type eT;
167
168 const unwrap<T1> tmp(in.m);
169
170 op_htrans::apply(out, tmp.M);
171
172 arrayops::inplace_mul( out.memptr(), in.aux, out.n_elem );
173 }
174
175
176
177 //! @}