max@0
|
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
|
max@0
|
2 // Copyright (C) 2008-2011 Conrad Sanderson
|
max@0
|
3 //
|
max@0
|
4 // This file is part of the Armadillo C++ library.
|
max@0
|
5 // It is provided without any warranty of fitness
|
max@0
|
6 // for any purpose. You can redistribute this file
|
max@0
|
7 // and/or modify it under the terms of the GNU
|
max@0
|
8 // Lesser General Public License (LGPL) as published
|
max@0
|
9 // by the Free Software Foundation, either version 3
|
max@0
|
10 // of the License or (at your option) any later version.
|
max@0
|
11 // (see http://www.opensource.org/licenses for more info)
|
max@0
|
12
|
max@0
|
13
|
max@0
|
14 //! \addtogroup diagview
|
max@0
|
15 //! @{
|
max@0
|
16
|
max@0
|
17
|
max@0
|
18 template<typename eT>
|
max@0
|
19 inline
|
max@0
|
20 diagview<eT>::~diagview()
|
max@0
|
21 {
|
max@0
|
22 arma_extra_debug_sigprint();
|
max@0
|
23 }
|
max@0
|
24
|
max@0
|
25
|
max@0
|
26 template<typename eT>
|
max@0
|
27 arma_inline
|
max@0
|
28 diagview<eT>::diagview(const Mat<eT>& in_m, const uword in_row_offset, const uword in_col_offset, const uword in_len)
|
max@0
|
29 : m(in_m)
|
max@0
|
30 , m_ptr(0)
|
max@0
|
31 , row_offset(in_row_offset)
|
max@0
|
32 , col_offset(in_col_offset)
|
max@0
|
33 , n_rows(in_len)
|
max@0
|
34 , n_elem(in_len)
|
max@0
|
35 {
|
max@0
|
36 arma_extra_debug_sigprint();
|
max@0
|
37 }
|
max@0
|
38
|
max@0
|
39
|
max@0
|
40
|
max@0
|
41 template<typename eT>
|
max@0
|
42 arma_inline
|
max@0
|
43 diagview<eT>::diagview(Mat<eT>& in_m, const uword in_row_offset, const uword in_col_offset, const uword in_len)
|
max@0
|
44 : m(in_m)
|
max@0
|
45 , m_ptr(&in_m)
|
max@0
|
46 , row_offset(in_row_offset)
|
max@0
|
47 , col_offset(in_col_offset)
|
max@0
|
48 , n_rows(in_len)
|
max@0
|
49 , n_elem(in_len)
|
max@0
|
50 {
|
max@0
|
51 arma_extra_debug_sigprint();
|
max@0
|
52 }
|
max@0
|
53
|
max@0
|
54
|
max@0
|
55
|
max@0
|
56 //! set a diagonal of our matrix using a diagonal from a foreign matrix
|
max@0
|
57 template<typename eT>
|
max@0
|
58 inline
|
max@0
|
59 void
|
max@0
|
60 diagview<eT>::operator= (const diagview<eT>& x)
|
max@0
|
61 {
|
max@0
|
62 arma_extra_debug_sigprint();
|
max@0
|
63
|
max@0
|
64 diagview<eT>& t = *this;
|
max@0
|
65
|
max@0
|
66 arma_debug_check( (t.n_elem != x.n_elem), "diagview: diagonals have incompatible lengths");
|
max@0
|
67
|
max@0
|
68 Mat<eT>& t_m = *(t.m_ptr);
|
max@0
|
69 const Mat<eT>& x_m = x.m;
|
max@0
|
70
|
max@0
|
71 if(&t_m != &x_m)
|
max@0
|
72 {
|
max@0
|
73 const uword t_n_elem = t.n_elem;
|
max@0
|
74 const uword t_row_offset = t.row_offset;
|
max@0
|
75 const uword t_col_offset = t.col_offset;
|
max@0
|
76
|
max@0
|
77 const uword x_row_offset = x.row_offset;
|
max@0
|
78 const uword x_col_offset = x.col_offset;
|
max@0
|
79
|
max@0
|
80 uword i,j;
|
max@0
|
81 for(i=0, j=1; j < t_n_elem; i+=2, j+=2)
|
max@0
|
82 {
|
max@0
|
83 const eT tmp_i = x_m.at(i + x_row_offset, i + x_col_offset);
|
max@0
|
84 const eT tmp_j = x_m.at(j + x_row_offset, j + x_col_offset);
|
max@0
|
85
|
max@0
|
86 t_m.at(i + t_row_offset, i + t_col_offset) = tmp_i;
|
max@0
|
87 t_m.at(j + t_row_offset, j + t_col_offset) = tmp_j;
|
max@0
|
88 }
|
max@0
|
89
|
max@0
|
90 if(i < t_n_elem)
|
max@0
|
91 {
|
max@0
|
92 t_m.at(i + t_row_offset, i + t_col_offset) = x_m.at(i + x_row_offset, i + x_col_offset);
|
max@0
|
93 }
|
max@0
|
94 }
|
max@0
|
95 else
|
max@0
|
96 {
|
max@0
|
97 const Mat<eT> tmp = x;
|
max@0
|
98
|
max@0
|
99 (*this).operator=(tmp);
|
max@0
|
100 }
|
max@0
|
101 }
|
max@0
|
102
|
max@0
|
103
|
max@0
|
104
|
max@0
|
105 template<typename eT>
|
max@0
|
106 inline
|
max@0
|
107 void
|
max@0
|
108 diagview<eT>::operator+=(const eT val)
|
max@0
|
109 {
|
max@0
|
110 arma_extra_debug_sigprint();
|
max@0
|
111
|
max@0
|
112 Mat<eT>& t_m = (*m_ptr);
|
max@0
|
113
|
max@0
|
114 const uword t_n_elem = n_elem;
|
max@0
|
115 const uword t_row_offset = row_offset;
|
max@0
|
116 const uword t_col_offset = col_offset;
|
max@0
|
117
|
max@0
|
118 for(uword i=0; i<t_n_elem; ++i)
|
max@0
|
119 {
|
max@0
|
120 t_m.at( i + t_row_offset, i + t_col_offset) += val;
|
max@0
|
121 }
|
max@0
|
122 }
|
max@0
|
123
|
max@0
|
124
|
max@0
|
125
|
max@0
|
126 template<typename eT>
|
max@0
|
127 inline
|
max@0
|
128 void
|
max@0
|
129 diagview<eT>::operator-=(const eT val)
|
max@0
|
130 {
|
max@0
|
131 arma_extra_debug_sigprint();
|
max@0
|
132
|
max@0
|
133 Mat<eT>& t_m = (*m_ptr);
|
max@0
|
134
|
max@0
|
135 const uword t_n_elem = n_elem;
|
max@0
|
136 const uword t_row_offset = row_offset;
|
max@0
|
137 const uword t_col_offset = col_offset;
|
max@0
|
138
|
max@0
|
139 for(uword i=0; i<t_n_elem; ++i)
|
max@0
|
140 {
|
max@0
|
141 t_m.at( i + t_row_offset, i + t_col_offset) -= val;
|
max@0
|
142 }
|
max@0
|
143 }
|
max@0
|
144
|
max@0
|
145
|
max@0
|
146
|
max@0
|
147 template<typename eT>
|
max@0
|
148 inline
|
max@0
|
149 void
|
max@0
|
150 diagview<eT>::operator*=(const eT val)
|
max@0
|
151 {
|
max@0
|
152 arma_extra_debug_sigprint();
|
max@0
|
153
|
max@0
|
154 Mat<eT>& t_m = (*m_ptr);
|
max@0
|
155
|
max@0
|
156 const uword t_n_elem = n_elem;
|
max@0
|
157 const uword t_row_offset = row_offset;
|
max@0
|
158 const uword t_col_offset = col_offset;
|
max@0
|
159
|
max@0
|
160 for(uword i=0; i<t_n_elem; ++i)
|
max@0
|
161 {
|
max@0
|
162 t_m.at( i + t_row_offset, i + t_col_offset) *= val;
|
max@0
|
163 }
|
max@0
|
164 }
|
max@0
|
165
|
max@0
|
166
|
max@0
|
167
|
max@0
|
168 template<typename eT>
|
max@0
|
169 inline
|
max@0
|
170 void
|
max@0
|
171 diagview<eT>::operator/=(const eT val)
|
max@0
|
172 {
|
max@0
|
173 arma_extra_debug_sigprint();
|
max@0
|
174
|
max@0
|
175 Mat<eT>& t_m = (*m_ptr);
|
max@0
|
176
|
max@0
|
177 const uword t_n_elem = n_elem;
|
max@0
|
178 const uword t_row_offset = row_offset;
|
max@0
|
179 const uword t_col_offset = col_offset;
|
max@0
|
180
|
max@0
|
181 for(uword i=0; i<t_n_elem; ++i)
|
max@0
|
182 {
|
max@0
|
183 t_m.at( i + t_row_offset, i + t_col_offset) /= val;
|
max@0
|
184 }
|
max@0
|
185 }
|
max@0
|
186
|
max@0
|
187
|
max@0
|
188
|
max@0
|
189 //! set a diagonal of our matrix using data from a foreign object
|
max@0
|
190 template<typename eT>
|
max@0
|
191 template<typename T1>
|
max@0
|
192 inline
|
max@0
|
193 void
|
max@0
|
194 diagview<eT>::operator= (const Base<eT,T1>& o)
|
max@0
|
195 {
|
max@0
|
196 arma_extra_debug_sigprint();
|
max@0
|
197
|
max@0
|
198 const unwrap<T1> tmp(o.get_ref());
|
max@0
|
199 const Mat<eT>& x = tmp.M;
|
max@0
|
200
|
max@0
|
201 diagview<eT>& t = *this;
|
max@0
|
202
|
max@0
|
203 arma_debug_check
|
max@0
|
204 (
|
max@0
|
205 ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ),
|
max@0
|
206 "diagview: given object has incompatible size"
|
max@0
|
207 );
|
max@0
|
208
|
max@0
|
209 Mat<eT>& t_m = *(t.m_ptr);
|
max@0
|
210
|
max@0
|
211 const uword t_n_elem = t.n_elem;
|
max@0
|
212 const uword t_row_offset = t.row_offset;
|
max@0
|
213 const uword t_col_offset = t.col_offset;
|
max@0
|
214
|
max@0
|
215 const eT* x_mem = x.memptr();
|
max@0
|
216
|
max@0
|
217 uword i,j;
|
max@0
|
218 for(i=0, j=1; j < t_n_elem; i+=2, j+=2)
|
max@0
|
219 {
|
max@0
|
220 const eT tmp_i = x_mem[i];
|
max@0
|
221 const eT tmp_j = x_mem[j];
|
max@0
|
222
|
max@0
|
223 t_m.at( i + t_row_offset, i + t_col_offset) = tmp_i;
|
max@0
|
224 t_m.at( j + t_row_offset, j + t_col_offset) = tmp_j;
|
max@0
|
225 }
|
max@0
|
226
|
max@0
|
227 if(i < t_n_elem)
|
max@0
|
228 {
|
max@0
|
229 t_m.at( i + t_row_offset, i + t_col_offset) = x_mem[i];
|
max@0
|
230 }
|
max@0
|
231 }
|
max@0
|
232
|
max@0
|
233
|
max@0
|
234
|
max@0
|
235 template<typename eT>
|
max@0
|
236 template<typename T1>
|
max@0
|
237 inline
|
max@0
|
238 void
|
max@0
|
239 diagview<eT>::operator+=(const Base<eT,T1>& o)
|
max@0
|
240 {
|
max@0
|
241 arma_extra_debug_sigprint();
|
max@0
|
242
|
max@0
|
243 const unwrap<T1> tmp(o.get_ref());
|
max@0
|
244 const Mat<eT>& x = tmp.M;
|
max@0
|
245
|
max@0
|
246 diagview<eT>& t = *this;
|
max@0
|
247
|
max@0
|
248 arma_debug_check
|
max@0
|
249 (
|
max@0
|
250 ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ),
|
max@0
|
251 "diagview: given object has incompatible size"
|
max@0
|
252 );
|
max@0
|
253
|
max@0
|
254 Mat<eT>& t_m = *(t.m_ptr);
|
max@0
|
255
|
max@0
|
256 const uword t_n_elem = t.n_elem;
|
max@0
|
257 const uword t_row_offset = t.row_offset;
|
max@0
|
258 const uword t_col_offset = t.col_offset;
|
max@0
|
259
|
max@0
|
260 const eT* x_mem = x.memptr();
|
max@0
|
261
|
max@0
|
262 uword i,j;
|
max@0
|
263 for(i=0, j=1; j < t_n_elem; i+=2, j+=2)
|
max@0
|
264 {
|
max@0
|
265 const eT tmp_i = x_mem[i];
|
max@0
|
266 const eT tmp_j = x_mem[j];
|
max@0
|
267
|
max@0
|
268 t_m.at( i + t_row_offset, i + t_col_offset) += tmp_i;
|
max@0
|
269 t_m.at( j + t_row_offset, j + t_col_offset) += tmp_j;
|
max@0
|
270 }
|
max@0
|
271
|
max@0
|
272 if(i < t_n_elem)
|
max@0
|
273 {
|
max@0
|
274 t_m.at( i + t_row_offset, i + t_col_offset) += x_mem[i];
|
max@0
|
275 }
|
max@0
|
276 }
|
max@0
|
277
|
max@0
|
278
|
max@0
|
279
|
max@0
|
280 template<typename eT>
|
max@0
|
281 template<typename T1>
|
max@0
|
282 inline
|
max@0
|
283 void
|
max@0
|
284 diagview<eT>::operator-=(const Base<eT,T1>& o)
|
max@0
|
285 {
|
max@0
|
286 arma_extra_debug_sigprint();
|
max@0
|
287
|
max@0
|
288 const unwrap<T1> tmp(o.get_ref());
|
max@0
|
289 const Mat<eT>& x = tmp.M;
|
max@0
|
290
|
max@0
|
291 diagview<eT>& t = *this;
|
max@0
|
292
|
max@0
|
293 arma_debug_check
|
max@0
|
294 (
|
max@0
|
295 ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ),
|
max@0
|
296 "diagview: given object has incompatible size"
|
max@0
|
297 );
|
max@0
|
298
|
max@0
|
299 Mat<eT>& t_m = *(t.m_ptr);
|
max@0
|
300
|
max@0
|
301 const uword t_n_elem = t.n_elem;
|
max@0
|
302 const uword t_row_offset = t.row_offset;
|
max@0
|
303 const uword t_col_offset = t.col_offset;
|
max@0
|
304
|
max@0
|
305 const eT* x_mem = x.memptr();
|
max@0
|
306
|
max@0
|
307 uword i,j;
|
max@0
|
308 for(i=0, j=1; j < t_n_elem; i+=2, j+=2)
|
max@0
|
309 {
|
max@0
|
310 const eT tmp_i = x_mem[i];
|
max@0
|
311 const eT tmp_j = x_mem[j];
|
max@0
|
312
|
max@0
|
313 t_m.at( i + t_row_offset, i + t_col_offset) -= tmp_i;
|
max@0
|
314 t_m.at( j + t_row_offset, j + t_col_offset) -= tmp_j;
|
max@0
|
315 }
|
max@0
|
316
|
max@0
|
317 if(i < t_n_elem)
|
max@0
|
318 {
|
max@0
|
319 t_m.at( i + t_row_offset, i + t_col_offset) -= x_mem[i];
|
max@0
|
320 }
|
max@0
|
321 }
|
max@0
|
322
|
max@0
|
323
|
max@0
|
324
|
max@0
|
325 template<typename eT>
|
max@0
|
326 template<typename T1>
|
max@0
|
327 inline
|
max@0
|
328 void
|
max@0
|
329 diagview<eT>::operator%=(const Base<eT,T1>& o)
|
max@0
|
330 {
|
max@0
|
331 arma_extra_debug_sigprint();
|
max@0
|
332
|
max@0
|
333 const unwrap<T1> tmp(o.get_ref());
|
max@0
|
334 const Mat<eT>& x = tmp.M;
|
max@0
|
335
|
max@0
|
336 diagview<eT>& t = *this;
|
max@0
|
337
|
max@0
|
338 arma_debug_check
|
max@0
|
339 (
|
max@0
|
340 ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ),
|
max@0
|
341 "diagview: given object has incompatible size"
|
max@0
|
342 );
|
max@0
|
343
|
max@0
|
344 Mat<eT>& t_m = *(t.m_ptr);
|
max@0
|
345
|
max@0
|
346 const uword t_n_elem = t.n_elem;
|
max@0
|
347 const uword t_row_offset = t.row_offset;
|
max@0
|
348 const uword t_col_offset = t.col_offset;
|
max@0
|
349
|
max@0
|
350 const eT* x_mem = x.memptr();
|
max@0
|
351
|
max@0
|
352 uword i,j;
|
max@0
|
353 for(i=0, j=1; j < t_n_elem; i+=2, j+=2)
|
max@0
|
354 {
|
max@0
|
355 const eT tmp_i = x_mem[i];
|
max@0
|
356 const eT tmp_j = x_mem[j];
|
max@0
|
357
|
max@0
|
358 t_m.at( i + t_row_offset, i + t_col_offset) *= tmp_i;
|
max@0
|
359 t_m.at( j + t_row_offset, j + t_col_offset) *= tmp_j;
|
max@0
|
360 }
|
max@0
|
361
|
max@0
|
362 if(i < t_n_elem)
|
max@0
|
363 {
|
max@0
|
364 t_m.at( i + t_row_offset, i + t_col_offset) *= x_mem[i];
|
max@0
|
365 }
|
max@0
|
366 }
|
max@0
|
367
|
max@0
|
368
|
max@0
|
369
|
max@0
|
370 template<typename eT>
|
max@0
|
371 template<typename T1>
|
max@0
|
372 inline
|
max@0
|
373 void
|
max@0
|
374 diagview<eT>::operator/=(const Base<eT,T1>& o)
|
max@0
|
375 {
|
max@0
|
376 arma_extra_debug_sigprint();
|
max@0
|
377
|
max@0
|
378 const unwrap<T1> tmp(o.get_ref());
|
max@0
|
379 const Mat<eT>& x = tmp.M;
|
max@0
|
380
|
max@0
|
381 diagview<eT>& t = *this;
|
max@0
|
382
|
max@0
|
383 arma_debug_check
|
max@0
|
384 (
|
max@0
|
385 ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ),
|
max@0
|
386 "diagview: given object has incompatible size"
|
max@0
|
387 );
|
max@0
|
388
|
max@0
|
389 Mat<eT>& t_m = *(t.m_ptr);
|
max@0
|
390
|
max@0
|
391 const uword t_n_elem = t.n_elem;
|
max@0
|
392 const uword t_row_offset = t.row_offset;
|
max@0
|
393 const uword t_col_offset = t.col_offset;
|
max@0
|
394
|
max@0
|
395 const eT* x_mem = x.memptr();
|
max@0
|
396
|
max@0
|
397 uword i,j;
|
max@0
|
398 for(i=0, j=1; j < t_n_elem; i+=2, j+=2)
|
max@0
|
399 {
|
max@0
|
400 const eT tmp_i = x_mem[i];
|
max@0
|
401 const eT tmp_j = x_mem[j];
|
max@0
|
402
|
max@0
|
403 t_m.at( i + t_row_offset, i + t_col_offset) /= tmp_i;
|
max@0
|
404 t_m.at( j + t_row_offset, j + t_col_offset) /= tmp_j;
|
max@0
|
405 }
|
max@0
|
406
|
max@0
|
407 if(i < t_n_elem)
|
max@0
|
408 {
|
max@0
|
409 t_m.at( i + t_row_offset, i + t_col_offset) /= x_mem[i];
|
max@0
|
410 }
|
max@0
|
411 }
|
max@0
|
412
|
max@0
|
413
|
max@0
|
414
|
max@0
|
415 //! extract a diagonal and store it as a column vector
|
max@0
|
416 template<typename eT>
|
max@0
|
417 inline
|
max@0
|
418 void
|
max@0
|
419 diagview<eT>::extract(Mat<eT>& out, const diagview<eT>& in)
|
max@0
|
420 {
|
max@0
|
421 arma_extra_debug_sigprint();
|
max@0
|
422
|
max@0
|
423 // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing;
|
max@0
|
424 // size setting and alias checking is done by either the Mat contructor or operator=()
|
max@0
|
425
|
max@0
|
426 const Mat<eT>& in_m = in.m;
|
max@0
|
427
|
max@0
|
428 const uword in_n_elem = in.n_elem;
|
max@0
|
429 const uword in_row_offset = in.row_offset;
|
max@0
|
430 const uword in_col_offset = in.col_offset;
|
max@0
|
431
|
max@0
|
432 eT* out_mem = out.memptr();
|
max@0
|
433
|
max@0
|
434 uword i,j;
|
max@0
|
435 for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
|
max@0
|
436 {
|
max@0
|
437 const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
438 const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
|
max@0
|
439
|
max@0
|
440 out_mem[i] = tmp_i;
|
max@0
|
441 out_mem[j] = tmp_j;
|
max@0
|
442 }
|
max@0
|
443
|
max@0
|
444 if(i < in_n_elem)
|
max@0
|
445 {
|
max@0
|
446 out_mem[i] = in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
447 }
|
max@0
|
448 }
|
max@0
|
449
|
max@0
|
450
|
max@0
|
451
|
max@0
|
452 //! X += Y.diag()
|
max@0
|
453 template<typename eT>
|
max@0
|
454 inline
|
max@0
|
455 void
|
max@0
|
456 diagview<eT>::plus_inplace(Mat<eT>& out, const diagview<eT>& in)
|
max@0
|
457 {
|
max@0
|
458 arma_extra_debug_sigprint();
|
max@0
|
459
|
max@0
|
460 arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "addition");
|
max@0
|
461
|
max@0
|
462 const Mat<eT>& in_m = in.m;
|
max@0
|
463
|
max@0
|
464 const uword in_n_elem = in.n_elem;
|
max@0
|
465 const uword in_row_offset = in.row_offset;
|
max@0
|
466 const uword in_col_offset = in.col_offset;
|
max@0
|
467
|
max@0
|
468 eT* out_mem = out.memptr();
|
max@0
|
469
|
max@0
|
470 uword i,j;
|
max@0
|
471 for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
|
max@0
|
472 {
|
max@0
|
473 const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
474 const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
|
max@0
|
475
|
max@0
|
476 out_mem[i] += tmp_i;
|
max@0
|
477 out_mem[j] += tmp_j;
|
max@0
|
478 }
|
max@0
|
479
|
max@0
|
480 if(i < in_n_elem)
|
max@0
|
481 {
|
max@0
|
482 out_mem[i] += in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
483 }
|
max@0
|
484 }
|
max@0
|
485
|
max@0
|
486
|
max@0
|
487
|
max@0
|
488 //! X -= Y.diag()
|
max@0
|
489 template<typename eT>
|
max@0
|
490 inline
|
max@0
|
491 void
|
max@0
|
492 diagview<eT>::minus_inplace(Mat<eT>& out, const diagview<eT>& in)
|
max@0
|
493 {
|
max@0
|
494 arma_extra_debug_sigprint();
|
max@0
|
495
|
max@0
|
496 arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "subtraction");
|
max@0
|
497
|
max@0
|
498 const Mat<eT>& in_m = in.m;
|
max@0
|
499
|
max@0
|
500 const uword in_n_elem = in.n_elem;
|
max@0
|
501 const uword in_row_offset = in.row_offset;
|
max@0
|
502 const uword in_col_offset = in.col_offset;
|
max@0
|
503
|
max@0
|
504 eT* out_mem = out.memptr();
|
max@0
|
505
|
max@0
|
506 uword i,j;
|
max@0
|
507 for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
|
max@0
|
508 {
|
max@0
|
509 const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
510 const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
|
max@0
|
511
|
max@0
|
512 out_mem[i] -= tmp_i;
|
max@0
|
513 out_mem[j] -= tmp_j;
|
max@0
|
514 }
|
max@0
|
515
|
max@0
|
516 if(i < in_n_elem)
|
max@0
|
517 {
|
max@0
|
518 out_mem[i] -= in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
519 }
|
max@0
|
520 }
|
max@0
|
521
|
max@0
|
522
|
max@0
|
523
|
max@0
|
524 //! X %= Y.diag()
|
max@0
|
525 template<typename eT>
|
max@0
|
526 inline
|
max@0
|
527 void
|
max@0
|
528 diagview<eT>::schur_inplace(Mat<eT>& out, const diagview<eT>& in)
|
max@0
|
529 {
|
max@0
|
530 arma_extra_debug_sigprint();
|
max@0
|
531
|
max@0
|
532 arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise multiplication");
|
max@0
|
533
|
max@0
|
534 const Mat<eT>& in_m = in.m;
|
max@0
|
535
|
max@0
|
536 const uword in_n_elem = in.n_elem;
|
max@0
|
537 const uword in_row_offset = in.row_offset;
|
max@0
|
538 const uword in_col_offset = in.col_offset;
|
max@0
|
539
|
max@0
|
540 eT* out_mem = out.memptr();
|
max@0
|
541
|
max@0
|
542 uword i,j;
|
max@0
|
543 for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
|
max@0
|
544 {
|
max@0
|
545 const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
546 const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
|
max@0
|
547
|
max@0
|
548 out_mem[i] *= tmp_i;
|
max@0
|
549 out_mem[j] *= tmp_j;
|
max@0
|
550 }
|
max@0
|
551
|
max@0
|
552 if(i < in_n_elem)
|
max@0
|
553 {
|
max@0
|
554 out_mem[i] *= in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
555 }
|
max@0
|
556 }
|
max@0
|
557
|
max@0
|
558
|
max@0
|
559
|
max@0
|
560 //! X /= Y.diag()
|
max@0
|
561 template<typename eT>
|
max@0
|
562 inline
|
max@0
|
563 void
|
max@0
|
564 diagview<eT>::div_inplace(Mat<eT>& out, const diagview<eT>& in)
|
max@0
|
565 {
|
max@0
|
566 arma_extra_debug_sigprint();
|
max@0
|
567
|
max@0
|
568 arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise division");
|
max@0
|
569
|
max@0
|
570 const Mat<eT>& in_m = in.m;
|
max@0
|
571
|
max@0
|
572 const uword in_n_elem = in.n_elem;
|
max@0
|
573 const uword in_row_offset = in.row_offset;
|
max@0
|
574 const uword in_col_offset = in.col_offset;
|
max@0
|
575
|
max@0
|
576 eT* out_mem = out.memptr();
|
max@0
|
577
|
max@0
|
578 uword i,j;
|
max@0
|
579 for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
|
max@0
|
580 {
|
max@0
|
581 const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
582 const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
|
max@0
|
583
|
max@0
|
584 out_mem[i] /= tmp_i;
|
max@0
|
585 out_mem[j] /= tmp_j;
|
max@0
|
586 }
|
max@0
|
587
|
max@0
|
588 if(i < in_n_elem)
|
max@0
|
589 {
|
max@0
|
590 out_mem[i] /= in_m.at( i + in_row_offset, i + in_col_offset );
|
max@0
|
591 }
|
max@0
|
592 }
|
max@0
|
593
|
max@0
|
594
|
max@0
|
595
|
max@0
|
596 template<typename eT>
|
max@0
|
597 arma_inline
|
max@0
|
598 eT&
|
max@0
|
599 diagview<eT>::operator[](const uword i)
|
max@0
|
600 {
|
max@0
|
601 return (*m_ptr).at(i+row_offset, i+col_offset);
|
max@0
|
602 }
|
max@0
|
603
|
max@0
|
604
|
max@0
|
605
|
max@0
|
606 template<typename eT>
|
max@0
|
607 arma_inline
|
max@0
|
608 eT
|
max@0
|
609 diagview<eT>::operator[](const uword i) const
|
max@0
|
610 {
|
max@0
|
611 return m.at(i+row_offset, i+col_offset);
|
max@0
|
612 }
|
max@0
|
613
|
max@0
|
614
|
max@0
|
615
|
max@0
|
616 template<typename eT>
|
max@0
|
617 arma_inline
|
max@0
|
618 eT&
|
max@0
|
619 diagview<eT>::at(const uword i)
|
max@0
|
620 {
|
max@0
|
621 return (*m_ptr).at(i+row_offset, i+col_offset);
|
max@0
|
622 }
|
max@0
|
623
|
max@0
|
624
|
max@0
|
625
|
max@0
|
626 template<typename eT>
|
max@0
|
627 arma_inline
|
max@0
|
628 eT
|
max@0
|
629 diagview<eT>::at(const uword i) const
|
max@0
|
630 {
|
max@0
|
631 return m.at(i+row_offset, i+col_offset);
|
max@0
|
632 }
|
max@0
|
633
|
max@0
|
634
|
max@0
|
635
|
max@0
|
636 template<typename eT>
|
max@0
|
637 arma_inline
|
max@0
|
638 eT&
|
max@0
|
639 diagview<eT>::operator()(const uword i)
|
max@0
|
640 {
|
max@0
|
641 arma_debug_check( (i >= n_elem), "diagview::operator(): out of bounds" );
|
max@0
|
642
|
max@0
|
643 return (*m_ptr).at(i+row_offset, i+col_offset);
|
max@0
|
644 }
|
max@0
|
645
|
max@0
|
646
|
max@0
|
647
|
max@0
|
648 template<typename eT>
|
max@0
|
649 arma_inline
|
max@0
|
650 eT
|
max@0
|
651 diagview<eT>::operator()(const uword i) const
|
max@0
|
652 {
|
max@0
|
653 arma_debug_check( (i >= n_elem), "diagview::operator(): out of bounds" );
|
max@0
|
654
|
max@0
|
655 return m.at(i+row_offset, i+col_offset);
|
max@0
|
656 }
|
max@0
|
657
|
max@0
|
658
|
max@0
|
659
|
max@0
|
660 template<typename eT>
|
max@0
|
661 arma_inline
|
max@0
|
662 eT&
|
max@0
|
663 diagview<eT>::at(const uword row, const uword col)
|
max@0
|
664 {
|
max@0
|
665 return (*m_ptr).at(row+row_offset, row+col_offset);
|
max@0
|
666 }
|
max@0
|
667
|
max@0
|
668
|
max@0
|
669
|
max@0
|
670 template<typename eT>
|
max@0
|
671 arma_inline
|
max@0
|
672 eT
|
max@0
|
673 diagview<eT>::at(const uword row, const uword col) const
|
max@0
|
674 {
|
max@0
|
675 return m.at(row+row_offset, row+col_offset);
|
max@0
|
676 }
|
max@0
|
677
|
max@0
|
678
|
max@0
|
679
|
max@0
|
680 template<typename eT>
|
max@0
|
681 arma_inline
|
max@0
|
682 eT&
|
max@0
|
683 diagview<eT>::operator()(const uword row, const uword col)
|
max@0
|
684 {
|
max@0
|
685 arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" );
|
max@0
|
686
|
max@0
|
687 return (*m_ptr).at(row+row_offset, row+col_offset);
|
max@0
|
688 }
|
max@0
|
689
|
max@0
|
690
|
max@0
|
691
|
max@0
|
692 template<typename eT>
|
max@0
|
693 arma_inline
|
max@0
|
694 eT
|
max@0
|
695 diagview<eT>::operator()(const uword row, const uword col) const
|
max@0
|
696 {
|
max@0
|
697 arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" );
|
max@0
|
698
|
max@0
|
699 return m.at(row+row_offset, row+col_offset);
|
max@0
|
700 }
|
max@0
|
701
|
max@0
|
702
|
max@0
|
703
|
max@0
|
704 template<typename eT>
|
max@0
|
705 inline
|
max@0
|
706 void
|
max@0
|
707 diagview<eT>::fill(const eT val)
|
max@0
|
708 {
|
max@0
|
709 arma_extra_debug_sigprint();
|
max@0
|
710
|
max@0
|
711 Mat<eT>& x = (*m_ptr);
|
max@0
|
712
|
max@0
|
713 for(uword i=0; i<n_elem; ++i)
|
max@0
|
714 {
|
max@0
|
715 x.at(i+row_offset, i+col_offset) = val;
|
max@0
|
716 }
|
max@0
|
717 }
|
max@0
|
718
|
max@0
|
719
|
max@0
|
720
|
max@0
|
721 template<typename eT>
|
max@0
|
722 inline
|
max@0
|
723 void
|
max@0
|
724 diagview<eT>::zeros()
|
max@0
|
725 {
|
max@0
|
726 arma_extra_debug_sigprint();
|
max@0
|
727
|
max@0
|
728 (*this).fill(eT(0));
|
max@0
|
729 }
|
max@0
|
730
|
max@0
|
731
|
max@0
|
732
|
max@0
|
733 template<typename eT>
|
max@0
|
734 inline
|
max@0
|
735 void
|
max@0
|
736 diagview<eT>::ones()
|
max@0
|
737 {
|
max@0
|
738 arma_extra_debug_sigprint();
|
max@0
|
739
|
max@0
|
740 (*this).fill(eT(1));
|
max@0
|
741 }
|
max@0
|
742
|
max@0
|
743
|
max@0
|
744
|
max@0
|
745 //! @}
|