comparison armadillo-2.4.4/include/armadillo_bits/op_symmat_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) 2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 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_symmat
15 //! @{
16
17
18
19 template<typename T1>
20 inline
21 void
22 op_symmat::apply
23 (
24 Mat<typename T1::elem_type>& out,
25 const Op<T1,op_symmat>& in,
26 const typename arma_not_cx<typename T1::elem_type>::result* junk
27 )
28 {
29 arma_extra_debug_sigprint();
30 arma_ignore(junk);
31
32 typedef typename T1::elem_type eT;
33
34 const unwrap<T1> tmp(in.m);
35 const Mat<eT>& A = tmp.M;
36
37 arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square" );
38
39 const uword N = A.n_rows;
40 const bool upper = (in.aux_uword_a == 0);
41
42 if(&out != &A)
43 {
44 out.copy_size(A);
45
46 if(upper)
47 {
48 // upper triangular: copy the diagonal and the elements above the diagonal
49
50 for(uword i=0; i<N; ++i)
51 {
52 const eT* A_data = A.colptr(i);
53 eT* out_data = out.colptr(i);
54
55 arrayops::copy( out_data, A_data, i+1 );
56 }
57 }
58 else
59 {
60 // lower triangular: copy the diagonal and the elements below the diagonal
61
62 for(uword i=0; i<N; ++i)
63 {
64 const eT* A_data = A.colptr(i);
65 eT* out_data = out.colptr(i);
66
67 arrayops::copy( &out_data[i], &A_data[i], N-i );
68 }
69 }
70 }
71
72
73 if(upper)
74 {
75 // reflect elements across the diagonal from upper triangle to lower triangle
76
77 for(uword col=1; col < N; ++col)
78 {
79 const eT* coldata = out.colptr(col);
80
81 for(uword row=0; row < col; ++row)
82 {
83 out.at(col,row) = coldata[row];
84 }
85 }
86 }
87 else
88 {
89 // reflect elements across the diagonal from lower triangle to upper triangle
90
91 for(uword col=0; col < N; ++col)
92 {
93 const eT* coldata = out.colptr(col);
94
95 for(uword row=(col+1); row < N; ++row)
96 {
97 out.at(col,row) = coldata[row];
98 }
99 }
100 }
101 }
102
103
104
105 template<typename T1>
106 inline
107 void
108 op_symmat::apply
109 (
110 Mat<typename T1::elem_type>& out,
111 const Op<T1,op_symmat>& in,
112 const typename arma_cx_only<typename T1::elem_type>::result* junk
113 )
114 {
115 arma_extra_debug_sigprint();
116 arma_ignore(junk);
117
118 typedef typename T1::elem_type eT;
119
120 const unwrap<T1> tmp(in.m);
121 const Mat<eT>& A = tmp.M;
122
123 arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square" );
124
125 const uword N = A.n_rows;
126 const bool upper = (in.aux_uword_a == 0);
127
128 if(&out != &A)
129 {
130 out.copy_size(A);
131
132 if(upper)
133 {
134 // upper triangular: copy the diagonal and the elements above the diagonal
135
136 for(uword i=0; i<N; ++i)
137 {
138 const eT* A_data = A.colptr(i);
139 eT* out_data = out.colptr(i);
140
141 arrayops::copy( out_data, A_data, i+1 );
142 }
143 }
144 else
145 {
146 // lower triangular: copy the diagonal and the elements below the diagonal
147
148 for(uword i=0; i<N; ++i)
149 {
150 const eT* A_data = A.colptr(i);
151 eT* out_data = out.colptr(i);
152
153 arrayops::copy( &out_data[i], &A_data[i], N-i );
154 }
155 }
156 }
157
158
159 if(upper)
160 {
161 // reflect elements across the diagonal from upper triangle to lower triangle
162
163 for(uword col=1; col < N; ++col)
164 {
165 const eT* coldata = out.colptr(col);
166
167 for(uword row=0; row < col; ++row)
168 {
169 out.at(col,row) = std::conj(coldata[row]);
170 }
171 }
172 }
173 else
174 {
175 // reflect elements across the diagonal from lower triangle to upper triangle
176
177 for(uword col=0; col < N; ++col)
178 {
179 const eT* coldata = out.colptr(col);
180
181 for(uword row=(col+1); row < N; ++row)
182 {
183 out.at(col,row) = std::conj(coldata[row]);
184 }
185 }
186 }
187 }
188
189
190
191 //! @}