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 Mat
|
max@0
|
15 //! @{
|
max@0
|
16
|
max@0
|
17
|
max@0
|
18 template<typename eT>
|
max@0
|
19 inline
|
max@0
|
20 Mat<eT>::~Mat()
|
max@0
|
21 {
|
max@0
|
22 arma_extra_debug_sigprint_this(this);
|
max@0
|
23
|
max@0
|
24 if(mem_state == 0)
|
max@0
|
25 {
|
max@0
|
26 if(n_elem > arma_config::mat_prealloc)
|
max@0
|
27 {
|
max@0
|
28 #if defined(ARMA_USE_TBB_ALLOC)
|
max@0
|
29 scalable_free((void *)(mem));
|
max@0
|
30 #else
|
max@0
|
31 delete [] mem;
|
max@0
|
32 #endif
|
max@0
|
33 }
|
max@0
|
34 }
|
max@0
|
35
|
max@0
|
36 if(arma_config::debug == true)
|
max@0
|
37 {
|
max@0
|
38 // try to expose buggy user code that accesses deleted objects
|
max@0
|
39 access::rw(n_rows) = 0;
|
max@0
|
40 access::rw(n_cols) = 0;
|
max@0
|
41 access::rw(n_elem) = 0;
|
max@0
|
42 access::rw(mem) = 0;
|
max@0
|
43 }
|
max@0
|
44
|
max@0
|
45 arma_type_check(( is_supported_elem_type<eT>::value == false ));
|
max@0
|
46 }
|
max@0
|
47
|
max@0
|
48
|
max@0
|
49
|
max@0
|
50 template<typename eT>
|
max@0
|
51 inline
|
max@0
|
52 Mat<eT>::Mat()
|
max@0
|
53 : n_rows(0)
|
max@0
|
54 , n_cols(0)
|
max@0
|
55 , n_elem(0)
|
max@0
|
56 , vec_state(0)
|
max@0
|
57 , mem_state(0)
|
max@0
|
58 , mem()
|
max@0
|
59 {
|
max@0
|
60 arma_extra_debug_sigprint_this(this);
|
max@0
|
61 }
|
max@0
|
62
|
max@0
|
63
|
max@0
|
64
|
max@0
|
65 //! construct the matrix to have user specified dimensions
|
max@0
|
66 template<typename eT>
|
max@0
|
67 inline
|
max@0
|
68 Mat<eT>::Mat(const uword in_n_rows, const uword in_n_cols)
|
max@0
|
69 : n_rows(in_n_rows)
|
max@0
|
70 , n_cols(in_n_cols)
|
max@0
|
71 , n_elem(in_n_rows*in_n_cols)
|
max@0
|
72 , vec_state(0)
|
max@0
|
73 , mem_state(0)
|
max@0
|
74 , mem()
|
max@0
|
75 {
|
max@0
|
76 arma_extra_debug_sigprint_this(this);
|
max@0
|
77
|
max@0
|
78 init_cold();
|
max@0
|
79 }
|
max@0
|
80
|
max@0
|
81
|
max@0
|
82
|
max@0
|
83 template<typename eT>
|
max@0
|
84 inline
|
max@0
|
85 void
|
max@0
|
86 Mat<eT>::init_cold()
|
max@0
|
87 {
|
max@0
|
88 arma_extra_debug_sigprint( arma_boost::format("n_rows = %d, n_cols = %d") % n_rows % n_cols );
|
max@0
|
89
|
max@0
|
90 // ensure that n_elem can hold the result of (n_rows * n_cols)
|
max@0
|
91
|
max@0
|
92 arma_debug_check
|
max@0
|
93 (
|
max@0
|
94 (
|
max@0
|
95 ( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) )
|
max@0
|
96 ? ( (float(n_rows) * float(n_cols)) > float(ARMA_MAX_UWORD) )
|
max@0
|
97 : false
|
max@0
|
98 ),
|
max@0
|
99 "Mat::init(): requested size is too large"
|
max@0
|
100 );
|
max@0
|
101
|
max@0
|
102 if(n_elem <= arma_config::mat_prealloc)
|
max@0
|
103 {
|
max@0
|
104 access::rw(mem) = mem_local;
|
max@0
|
105 }
|
max@0
|
106 else
|
max@0
|
107 {
|
max@0
|
108 arma_extra_debug_print("Mat::init(): allocating memory");
|
max@0
|
109
|
max@0
|
110 #if defined(ARMA_USE_TBB_ALLOC)
|
max@0
|
111 access::rw(mem) = (eT *) scalable_malloc(sizeof(eT)*n_elem);
|
max@0
|
112 #else
|
max@0
|
113 access::rw(mem) = new(std::nothrow) eT[n_elem];
|
max@0
|
114 #endif
|
max@0
|
115
|
max@0
|
116 arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" );
|
max@0
|
117 }
|
max@0
|
118 }
|
max@0
|
119
|
max@0
|
120
|
max@0
|
121
|
max@0
|
122 //! internal matrix construction; if the requested size is small enough, memory from the stack is used. otherwise memory is allocated via 'new'
|
max@0
|
123 template<typename eT>
|
max@0
|
124 inline
|
max@0
|
125 void
|
max@0
|
126 Mat<eT>::init_warm(uword in_n_rows, uword in_n_cols)
|
max@0
|
127 {
|
max@0
|
128 arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols = %d") % in_n_rows % in_n_cols );
|
max@0
|
129
|
max@0
|
130 if( (n_rows == in_n_rows) && (n_cols == in_n_cols) )
|
max@0
|
131 {
|
max@0
|
132 return;
|
max@0
|
133 }
|
max@0
|
134
|
max@0
|
135 bool err_state = false;
|
max@0
|
136 char* err_msg = 0;
|
max@0
|
137
|
max@0
|
138 const uhword t_vec_state = vec_state;
|
max@0
|
139 const uhword t_mem_state = mem_state;
|
max@0
|
140
|
max@0
|
141 arma_debug_set_error
|
max@0
|
142 (
|
max@0
|
143 err_state,
|
max@0
|
144 err_msg,
|
max@0
|
145 (t_mem_state == 3),
|
max@0
|
146 "Mat::init(): size is fixed and hence cannot be changed"
|
max@0
|
147 );
|
max@0
|
148
|
max@0
|
149 if(t_vec_state > 0)
|
max@0
|
150 {
|
max@0
|
151 if( (in_n_rows == 0) && (in_n_cols == 0) )
|
max@0
|
152 {
|
max@0
|
153 if(t_vec_state == 1)
|
max@0
|
154 {
|
max@0
|
155 in_n_cols = 1;
|
max@0
|
156 }
|
max@0
|
157 else
|
max@0
|
158 if(t_vec_state == 2)
|
max@0
|
159 {
|
max@0
|
160 in_n_rows = 1;
|
max@0
|
161 }
|
max@0
|
162 }
|
max@0
|
163 else
|
max@0
|
164 {
|
max@0
|
165 arma_debug_set_error
|
max@0
|
166 (
|
max@0
|
167 err_state,
|
max@0
|
168 err_msg,
|
max@0
|
169 ( ((t_vec_state == 1) && (in_n_cols != 1)) || ((t_vec_state == 2) && (in_n_rows != 1)) ),
|
max@0
|
170 "Mat::init(): object is a vector; requested size is not compatible"
|
max@0
|
171 );
|
max@0
|
172 }
|
max@0
|
173 }
|
max@0
|
174
|
max@0
|
175 // ensure that n_elem can hold the result of (n_rows * n_cols)
|
max@0
|
176
|
max@0
|
177 arma_debug_set_error
|
max@0
|
178 (
|
max@0
|
179 err_state,
|
max@0
|
180 err_msg,
|
max@0
|
181 (
|
max@0
|
182 ( (in_n_rows > ARMA_MAX_UHWORD) || (in_n_cols > ARMA_MAX_UHWORD) )
|
max@0
|
183 ? ( (float(in_n_rows) * float(in_n_cols)) > float(ARMA_MAX_UWORD) )
|
max@0
|
184 : false
|
max@0
|
185 ),
|
max@0
|
186 "Mat::init(): requested size is too large"
|
max@0
|
187 );
|
max@0
|
188
|
max@0
|
189 arma_debug_check(err_state, err_msg);
|
max@0
|
190
|
max@0
|
191 const uword old_n_elem = n_elem;
|
max@0
|
192 const uword new_n_elem = in_n_rows * in_n_cols;
|
max@0
|
193
|
max@0
|
194 if(old_n_elem == new_n_elem)
|
max@0
|
195 {
|
max@0
|
196 arma_extra_debug_print("Mat::init(): reusing memory");
|
max@0
|
197
|
max@0
|
198 access::rw(n_rows) = in_n_rows;
|
max@0
|
199 access::rw(n_cols) = in_n_cols;
|
max@0
|
200 }
|
max@0
|
201 else
|
max@0
|
202 {
|
max@0
|
203 arma_debug_check
|
max@0
|
204 (
|
max@0
|
205 (t_mem_state == 2),
|
max@0
|
206 "Mat::init(): mismatch between size of auxiliary memory and requested size"
|
max@0
|
207 );
|
max@0
|
208
|
max@0
|
209 if(t_mem_state == 0)
|
max@0
|
210 {
|
max@0
|
211 if(old_n_elem > arma_config::mat_prealloc)
|
max@0
|
212 {
|
max@0
|
213 arma_extra_debug_print("Mat::init(): freeing memory");
|
max@0
|
214
|
max@0
|
215 #if defined(ARMA_USE_TBB_ALLOC)
|
max@0
|
216 scalable_free((void *)(mem));
|
max@0
|
217 #else
|
max@0
|
218 delete [] mem;
|
max@0
|
219 #endif
|
max@0
|
220 }
|
max@0
|
221 }
|
max@0
|
222
|
max@0
|
223
|
max@0
|
224 if(new_n_elem <= arma_config::mat_prealloc)
|
max@0
|
225 {
|
max@0
|
226 access::rw(mem) = mem_local;
|
max@0
|
227 }
|
max@0
|
228 else
|
max@0
|
229 {
|
max@0
|
230 arma_extra_debug_print("Mat::init(): allocating memory");
|
max@0
|
231
|
max@0
|
232 #if defined(ARMA_USE_TBB_ALLOC)
|
max@0
|
233 access::rw(mem) = (eT *) scalable_malloc(sizeof(eT)*new_n_elem);
|
max@0
|
234 #else
|
max@0
|
235 access::rw(mem) = new(std::nothrow) eT[new_n_elem];
|
max@0
|
236 #endif
|
max@0
|
237
|
max@0
|
238 arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" );
|
max@0
|
239 }
|
max@0
|
240
|
max@0
|
241 access::rw(n_rows) = in_n_rows;
|
max@0
|
242 access::rw(n_cols) = in_n_cols;
|
max@0
|
243 access::rw(n_elem) = new_n_elem;
|
max@0
|
244 access::rw(mem_state) = 0;
|
max@0
|
245 }
|
max@0
|
246 }
|
max@0
|
247
|
max@0
|
248
|
max@0
|
249
|
max@0
|
250 //! create the matrix from a textual description
|
max@0
|
251 template<typename eT>
|
max@0
|
252 inline
|
max@0
|
253 Mat<eT>::Mat(const char* text)
|
max@0
|
254 : n_rows(0)
|
max@0
|
255 , n_cols(0)
|
max@0
|
256 , n_elem(0)
|
max@0
|
257 , vec_state(0)
|
max@0
|
258 , mem_state(0)
|
max@0
|
259 , mem()
|
max@0
|
260 {
|
max@0
|
261 arma_extra_debug_sigprint_this(this);
|
max@0
|
262
|
max@0
|
263 init( std::string(text) );
|
max@0
|
264 }
|
max@0
|
265
|
max@0
|
266
|
max@0
|
267
|
max@0
|
268 //! create the matrix from a textual description
|
max@0
|
269 template<typename eT>
|
max@0
|
270 inline
|
max@0
|
271 const Mat<eT>&
|
max@0
|
272 Mat<eT>::operator=(const char* text)
|
max@0
|
273 {
|
max@0
|
274 arma_extra_debug_sigprint();
|
max@0
|
275
|
max@0
|
276 init( std::string(text) );
|
max@0
|
277 return *this;
|
max@0
|
278 }
|
max@0
|
279
|
max@0
|
280
|
max@0
|
281
|
max@0
|
282 //! create the matrix from a textual description
|
max@0
|
283 template<typename eT>
|
max@0
|
284 inline
|
max@0
|
285 Mat<eT>::Mat(const std::string& text)
|
max@0
|
286 : n_rows(0)
|
max@0
|
287 , n_cols(0)
|
max@0
|
288 , n_elem(0)
|
max@0
|
289 , vec_state(0)
|
max@0
|
290 , mem_state(0)
|
max@0
|
291 , mem()
|
max@0
|
292 {
|
max@0
|
293 arma_extra_debug_sigprint_this(this);
|
max@0
|
294
|
max@0
|
295 init(text);
|
max@0
|
296 }
|
max@0
|
297
|
max@0
|
298
|
max@0
|
299
|
max@0
|
300 //! create the matrix from a textual description
|
max@0
|
301 template<typename eT>
|
max@0
|
302 inline
|
max@0
|
303 const Mat<eT>&
|
max@0
|
304 Mat<eT>::operator=(const std::string& text)
|
max@0
|
305 {
|
max@0
|
306 arma_extra_debug_sigprint();
|
max@0
|
307
|
max@0
|
308 init(text);
|
max@0
|
309 return *this;
|
max@0
|
310 }
|
max@0
|
311
|
max@0
|
312
|
max@0
|
313
|
max@0
|
314 //! internal function to create the matrix from a textual description
|
max@0
|
315 template<typename eT>
|
max@0
|
316 inline
|
max@0
|
317 void
|
max@0
|
318 Mat<eT>::init(const std::string& text)
|
max@0
|
319 {
|
max@0
|
320 arma_extra_debug_sigprint();
|
max@0
|
321
|
max@0
|
322 //
|
max@0
|
323 // work out the size
|
max@0
|
324
|
max@0
|
325 uword t_n_rows = 0;
|
max@0
|
326 uword t_n_cols = 0;
|
max@0
|
327
|
max@0
|
328 bool t_n_cols_found = false;
|
max@0
|
329
|
max@0
|
330 std::string token;
|
max@0
|
331
|
max@0
|
332 std::string::size_type line_start = 0;
|
max@0
|
333 std::string::size_type line_end = 0;
|
max@0
|
334
|
max@0
|
335 while( line_start < text.length() )
|
max@0
|
336 {
|
max@0
|
337
|
max@0
|
338 line_end = text.find(';', line_start);
|
max@0
|
339
|
max@0
|
340 if(line_end == std::string::npos)
|
max@0
|
341 line_end = text.length()-1;
|
max@0
|
342
|
max@0
|
343 std::string::size_type line_len = line_end - line_start + 1;
|
max@0
|
344 std::stringstream line_stream( text.substr(line_start,line_len) );
|
max@0
|
345
|
max@0
|
346
|
max@0
|
347 uword line_n_cols = 0;
|
max@0
|
348 while(line_stream >> token)
|
max@0
|
349 {
|
max@0
|
350 ++line_n_cols;
|
max@0
|
351 }
|
max@0
|
352
|
max@0
|
353
|
max@0
|
354 if(line_n_cols > 0)
|
max@0
|
355 {
|
max@0
|
356 if(t_n_cols_found == false)
|
max@0
|
357 {
|
max@0
|
358 t_n_cols = line_n_cols;
|
max@0
|
359 t_n_cols_found = true;
|
max@0
|
360 }
|
max@0
|
361 else
|
max@0
|
362 arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent number of columns in given string");
|
max@0
|
363
|
max@0
|
364 ++t_n_rows;
|
max@0
|
365 }
|
max@0
|
366 line_start = line_end+1;
|
max@0
|
367
|
max@0
|
368 }
|
max@0
|
369
|
max@0
|
370 Mat<eT>& x = *this;
|
max@0
|
371 x.set_size(t_n_rows, t_n_cols);
|
max@0
|
372
|
max@0
|
373 line_start = 0;
|
max@0
|
374 line_end = 0;
|
max@0
|
375
|
max@0
|
376 uword row = 0;
|
max@0
|
377
|
max@0
|
378 while( line_start < text.length() )
|
max@0
|
379 {
|
max@0
|
380
|
max@0
|
381 line_end = text.find(';', line_start);
|
max@0
|
382
|
max@0
|
383 if(line_end == std::string::npos)
|
max@0
|
384 line_end = text.length()-1;
|
max@0
|
385
|
max@0
|
386 std::string::size_type line_len = line_end - line_start + 1;
|
max@0
|
387 std::stringstream line_stream( text.substr(line_start,line_len) );
|
max@0
|
388
|
max@0
|
389 // uword col = 0;
|
max@0
|
390 // while(line_stream >> token)
|
max@0
|
391 // {
|
max@0
|
392 // x.at(row,col) = strtod(token.c_str(), 0);
|
max@0
|
393 // ++col;
|
max@0
|
394 // }
|
max@0
|
395
|
max@0
|
396 uword col = 0;
|
max@0
|
397 eT val;
|
max@0
|
398 while(line_stream >> val)
|
max@0
|
399 {
|
max@0
|
400 x.at(row,col) = val;
|
max@0
|
401 ++col;
|
max@0
|
402 }
|
max@0
|
403
|
max@0
|
404 ++row;
|
max@0
|
405 line_start = line_end+1;
|
max@0
|
406 }
|
max@0
|
407
|
max@0
|
408 }
|
max@0
|
409
|
max@0
|
410
|
max@0
|
411
|
max@0
|
412 #if defined(ARMA_USE_CXX11)
|
max@0
|
413
|
max@0
|
414 template<typename eT>
|
max@0
|
415 inline
|
max@0
|
416 Mat<eT>::Mat(const std::initializer_list<eT>& list)
|
max@0
|
417 : n_rows(0)
|
max@0
|
418 , n_cols(0)
|
max@0
|
419 , n_elem(0)
|
max@0
|
420 , vec_state(0)
|
max@0
|
421 , mem_state(0)
|
max@0
|
422 , mem()
|
max@0
|
423 {
|
max@0
|
424 arma_extra_debug_sigprint_this(this);
|
max@0
|
425
|
max@0
|
426 init(list);
|
max@0
|
427 }
|
max@0
|
428
|
max@0
|
429
|
max@0
|
430
|
max@0
|
431 template<typename eT>
|
max@0
|
432 inline
|
max@0
|
433 const Mat<eT>&
|
max@0
|
434 Mat<eT>::operator=(const std::initializer_list<eT>& list)
|
max@0
|
435 {
|
max@0
|
436 arma_extra_debug_sigprint();
|
max@0
|
437
|
max@0
|
438 init(list);
|
max@0
|
439
|
max@0
|
440 return *this;
|
max@0
|
441 }
|
max@0
|
442
|
max@0
|
443 #endif
|
max@0
|
444
|
max@0
|
445
|
max@0
|
446
|
max@0
|
447 //! Set the matrix to be equal to the specified scalar.
|
max@0
|
448 //! NOTE: the size of the matrix will be 1x1
|
max@0
|
449 template<typename eT>
|
max@0
|
450 arma_inline
|
max@0
|
451 const Mat<eT>&
|
max@0
|
452 Mat<eT>::operator=(const eT val)
|
max@0
|
453 {
|
max@0
|
454 arma_extra_debug_sigprint();
|
max@0
|
455
|
max@0
|
456 init_warm(1,1);
|
max@0
|
457 access::rw(mem[0]) = val;
|
max@0
|
458 return *this;
|
max@0
|
459 }
|
max@0
|
460
|
max@0
|
461
|
max@0
|
462
|
max@0
|
463 //! In-place addition of a scalar to all elements of the matrix
|
max@0
|
464 template<typename eT>
|
max@0
|
465 arma_inline
|
max@0
|
466 const Mat<eT>&
|
max@0
|
467 Mat<eT>::operator+=(const eT val)
|
max@0
|
468 {
|
max@0
|
469 arma_extra_debug_sigprint();
|
max@0
|
470
|
max@0
|
471 arrayops::inplace_plus( memptr(), val, n_elem );
|
max@0
|
472
|
max@0
|
473 return *this;
|
max@0
|
474 }
|
max@0
|
475
|
max@0
|
476
|
max@0
|
477
|
max@0
|
478 //! In-place subtraction of a scalar from all elements of the matrix
|
max@0
|
479 template<typename eT>
|
max@0
|
480 arma_inline
|
max@0
|
481 const Mat<eT>&
|
max@0
|
482 Mat<eT>::operator-=(const eT val)
|
max@0
|
483 {
|
max@0
|
484 arma_extra_debug_sigprint();
|
max@0
|
485
|
max@0
|
486 arrayops::inplace_minus( memptr(), val, n_elem );
|
max@0
|
487
|
max@0
|
488 return *this;
|
max@0
|
489 }
|
max@0
|
490
|
max@0
|
491
|
max@0
|
492
|
max@0
|
493 //! In-place multiplication of all elements of the matrix with a scalar
|
max@0
|
494 template<typename eT>
|
max@0
|
495 arma_inline
|
max@0
|
496 const Mat<eT>&
|
max@0
|
497 Mat<eT>::operator*=(const eT val)
|
max@0
|
498 {
|
max@0
|
499 arma_extra_debug_sigprint();
|
max@0
|
500
|
max@0
|
501 arrayops::inplace_mul( memptr(), val, n_elem );
|
max@0
|
502
|
max@0
|
503 return *this;
|
max@0
|
504 }
|
max@0
|
505
|
max@0
|
506
|
max@0
|
507
|
max@0
|
508 //! In-place division of all elements of the matrix with a scalar
|
max@0
|
509 template<typename eT>
|
max@0
|
510 arma_inline
|
max@0
|
511 const Mat<eT>&
|
max@0
|
512 Mat<eT>::operator/=(const eT val)
|
max@0
|
513 {
|
max@0
|
514 arma_extra_debug_sigprint();
|
max@0
|
515
|
max@0
|
516 arrayops::inplace_div( memptr(), val, n_elem );
|
max@0
|
517
|
max@0
|
518 return *this;
|
max@0
|
519 }
|
max@0
|
520
|
max@0
|
521
|
max@0
|
522
|
max@0
|
523 //! construct a matrix from a given matrix
|
max@0
|
524 template<typename eT>
|
max@0
|
525 inline
|
max@0
|
526 Mat<eT>::Mat(const Mat<eT>& in_mat)
|
max@0
|
527 : n_rows(in_mat.n_rows)
|
max@0
|
528 , n_cols(in_mat.n_cols)
|
max@0
|
529 , n_elem(in_mat.n_elem)
|
max@0
|
530 , vec_state(0)
|
max@0
|
531 , mem_state(0)
|
max@0
|
532 , mem()
|
max@0
|
533 {
|
max@0
|
534 arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat);
|
max@0
|
535
|
max@0
|
536 init_cold();
|
max@0
|
537
|
max@0
|
538 arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem );
|
max@0
|
539 }
|
max@0
|
540
|
max@0
|
541
|
max@0
|
542
|
max@0
|
543 //! construct a matrix from a given matrix
|
max@0
|
544 template<typename eT>
|
max@0
|
545 inline
|
max@0
|
546 const Mat<eT>&
|
max@0
|
547 Mat<eT>::operator=(const Mat<eT>& in_mat)
|
max@0
|
548 {
|
max@0
|
549 arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat);
|
max@0
|
550
|
max@0
|
551 if(this != &in_mat)
|
max@0
|
552 {
|
max@0
|
553 init_warm(in_mat.n_rows, in_mat.n_cols);
|
max@0
|
554
|
max@0
|
555 arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem );
|
max@0
|
556 }
|
max@0
|
557
|
max@0
|
558 return *this;
|
max@0
|
559 }
|
max@0
|
560
|
max@0
|
561
|
max@0
|
562
|
max@0
|
563 #if defined(ARMA_USE_CXX11)
|
max@0
|
564
|
max@0
|
565 template<typename eT>
|
max@0
|
566 inline
|
max@0
|
567 void
|
max@0
|
568 Mat<eT>::init(const std::initializer_list<eT>& list)
|
max@0
|
569 {
|
max@0
|
570 arma_extra_debug_sigprint();
|
max@0
|
571
|
max@0
|
572 const uword N = list.size();
|
max@0
|
573
|
max@0
|
574 set_size(1, N);
|
max@0
|
575
|
max@0
|
576 arrayops::copy( memptr(), list.begin(), N );
|
max@0
|
577 }
|
max@0
|
578
|
max@0
|
579 #endif
|
max@0
|
580
|
max@0
|
581
|
max@0
|
582
|
max@0
|
583 //! for constructing a complex matrix out of two non-complex matrices
|
max@0
|
584 template<typename eT>
|
max@0
|
585 template<typename T1, typename T2>
|
max@0
|
586 inline
|
max@0
|
587 void
|
max@0
|
588 Mat<eT>::init
|
max@0
|
589 (
|
max@0
|
590 const Base<typename Mat<eT>::pod_type, T1>& A,
|
max@0
|
591 const Base<typename Mat<eT>::pod_type, T2>& B
|
max@0
|
592 )
|
max@0
|
593 {
|
max@0
|
594 arma_extra_debug_sigprint();
|
max@0
|
595
|
max@0
|
596 typedef typename T1::elem_type T;
|
max@0
|
597 typedef typename Proxy<T1>::ea_type ea_type1;
|
max@0
|
598 typedef typename Proxy<T2>::ea_type ea_type2;
|
max@0
|
599
|
max@0
|
600 arma_type_check(( is_complex<eT>::value == false )); //!< compile-time abort if eT isn't std::complex
|
max@0
|
601 arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex
|
max@0
|
602
|
max@0
|
603 arma_type_check(( is_same_type< std::complex<T>, eT >::value == false )); //!< compile-time abort if types are not compatible
|
max@0
|
604
|
max@0
|
605 const Proxy<T1> X(A.get_ref());
|
max@0
|
606 const Proxy<T2> Y(B.get_ref());
|
max@0
|
607
|
max@0
|
608 arma_assert_same_size(X, Y, "Mat()");
|
max@0
|
609
|
max@0
|
610 init_warm(X.get_n_rows(), X.get_n_cols());
|
max@0
|
611
|
max@0
|
612 const uword N = n_elem;
|
max@0
|
613 eT* out_mem = memptr();
|
max@0
|
614 ea_type1 PX = X.get_ea();
|
max@0
|
615 ea_type2 PY = Y.get_ea();
|
max@0
|
616
|
max@0
|
617 for(uword i=0; i<N; ++i)
|
max@0
|
618 {
|
max@0
|
619 out_mem[i] = std::complex<T>(PX[i], PY[i]);
|
max@0
|
620 }
|
max@0
|
621 }
|
max@0
|
622
|
max@0
|
623
|
max@0
|
624
|
max@0
|
625 //! try to steal the memory from a given matrix;
|
max@0
|
626 //! if memory can't be stolen, copy the given matrix
|
max@0
|
627 template<typename eT>
|
max@0
|
628 inline
|
max@0
|
629 void
|
max@0
|
630 Mat<eT>::steal_mem(Mat<eT>& x)
|
max@0
|
631 {
|
max@0
|
632 arma_extra_debug_sigprint();
|
max@0
|
633
|
max@0
|
634 if(this != &x)
|
max@0
|
635 {
|
max@0
|
636 const uword x_n_rows = x.n_rows;
|
max@0
|
637 const uword x_n_cols = x.n_cols;
|
max@0
|
638 const uword x_n_elem = x.n_elem;
|
max@0
|
639 const uword x_vec_state = x.vec_state;
|
max@0
|
640 const uword x_mem_state = x.mem_state;
|
max@0
|
641
|
max@0
|
642 const uword t_vec_state = vec_state;
|
max@0
|
643
|
max@0
|
644 bool layout_ok = false;
|
max@0
|
645
|
max@0
|
646 if(t_vec_state == x_vec_state)
|
max@0
|
647 {
|
max@0
|
648 layout_ok = true;
|
max@0
|
649 }
|
max@0
|
650 else
|
max@0
|
651 {
|
max@0
|
652 if( (t_vec_state == 1) && ( x_n_cols == 1) )
|
max@0
|
653 {
|
max@0
|
654 layout_ok = true;
|
max@0
|
655 }
|
max@0
|
656
|
max@0
|
657 if( (t_vec_state == 2) && ( x_n_rows == 1) )
|
max@0
|
658 {
|
max@0
|
659 layout_ok = true;
|
max@0
|
660 }
|
max@0
|
661 }
|
max@0
|
662
|
max@0
|
663
|
max@0
|
664 if( (x_mem_state == 0) && (x_n_elem > arma_config::mat_prealloc) && (layout_ok == true) )
|
max@0
|
665 {
|
max@0
|
666 reset();
|
max@0
|
667 // note: calling reset() also prevents fixed size matrices from changing size or using non-local memory
|
max@0
|
668
|
max@0
|
669 access::rw(n_rows) = x_n_rows;
|
max@0
|
670 access::rw(n_cols) = x_n_cols;
|
max@0
|
671 access::rw(n_elem) = x_n_elem;
|
max@0
|
672 access::rw(mem) = x.mem;
|
max@0
|
673
|
max@0
|
674 access::rw(x.n_rows) = 0;
|
max@0
|
675 access::rw(x.n_cols) = 0;
|
max@0
|
676 access::rw(x.n_elem) = 0;
|
max@0
|
677 access::rw(x.mem) = 0;
|
max@0
|
678 }
|
max@0
|
679 else
|
max@0
|
680 {
|
max@0
|
681 (*this).operator=(x);
|
max@0
|
682 }
|
max@0
|
683 }
|
max@0
|
684 }
|
max@0
|
685
|
max@0
|
686
|
max@0
|
687
|
max@0
|
688 //! construct a matrix from a given auxiliary array of eTs.
|
max@0
|
689 //! if copy_aux_mem is true, new memory is allocated and the array is copied.
|
max@0
|
690 //! if copy_aux_mem is false, the auxiliary array is used directly (without allocating memory and copying).
|
max@0
|
691 //! the default is to copy the array.
|
max@0
|
692
|
max@0
|
693 template<typename eT>
|
max@0
|
694 inline
|
max@0
|
695 Mat<eT>::Mat(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const bool copy_aux_mem, const bool strict)
|
max@0
|
696 : n_rows ( aux_n_rows )
|
max@0
|
697 , n_cols ( aux_n_cols )
|
max@0
|
698 , n_elem ( aux_n_rows*aux_n_cols )
|
max@0
|
699 , vec_state( 0 )
|
max@0
|
700 , mem_state( copy_aux_mem ? 0 : ( strict ? 2 : 1 ) )
|
max@0
|
701 , mem ( copy_aux_mem ? 0 : aux_mem )
|
max@0
|
702 {
|
max@0
|
703 arma_extra_debug_sigprint_this(this);
|
max@0
|
704
|
max@0
|
705 if(copy_aux_mem == true)
|
max@0
|
706 {
|
max@0
|
707 init_cold();
|
max@0
|
708
|
max@0
|
709 arrayops::copy( memptr(), aux_mem, n_elem );
|
max@0
|
710 }
|
max@0
|
711 }
|
max@0
|
712
|
max@0
|
713
|
max@0
|
714
|
max@0
|
715 //! construct a matrix from a given auxiliary read-only array of eTs.
|
max@0
|
716 //! the array is copied.
|
max@0
|
717 template<typename eT>
|
max@0
|
718 inline
|
max@0
|
719 Mat<eT>::Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols)
|
max@0
|
720 : n_rows(aux_n_rows)
|
max@0
|
721 , n_cols(aux_n_cols)
|
max@0
|
722 , n_elem(aux_n_rows*aux_n_cols)
|
max@0
|
723 , vec_state(0)
|
max@0
|
724 , mem_state(0)
|
max@0
|
725 , mem()
|
max@0
|
726 {
|
max@0
|
727 arma_extra_debug_sigprint_this(this);
|
max@0
|
728
|
max@0
|
729 init_cold();
|
max@0
|
730
|
max@0
|
731 arrayops::copy( memptr(), aux_mem, n_elem );
|
max@0
|
732 }
|
max@0
|
733
|
max@0
|
734
|
max@0
|
735
|
max@0
|
736 //! DANGEROUS! Construct a temporary matrix, using auxiliary memory.
|
max@0
|
737 //! This constructor is NOT intended for usage by user code.
|
max@0
|
738 //! Its sole purpose is to be used by the Cube class.
|
max@0
|
739
|
max@0
|
740 template<typename eT>
|
max@0
|
741 inline
|
max@0
|
742 Mat<eT>::Mat(const char junk, const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols)
|
max@0
|
743 : n_rows (aux_n_rows )
|
max@0
|
744 , n_cols (aux_n_cols )
|
max@0
|
745 , n_elem (aux_n_rows*aux_n_cols)
|
max@0
|
746 , vec_state(0 )
|
max@0
|
747 , mem_state(3 )
|
max@0
|
748 , mem (aux_mem )
|
max@0
|
749 {
|
max@0
|
750 arma_extra_debug_sigprint_this(this);
|
max@0
|
751 arma_ignore(junk);
|
max@0
|
752 }
|
max@0
|
753
|
max@0
|
754
|
max@0
|
755
|
max@0
|
756 //! in-place matrix addition
|
max@0
|
757 template<typename eT>
|
max@0
|
758 inline
|
max@0
|
759 const Mat<eT>&
|
max@0
|
760 Mat<eT>::operator+=(const Mat<eT>& m)
|
max@0
|
761 {
|
max@0
|
762 arma_extra_debug_sigprint();
|
max@0
|
763
|
max@0
|
764 arma_debug_assert_same_size(*this, m, "addition");
|
max@0
|
765
|
max@0
|
766 arrayops::inplace_plus( memptr(), m.memptr(), n_elem );
|
max@0
|
767
|
max@0
|
768 return *this;
|
max@0
|
769 }
|
max@0
|
770
|
max@0
|
771
|
max@0
|
772
|
max@0
|
773 //! in-place matrix subtraction
|
max@0
|
774 template<typename eT>
|
max@0
|
775 inline
|
max@0
|
776 const Mat<eT>&
|
max@0
|
777 Mat<eT>::operator-=(const Mat<eT>& m)
|
max@0
|
778 {
|
max@0
|
779 arma_extra_debug_sigprint();
|
max@0
|
780
|
max@0
|
781 arma_debug_assert_same_size(*this, m, "subtraction");
|
max@0
|
782
|
max@0
|
783 arrayops::inplace_minus( memptr(), m.memptr(), n_elem );
|
max@0
|
784
|
max@0
|
785 return *this;
|
max@0
|
786 }
|
max@0
|
787
|
max@0
|
788
|
max@0
|
789
|
max@0
|
790 //! in-place matrix multiplication
|
max@0
|
791 template<typename eT>
|
max@0
|
792 inline
|
max@0
|
793 const Mat<eT>&
|
max@0
|
794 Mat<eT>::operator*=(const Mat<eT>& m)
|
max@0
|
795 {
|
max@0
|
796 arma_extra_debug_sigprint();
|
max@0
|
797
|
max@0
|
798 glue_times::apply_inplace(*this, m);
|
max@0
|
799
|
max@0
|
800 return *this;
|
max@0
|
801 }
|
max@0
|
802
|
max@0
|
803
|
max@0
|
804
|
max@0
|
805 //! in-place element-wise matrix multiplication
|
max@0
|
806 template<typename eT>
|
max@0
|
807 inline
|
max@0
|
808 const Mat<eT>&
|
max@0
|
809 Mat<eT>::operator%=(const Mat<eT>& m)
|
max@0
|
810 {
|
max@0
|
811 arma_extra_debug_sigprint();
|
max@0
|
812
|
max@0
|
813 arma_debug_assert_same_size(*this, m, "element-wise multiplication");
|
max@0
|
814
|
max@0
|
815 arrayops::inplace_mul( memptr(), m.memptr(), n_elem );
|
max@0
|
816
|
max@0
|
817 return *this;
|
max@0
|
818 }
|
max@0
|
819
|
max@0
|
820
|
max@0
|
821
|
max@0
|
822 //! in-place element-wise matrix division
|
max@0
|
823 template<typename eT>
|
max@0
|
824 inline
|
max@0
|
825 const Mat<eT>&
|
max@0
|
826 Mat<eT>::operator/=(const Mat<eT>& m)
|
max@0
|
827 {
|
max@0
|
828 arma_extra_debug_sigprint();
|
max@0
|
829
|
max@0
|
830 arma_debug_assert_same_size(*this, m, "element-wise division");
|
max@0
|
831
|
max@0
|
832 arrayops::inplace_div( memptr(), m.memptr(), n_elem );
|
max@0
|
833
|
max@0
|
834 return *this;
|
max@0
|
835 }
|
max@0
|
836
|
max@0
|
837
|
max@0
|
838
|
max@0
|
839 template<typename eT>
|
max@0
|
840 template<typename T1>
|
max@0
|
841 inline
|
max@0
|
842 Mat<eT>::Mat(const BaseCube<eT,T1>& X)
|
max@0
|
843 : n_rows(0)
|
max@0
|
844 , n_cols(0)
|
max@0
|
845 , n_elem(0)
|
max@0
|
846 , vec_state(0)
|
max@0
|
847 , mem_state(0)
|
max@0
|
848 , mem()
|
max@0
|
849 {
|
max@0
|
850 arma_extra_debug_sigprint_this(this);
|
max@0
|
851
|
max@0
|
852 (*this).operator=(X);
|
max@0
|
853 }
|
max@0
|
854
|
max@0
|
855
|
max@0
|
856
|
max@0
|
857 template<typename eT>
|
max@0
|
858 template<typename T1>
|
max@0
|
859 inline
|
max@0
|
860 const Mat<eT>&
|
max@0
|
861 Mat<eT>::operator=(const BaseCube<eT,T1>& X)
|
max@0
|
862 {
|
max@0
|
863 arma_extra_debug_sigprint();
|
max@0
|
864
|
max@0
|
865 Mat<eT>& out = *this;
|
max@0
|
866
|
max@0
|
867 const unwrap_cube<T1> tmp(X.get_ref());
|
max@0
|
868 const Cube<eT>& in = tmp.M;
|
max@0
|
869
|
max@0
|
870 arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false);
|
max@0
|
871
|
max@0
|
872 const uword in_n_rows = in.n_rows;
|
max@0
|
873 const uword in_n_cols = in.n_cols;
|
max@0
|
874 const uword in_n_slices = in.n_slices;
|
max@0
|
875
|
max@0
|
876 const uword out_vec_state = out.vec_state;
|
max@0
|
877
|
max@0
|
878 if(in_n_slices == 1)
|
max@0
|
879 {
|
max@0
|
880 out.set_size(in_n_rows, in_n_cols);
|
max@0
|
881
|
max@0
|
882 for(uword col=0; col < in_n_cols; ++col)
|
max@0
|
883 {
|
max@0
|
884 arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
|
max@0
|
885 }
|
max@0
|
886 }
|
max@0
|
887 else
|
max@0
|
888 {
|
max@0
|
889 if(out_vec_state == 0)
|
max@0
|
890 {
|
max@0
|
891 if(in_n_cols == 1)
|
max@0
|
892 {
|
max@0
|
893 out.set_size(in_n_rows, in_n_slices);
|
max@0
|
894
|
max@0
|
895 for(uword i=0; i < in_n_slices; ++i)
|
max@0
|
896 {
|
max@0
|
897 arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
|
max@0
|
898 }
|
max@0
|
899 }
|
max@0
|
900 else
|
max@0
|
901 if(in_n_rows == 1)
|
max@0
|
902 {
|
max@0
|
903 out.set_size(in_n_cols, in_n_slices);
|
max@0
|
904
|
max@0
|
905 for(uword slice=0; slice < in_n_slices; ++slice)
|
max@0
|
906 {
|
max@0
|
907 eT* out_colptr = out.colptr(slice);
|
max@0
|
908
|
max@0
|
909 uword i,j;
|
max@0
|
910 for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
|
max@0
|
911 {
|
max@0
|
912 const eT tmp_i = in.at(0, i, slice);
|
max@0
|
913 const eT tmp_j = in.at(0, j, slice);
|
max@0
|
914
|
max@0
|
915 out_colptr[i] = tmp_i;
|
max@0
|
916 out_colptr[j] = tmp_j;
|
max@0
|
917 }
|
max@0
|
918
|
max@0
|
919 if(i < in_n_cols)
|
max@0
|
920 {
|
max@0
|
921 out_colptr[i] = in.at(0, i, slice);
|
max@0
|
922 }
|
max@0
|
923 }
|
max@0
|
924 }
|
max@0
|
925 }
|
max@0
|
926 else
|
max@0
|
927 {
|
max@0
|
928 out.set_size(in_n_slices);
|
max@0
|
929
|
max@0
|
930 eT* out_mem = out.memptr();
|
max@0
|
931
|
max@0
|
932 for(uword i=0; i<in_n_slices; ++i)
|
max@0
|
933 {
|
max@0
|
934 out_mem[i] = in.at(0, 0, i);
|
max@0
|
935 }
|
max@0
|
936 }
|
max@0
|
937 }
|
max@0
|
938
|
max@0
|
939 return *this;
|
max@0
|
940 }
|
max@0
|
941
|
max@0
|
942
|
max@0
|
943
|
max@0
|
944 template<typename eT>
|
max@0
|
945 template<typename T1>
|
max@0
|
946 inline
|
max@0
|
947 const Mat<eT>&
|
max@0
|
948 Mat<eT>::operator+=(const BaseCube<eT,T1>& X)
|
max@0
|
949 {
|
max@0
|
950 arma_extra_debug_sigprint();
|
max@0
|
951
|
max@0
|
952 Mat<eT>& out = *this;
|
max@0
|
953
|
max@0
|
954 const unwrap_cube<T1> tmp(X.get_ref());
|
max@0
|
955 const Cube<eT>& in = tmp.M;
|
max@0
|
956
|
max@0
|
957 arma_debug_assert_cube_as_mat(out, in, "addition", true);
|
max@0
|
958
|
max@0
|
959 const uword in_n_rows = in.n_rows;
|
max@0
|
960 const uword in_n_cols = in.n_cols;
|
max@0
|
961 const uword in_n_slices = in.n_slices;
|
max@0
|
962
|
max@0
|
963 const uword out_n_rows = out.n_rows;
|
max@0
|
964 const uword out_n_cols = out.n_cols;
|
max@0
|
965 const uword out_vec_state = out.vec_state;
|
max@0
|
966
|
max@0
|
967 if(in_n_slices == 1)
|
max@0
|
968 {
|
max@0
|
969 for(uword col=0; col < in_n_cols; ++col)
|
max@0
|
970 {
|
max@0
|
971 arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
|
max@0
|
972 }
|
max@0
|
973 }
|
max@0
|
974 else
|
max@0
|
975 {
|
max@0
|
976 if(out_vec_state == 0)
|
max@0
|
977 {
|
max@0
|
978 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
|
max@0
|
979 {
|
max@0
|
980 for(uword i=0; i < in_n_slices; ++i)
|
max@0
|
981 {
|
max@0
|
982 arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
|
max@0
|
983 }
|
max@0
|
984 }
|
max@0
|
985 else
|
max@0
|
986 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
|
max@0
|
987 {
|
max@0
|
988 for(uword slice=0; slice < in_n_slices; ++slice)
|
max@0
|
989 {
|
max@0
|
990 eT* out_colptr = out.colptr(slice);
|
max@0
|
991
|
max@0
|
992 uword i,j;
|
max@0
|
993 for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
|
max@0
|
994 {
|
max@0
|
995 const eT tmp_i = in.at(0, i, slice);
|
max@0
|
996 const eT tmp_j = in.at(0, j, slice);
|
max@0
|
997
|
max@0
|
998 out_colptr[i] += tmp_i;
|
max@0
|
999 out_colptr[j] += tmp_j;
|
max@0
|
1000 }
|
max@0
|
1001
|
max@0
|
1002 if(i < in_n_cols)
|
max@0
|
1003 {
|
max@0
|
1004 out_colptr[i] += in.at(0, i, slice);
|
max@0
|
1005 }
|
max@0
|
1006 }
|
max@0
|
1007 }
|
max@0
|
1008 }
|
max@0
|
1009 else
|
max@0
|
1010 {
|
max@0
|
1011 eT* out_mem = out.memptr();
|
max@0
|
1012
|
max@0
|
1013 for(uword i=0; i<in_n_slices; ++i)
|
max@0
|
1014 {
|
max@0
|
1015 out_mem[i] += in.at(0, 0, i);
|
max@0
|
1016 }
|
max@0
|
1017 }
|
max@0
|
1018 }
|
max@0
|
1019
|
max@0
|
1020 return *this;
|
max@0
|
1021 }
|
max@0
|
1022
|
max@0
|
1023
|
max@0
|
1024
|
max@0
|
1025 template<typename eT>
|
max@0
|
1026 template<typename T1>
|
max@0
|
1027 inline
|
max@0
|
1028 const Mat<eT>&
|
max@0
|
1029 Mat<eT>::operator-=(const BaseCube<eT,T1>& X)
|
max@0
|
1030 {
|
max@0
|
1031 arma_extra_debug_sigprint();
|
max@0
|
1032
|
max@0
|
1033 Mat<eT>& out = *this;
|
max@0
|
1034
|
max@0
|
1035 const unwrap_cube<T1> tmp(X.get_ref());
|
max@0
|
1036 const Cube<eT>& in = tmp.M;
|
max@0
|
1037
|
max@0
|
1038 arma_debug_assert_cube_as_mat(out, in, "subtraction", true);
|
max@0
|
1039
|
max@0
|
1040 const uword in_n_rows = in.n_rows;
|
max@0
|
1041 const uword in_n_cols = in.n_cols;
|
max@0
|
1042 const uword in_n_slices = in.n_slices;
|
max@0
|
1043
|
max@0
|
1044 const uword out_n_rows = out.n_rows;
|
max@0
|
1045 const uword out_n_cols = out.n_cols;
|
max@0
|
1046 const uword out_vec_state = out.vec_state;
|
max@0
|
1047
|
max@0
|
1048 if(in_n_slices == 1)
|
max@0
|
1049 {
|
max@0
|
1050 for(uword col=0; col < in_n_cols; ++col)
|
max@0
|
1051 {
|
max@0
|
1052 arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
|
max@0
|
1053 }
|
max@0
|
1054 }
|
max@0
|
1055 else
|
max@0
|
1056 {
|
max@0
|
1057 if(out_vec_state == 0)
|
max@0
|
1058 {
|
max@0
|
1059 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
|
max@0
|
1060 {
|
max@0
|
1061 for(uword i=0; i < in_n_slices; ++i)
|
max@0
|
1062 {
|
max@0
|
1063 arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
|
max@0
|
1064 }
|
max@0
|
1065 }
|
max@0
|
1066 else
|
max@0
|
1067 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
|
max@0
|
1068 {
|
max@0
|
1069 for(uword slice=0; slice < in_n_slices; ++slice)
|
max@0
|
1070 {
|
max@0
|
1071 eT* out_colptr = out.colptr(slice);
|
max@0
|
1072
|
max@0
|
1073 uword i,j;
|
max@0
|
1074 for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
|
max@0
|
1075 {
|
max@0
|
1076 const eT tmp_i = in.at(0, i, slice);
|
max@0
|
1077 const eT tmp_j = in.at(0, j, slice);
|
max@0
|
1078
|
max@0
|
1079 out_colptr[i] -= tmp_i;
|
max@0
|
1080 out_colptr[j] -= tmp_j;
|
max@0
|
1081 }
|
max@0
|
1082
|
max@0
|
1083 if(i < in_n_cols)
|
max@0
|
1084 {
|
max@0
|
1085 out_colptr[i] -= in.at(0, i, slice);
|
max@0
|
1086 }
|
max@0
|
1087 }
|
max@0
|
1088 }
|
max@0
|
1089 }
|
max@0
|
1090 else
|
max@0
|
1091 {
|
max@0
|
1092 eT* out_mem = out.memptr();
|
max@0
|
1093
|
max@0
|
1094 for(uword i=0; i<in_n_slices; ++i)
|
max@0
|
1095 {
|
max@0
|
1096 out_mem[i] -= in.at(0, 0, i);
|
max@0
|
1097 }
|
max@0
|
1098 }
|
max@0
|
1099 }
|
max@0
|
1100
|
max@0
|
1101 return *this;
|
max@0
|
1102 }
|
max@0
|
1103
|
max@0
|
1104
|
max@0
|
1105
|
max@0
|
1106 template<typename eT>
|
max@0
|
1107 template<typename T1>
|
max@0
|
1108 inline
|
max@0
|
1109 const Mat<eT>&
|
max@0
|
1110 Mat<eT>::operator*=(const BaseCube<eT,T1>& X)
|
max@0
|
1111 {
|
max@0
|
1112 arma_extra_debug_sigprint();
|
max@0
|
1113
|
max@0
|
1114 const Mat<eT> B(X);
|
max@0
|
1115
|
max@0
|
1116 (*this).operator*=(B);
|
max@0
|
1117
|
max@0
|
1118 return *this;
|
max@0
|
1119 }
|
max@0
|
1120
|
max@0
|
1121
|
max@0
|
1122
|
max@0
|
1123 template<typename eT>
|
max@0
|
1124 template<typename T1>
|
max@0
|
1125 inline
|
max@0
|
1126 const Mat<eT>&
|
max@0
|
1127 Mat<eT>::operator%=(const BaseCube<eT,T1>& X)
|
max@0
|
1128 {
|
max@0
|
1129 arma_extra_debug_sigprint();
|
max@0
|
1130
|
max@0
|
1131 Mat<eT>& out = *this;
|
max@0
|
1132
|
max@0
|
1133 const unwrap_cube<T1> tmp(X.get_ref());
|
max@0
|
1134 const Cube<eT>& in = tmp.M;
|
max@0
|
1135
|
max@0
|
1136 arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true);
|
max@0
|
1137
|
max@0
|
1138 const uword in_n_rows = in.n_rows;
|
max@0
|
1139 const uword in_n_cols = in.n_cols;
|
max@0
|
1140 const uword in_n_slices = in.n_slices;
|
max@0
|
1141
|
max@0
|
1142 const uword out_n_rows = out.n_rows;
|
max@0
|
1143 const uword out_n_cols = out.n_cols;
|
max@0
|
1144 const uword out_vec_state = out.vec_state;
|
max@0
|
1145
|
max@0
|
1146 if(in_n_slices == 1)
|
max@0
|
1147 {
|
max@0
|
1148 for(uword col=0; col < in_n_cols; ++col)
|
max@0
|
1149 {
|
max@0
|
1150 arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
|
max@0
|
1151 }
|
max@0
|
1152 }
|
max@0
|
1153 else
|
max@0
|
1154 {
|
max@0
|
1155 if(out_vec_state == 0)
|
max@0
|
1156 {
|
max@0
|
1157 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
|
max@0
|
1158 {
|
max@0
|
1159 for(uword i=0; i < in_n_slices; ++i)
|
max@0
|
1160 {
|
max@0
|
1161 arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
|
max@0
|
1162 }
|
max@0
|
1163 }
|
max@0
|
1164 else
|
max@0
|
1165 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
|
max@0
|
1166 {
|
max@0
|
1167 for(uword slice=0; slice < in_n_slices; ++slice)
|
max@0
|
1168 {
|
max@0
|
1169 eT* out_colptr = out.colptr(slice);
|
max@0
|
1170
|
max@0
|
1171 uword i,j;
|
max@0
|
1172 for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
|
max@0
|
1173 {
|
max@0
|
1174 const eT tmp_i = in.at(0, i, slice);
|
max@0
|
1175 const eT tmp_j = in.at(0, j, slice);
|
max@0
|
1176
|
max@0
|
1177 out_colptr[i] *= tmp_i;
|
max@0
|
1178 out_colptr[j] *= tmp_j;
|
max@0
|
1179 }
|
max@0
|
1180
|
max@0
|
1181 if(i < in_n_cols)
|
max@0
|
1182 {
|
max@0
|
1183 out_colptr[i] *= in.at(0, i, slice);
|
max@0
|
1184 }
|
max@0
|
1185 }
|
max@0
|
1186 }
|
max@0
|
1187 }
|
max@0
|
1188 else
|
max@0
|
1189 {
|
max@0
|
1190 eT* out_mem = out.memptr();
|
max@0
|
1191
|
max@0
|
1192 for(uword i=0; i<in_n_slices; ++i)
|
max@0
|
1193 {
|
max@0
|
1194 out_mem[i] *= in.at(0, 0, i);
|
max@0
|
1195 }
|
max@0
|
1196 }
|
max@0
|
1197 }
|
max@0
|
1198
|
max@0
|
1199 return *this;
|
max@0
|
1200 }
|
max@0
|
1201
|
max@0
|
1202
|
max@0
|
1203
|
max@0
|
1204 template<typename eT>
|
max@0
|
1205 template<typename T1>
|
max@0
|
1206 inline
|
max@0
|
1207 const Mat<eT>&
|
max@0
|
1208 Mat<eT>::operator/=(const BaseCube<eT,T1>& X)
|
max@0
|
1209 {
|
max@0
|
1210 arma_extra_debug_sigprint();
|
max@0
|
1211
|
max@0
|
1212 Mat<eT>& out = *this;
|
max@0
|
1213
|
max@0
|
1214 const unwrap_cube<T1> tmp(X.get_ref());
|
max@0
|
1215 const Cube<eT>& in = tmp.M;
|
max@0
|
1216
|
max@0
|
1217 arma_debug_assert_cube_as_mat(out, in, "element-wise division", true);
|
max@0
|
1218
|
max@0
|
1219 const uword in_n_rows = in.n_rows;
|
max@0
|
1220 const uword in_n_cols = in.n_cols;
|
max@0
|
1221 const uword in_n_slices = in.n_slices;
|
max@0
|
1222
|
max@0
|
1223 const uword out_n_rows = out.n_rows;
|
max@0
|
1224 const uword out_n_cols = out.n_cols;
|
max@0
|
1225 const uword out_vec_state = out.vec_state;
|
max@0
|
1226
|
max@0
|
1227 if(in_n_slices == 1)
|
max@0
|
1228 {
|
max@0
|
1229 for(uword col=0; col < in_n_cols; ++col)
|
max@0
|
1230 {
|
max@0
|
1231 arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
|
max@0
|
1232 }
|
max@0
|
1233 }
|
max@0
|
1234 else
|
max@0
|
1235 {
|
max@0
|
1236 if(out_vec_state == 0)
|
max@0
|
1237 {
|
max@0
|
1238 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
|
max@0
|
1239 {
|
max@0
|
1240 for(uword i=0; i < in_n_slices; ++i)
|
max@0
|
1241 {
|
max@0
|
1242 arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
|
max@0
|
1243 }
|
max@0
|
1244 }
|
max@0
|
1245 else
|
max@0
|
1246 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
|
max@0
|
1247 {
|
max@0
|
1248 for(uword slice=0; slice < in_n_slices; ++slice)
|
max@0
|
1249 {
|
max@0
|
1250 eT* out_colptr = out.colptr(slice);
|
max@0
|
1251
|
max@0
|
1252 uword i,j;
|
max@0
|
1253 for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
|
max@0
|
1254 {
|
max@0
|
1255 const eT tmp_i = in.at(0, i, slice);
|
max@0
|
1256 const eT tmp_j = in.at(0, j, slice);
|
max@0
|
1257
|
max@0
|
1258 out_colptr[i] /= tmp_i;
|
max@0
|
1259 out_colptr[j] /= tmp_j;
|
max@0
|
1260 }
|
max@0
|
1261
|
max@0
|
1262 if(i < in_n_cols)
|
max@0
|
1263 {
|
max@0
|
1264 out_colptr[i] /= in.at(0, i, slice);
|
max@0
|
1265 }
|
max@0
|
1266 }
|
max@0
|
1267 }
|
max@0
|
1268 }
|
max@0
|
1269 else
|
max@0
|
1270 {
|
max@0
|
1271 eT* out_mem = out.memptr();
|
max@0
|
1272
|
max@0
|
1273 for(uword i=0; i<in_n_slices; ++i)
|
max@0
|
1274 {
|
max@0
|
1275 out_mem[i] /= in.at(0, 0, i);
|
max@0
|
1276 }
|
max@0
|
1277 }
|
max@0
|
1278 }
|
max@0
|
1279
|
max@0
|
1280 return *this;
|
max@0
|
1281 }
|
max@0
|
1282
|
max@0
|
1283
|
max@0
|
1284
|
max@0
|
1285 //! for constructing a complex matrix out of two non-complex matrices
|
max@0
|
1286 template<typename eT>
|
max@0
|
1287 template<typename T1, typename T2>
|
max@0
|
1288 inline
|
max@0
|
1289 Mat<eT>::Mat
|
max@0
|
1290 (
|
max@0
|
1291 const Base<typename Mat<eT>::pod_type,T1>& A,
|
max@0
|
1292 const Base<typename Mat<eT>::pod_type,T2>& B
|
max@0
|
1293 )
|
max@0
|
1294 : n_rows(0)
|
max@0
|
1295 , n_cols(0)
|
max@0
|
1296 , n_elem(0)
|
max@0
|
1297 , vec_state(0)
|
max@0
|
1298 , mem_state(0)
|
max@0
|
1299 , mem()
|
max@0
|
1300 {
|
max@0
|
1301 arma_extra_debug_sigprint_this(this);
|
max@0
|
1302
|
max@0
|
1303 init(A,B);
|
max@0
|
1304 }
|
max@0
|
1305
|
max@0
|
1306
|
max@0
|
1307
|
max@0
|
1308 //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation)
|
max@0
|
1309 template<typename eT>
|
max@0
|
1310 inline
|
max@0
|
1311 Mat<eT>::Mat(const subview<eT>& X)
|
max@0
|
1312 : n_rows(X.n_rows)
|
max@0
|
1313 , n_cols(X.n_cols)
|
max@0
|
1314 , n_elem(X.n_elem)
|
max@0
|
1315 , vec_state(0)
|
max@0
|
1316 , mem_state(0)
|
max@0
|
1317 , mem()
|
max@0
|
1318 {
|
max@0
|
1319 arma_extra_debug_sigprint_this(this);
|
max@0
|
1320
|
max@0
|
1321 init_cold();
|
max@0
|
1322
|
max@0
|
1323 subview<eT>::extract(*this, X);
|
max@0
|
1324 }
|
max@0
|
1325
|
max@0
|
1326
|
max@0
|
1327
|
max@0
|
1328 //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation)
|
max@0
|
1329 template<typename eT>
|
max@0
|
1330 inline
|
max@0
|
1331 const Mat<eT>&
|
max@0
|
1332 Mat<eT>::operator=(const subview<eT>& X)
|
max@0
|
1333 {
|
max@0
|
1334 arma_extra_debug_sigprint();
|
max@0
|
1335
|
max@0
|
1336 const bool alias = (this == &(X.m));
|
max@0
|
1337
|
max@0
|
1338 if(alias == false)
|
max@0
|
1339 {
|
max@0
|
1340 init_warm(X.n_rows, X.n_cols);
|
max@0
|
1341
|
max@0
|
1342 subview<eT>::extract(*this, X);
|
max@0
|
1343 }
|
max@0
|
1344 else
|
max@0
|
1345 {
|
max@0
|
1346 Mat<eT> tmp(X);
|
max@0
|
1347
|
max@0
|
1348 steal_mem(tmp);
|
max@0
|
1349 }
|
max@0
|
1350
|
max@0
|
1351 return *this;
|
max@0
|
1352 }
|
max@0
|
1353
|
max@0
|
1354
|
max@0
|
1355 //! in-place matrix addition (using a submatrix on the right-hand-side)
|
max@0
|
1356 template<typename eT>
|
max@0
|
1357 inline
|
max@0
|
1358 const Mat<eT>&
|
max@0
|
1359 Mat<eT>::operator+=(const subview<eT>& X)
|
max@0
|
1360 {
|
max@0
|
1361 arma_extra_debug_sigprint();
|
max@0
|
1362
|
max@0
|
1363 subview<eT>::plus_inplace(*this, X);
|
max@0
|
1364
|
max@0
|
1365 return *this;
|
max@0
|
1366 }
|
max@0
|
1367
|
max@0
|
1368
|
max@0
|
1369 //! in-place matrix subtraction (using a submatrix on the right-hand-side)
|
max@0
|
1370 template<typename eT>
|
max@0
|
1371 inline
|
max@0
|
1372 const Mat<eT>&
|
max@0
|
1373 Mat<eT>::operator-=(const subview<eT>& X)
|
max@0
|
1374 {
|
max@0
|
1375 arma_extra_debug_sigprint();
|
max@0
|
1376
|
max@0
|
1377 subview<eT>::minus_inplace(*this, X);
|
max@0
|
1378
|
max@0
|
1379 return *this;
|
max@0
|
1380 }
|
max@0
|
1381
|
max@0
|
1382
|
max@0
|
1383
|
max@0
|
1384 //! in-place matrix mutiplication (using a submatrix on the right-hand-side)
|
max@0
|
1385 template<typename eT>
|
max@0
|
1386 inline
|
max@0
|
1387 const Mat<eT>&
|
max@0
|
1388 Mat<eT>::operator*=(const subview<eT>& X)
|
max@0
|
1389 {
|
max@0
|
1390 arma_extra_debug_sigprint();
|
max@0
|
1391
|
max@0
|
1392 glue_times::apply_inplace(*this, X);
|
max@0
|
1393
|
max@0
|
1394 return *this;
|
max@0
|
1395 }
|
max@0
|
1396
|
max@0
|
1397
|
max@0
|
1398
|
max@0
|
1399 //! in-place element-wise matrix mutiplication (using a submatrix on the right-hand-side)
|
max@0
|
1400 template<typename eT>
|
max@0
|
1401 inline
|
max@0
|
1402 const Mat<eT>&
|
max@0
|
1403 Mat<eT>::operator%=(const subview<eT>& X)
|
max@0
|
1404 {
|
max@0
|
1405 arma_extra_debug_sigprint();
|
max@0
|
1406
|
max@0
|
1407 subview<eT>::schur_inplace(*this, X);
|
max@0
|
1408
|
max@0
|
1409 return *this;
|
max@0
|
1410 }
|
max@0
|
1411
|
max@0
|
1412
|
max@0
|
1413
|
max@0
|
1414 //! in-place element-wise matrix division (using a submatrix on the right-hand-side)
|
max@0
|
1415 template<typename eT>
|
max@0
|
1416 inline
|
max@0
|
1417 const Mat<eT>&
|
max@0
|
1418 Mat<eT>::operator/=(const subview<eT>& X)
|
max@0
|
1419 {
|
max@0
|
1420 arma_extra_debug_sigprint();
|
max@0
|
1421
|
max@0
|
1422 subview<eT>::div_inplace(*this, X);
|
max@0
|
1423
|
max@0
|
1424 return *this;
|
max@0
|
1425 }
|
max@0
|
1426
|
max@0
|
1427
|
max@0
|
1428
|
max@0
|
1429 //! construct a matrix from a subview_cube instance
|
max@0
|
1430 template<typename eT>
|
max@0
|
1431 inline
|
max@0
|
1432 Mat<eT>::Mat(const subview_cube<eT>& x)
|
max@0
|
1433 : n_rows(0)
|
max@0
|
1434 , n_cols(0)
|
max@0
|
1435 , n_elem(0)
|
max@0
|
1436 , vec_state(0)
|
max@0
|
1437 , mem_state(0)
|
max@0
|
1438 , mem()
|
max@0
|
1439 {
|
max@0
|
1440 arma_extra_debug_sigprint_this(this);
|
max@0
|
1441
|
max@0
|
1442 this->operator=(x);
|
max@0
|
1443 }
|
max@0
|
1444
|
max@0
|
1445
|
max@0
|
1446
|
max@0
|
1447 //! construct a matrix from a subview_cube instance
|
max@0
|
1448 template<typename eT>
|
max@0
|
1449 inline
|
max@0
|
1450 const Mat<eT>&
|
max@0
|
1451 Mat<eT>::operator=(const subview_cube<eT>& X)
|
max@0
|
1452 {
|
max@0
|
1453 arma_extra_debug_sigprint();
|
max@0
|
1454
|
max@0
|
1455 subview_cube<eT>::extract(*this, X);
|
max@0
|
1456
|
max@0
|
1457 return *this;
|
max@0
|
1458 }
|
max@0
|
1459
|
max@0
|
1460
|
max@0
|
1461
|
max@0
|
1462 //! in-place matrix addition (using a single-slice subcube on the right-hand-side)
|
max@0
|
1463 template<typename eT>
|
max@0
|
1464 inline
|
max@0
|
1465 const Mat<eT>&
|
max@0
|
1466 Mat<eT>::operator+=(const subview_cube<eT>& X)
|
max@0
|
1467 {
|
max@0
|
1468 arma_extra_debug_sigprint();
|
max@0
|
1469
|
max@0
|
1470 subview_cube<eT>::plus_inplace(*this, X);
|
max@0
|
1471
|
max@0
|
1472 return *this;
|
max@0
|
1473 }
|
max@0
|
1474
|
max@0
|
1475
|
max@0
|
1476
|
max@0
|
1477 //! in-place matrix subtraction (using a single-slice subcube on the right-hand-side)
|
max@0
|
1478 template<typename eT>
|
max@0
|
1479 inline
|
max@0
|
1480 const Mat<eT>&
|
max@0
|
1481 Mat<eT>::operator-=(const subview_cube<eT>& X)
|
max@0
|
1482 {
|
max@0
|
1483 arma_extra_debug_sigprint();
|
max@0
|
1484
|
max@0
|
1485 subview_cube<eT>::minus_inplace(*this, X);
|
max@0
|
1486
|
max@0
|
1487 return *this;
|
max@0
|
1488 }
|
max@0
|
1489
|
max@0
|
1490
|
max@0
|
1491
|
max@0
|
1492 //! in-place matrix mutiplication (using a single-slice subcube on the right-hand-side)
|
max@0
|
1493 template<typename eT>
|
max@0
|
1494 inline
|
max@0
|
1495 const Mat<eT>&
|
max@0
|
1496 Mat<eT>::operator*=(const subview_cube<eT>& X)
|
max@0
|
1497 {
|
max@0
|
1498 arma_extra_debug_sigprint();
|
max@0
|
1499
|
max@0
|
1500 const Mat<eT> tmp(X);
|
max@0
|
1501 glue_times::apply_inplace(*this, tmp);
|
max@0
|
1502
|
max@0
|
1503 return *this;
|
max@0
|
1504 }
|
max@0
|
1505
|
max@0
|
1506
|
max@0
|
1507
|
max@0
|
1508 //! in-place element-wise matrix mutiplication (using a single-slice subcube on the right-hand-side)
|
max@0
|
1509 template<typename eT>
|
max@0
|
1510 inline
|
max@0
|
1511 const Mat<eT>&
|
max@0
|
1512 Mat<eT>::operator%=(const subview_cube<eT>& X)
|
max@0
|
1513 {
|
max@0
|
1514 arma_extra_debug_sigprint();
|
max@0
|
1515
|
max@0
|
1516 subview_cube<eT>::schur_inplace(*this, X);
|
max@0
|
1517
|
max@0
|
1518 return *this;
|
max@0
|
1519 }
|
max@0
|
1520
|
max@0
|
1521
|
max@0
|
1522
|
max@0
|
1523 //! in-place element-wise matrix division (using a single-slice subcube on the right-hand-side)
|
max@0
|
1524 template<typename eT>
|
max@0
|
1525 inline
|
max@0
|
1526 const Mat<eT>&
|
max@0
|
1527 Mat<eT>::operator/=(const subview_cube<eT>& X)
|
max@0
|
1528 {
|
max@0
|
1529 arma_extra_debug_sigprint();
|
max@0
|
1530
|
max@0
|
1531 subview_cube<eT>::div_inplace(*this, X);
|
max@0
|
1532
|
max@0
|
1533 return *this;
|
max@0
|
1534 }
|
max@0
|
1535
|
max@0
|
1536
|
max@0
|
1537
|
max@0
|
1538 //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation)
|
max@0
|
1539 template<typename eT>
|
max@0
|
1540 inline
|
max@0
|
1541 Mat<eT>::Mat(const diagview<eT>& X)
|
max@0
|
1542 : n_rows(X.n_rows)
|
max@0
|
1543 , n_cols(X.n_cols)
|
max@0
|
1544 , n_elem(X.n_elem)
|
max@0
|
1545 , vec_state(0)
|
max@0
|
1546 , mem_state(0)
|
max@0
|
1547 , mem()
|
max@0
|
1548 {
|
max@0
|
1549 arma_extra_debug_sigprint_this(this);
|
max@0
|
1550
|
max@0
|
1551 init_cold();
|
max@0
|
1552
|
max@0
|
1553 diagview<eT>::extract(*this, X);
|
max@0
|
1554 }
|
max@0
|
1555
|
max@0
|
1556
|
max@0
|
1557
|
max@0
|
1558 //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation)
|
max@0
|
1559 template<typename eT>
|
max@0
|
1560 inline
|
max@0
|
1561 const Mat<eT>&
|
max@0
|
1562 Mat<eT>::operator=(const diagview<eT>& X)
|
max@0
|
1563 {
|
max@0
|
1564 arma_extra_debug_sigprint();
|
max@0
|
1565
|
max@0
|
1566 const bool alias = (this == &(X.m));
|
max@0
|
1567
|
max@0
|
1568 if(alias == false)
|
max@0
|
1569 {
|
max@0
|
1570 init_warm(X.n_rows, X.n_cols);
|
max@0
|
1571
|
max@0
|
1572 diagview<eT>::extract(*this, X);
|
max@0
|
1573 }
|
max@0
|
1574 else
|
max@0
|
1575 {
|
max@0
|
1576 Mat<eT> tmp(X);
|
max@0
|
1577
|
max@0
|
1578 steal_mem(tmp);
|
max@0
|
1579 }
|
max@0
|
1580
|
max@0
|
1581 return *this;
|
max@0
|
1582 }
|
max@0
|
1583
|
max@0
|
1584
|
max@0
|
1585
|
max@0
|
1586 //! in-place matrix addition (using a diagview on the right-hand-side)
|
max@0
|
1587 template<typename eT>
|
max@0
|
1588 inline
|
max@0
|
1589 const Mat<eT>&
|
max@0
|
1590 Mat<eT>::operator+=(const diagview<eT>& X)
|
max@0
|
1591 {
|
max@0
|
1592 arma_extra_debug_sigprint();
|
max@0
|
1593
|
max@0
|
1594 diagview<eT>::plus_inplace(*this, X);
|
max@0
|
1595
|
max@0
|
1596 return *this;
|
max@0
|
1597 }
|
max@0
|
1598
|
max@0
|
1599
|
max@0
|
1600 //! in-place matrix subtraction (using a diagview on the right-hand-side)
|
max@0
|
1601 template<typename eT>
|
max@0
|
1602 inline
|
max@0
|
1603 const Mat<eT>&
|
max@0
|
1604 Mat<eT>::operator-=(const diagview<eT>& X)
|
max@0
|
1605 {
|
max@0
|
1606 arma_extra_debug_sigprint();
|
max@0
|
1607
|
max@0
|
1608 diagview<eT>::minus_inplace(*this, X);
|
max@0
|
1609
|
max@0
|
1610 return *this;
|
max@0
|
1611 }
|
max@0
|
1612
|
max@0
|
1613
|
max@0
|
1614
|
max@0
|
1615 //! in-place matrix mutiplication (using a diagview on the right-hand-side)
|
max@0
|
1616 template<typename eT>
|
max@0
|
1617 inline
|
max@0
|
1618 const Mat<eT>&
|
max@0
|
1619 Mat<eT>::operator*=(const diagview<eT>& X)
|
max@0
|
1620 {
|
max@0
|
1621 arma_extra_debug_sigprint();
|
max@0
|
1622
|
max@0
|
1623 glue_times::apply_inplace(*this, X);
|
max@0
|
1624
|
max@0
|
1625 return *this;
|
max@0
|
1626 }
|
max@0
|
1627
|
max@0
|
1628
|
max@0
|
1629
|
max@0
|
1630 //! in-place element-wise matrix mutiplication (using a diagview on the right-hand-side)
|
max@0
|
1631 template<typename eT>
|
max@0
|
1632 inline
|
max@0
|
1633 const Mat<eT>&
|
max@0
|
1634 Mat<eT>::operator%=(const diagview<eT>& X)
|
max@0
|
1635 {
|
max@0
|
1636 arma_extra_debug_sigprint();
|
max@0
|
1637
|
max@0
|
1638 diagview<eT>::schur_inplace(*this, X);
|
max@0
|
1639
|
max@0
|
1640 return *this;
|
max@0
|
1641 }
|
max@0
|
1642
|
max@0
|
1643
|
max@0
|
1644
|
max@0
|
1645 //! in-place element-wise matrix division (using a diagview on the right-hand-side)
|
max@0
|
1646 template<typename eT>
|
max@0
|
1647 inline
|
max@0
|
1648 const Mat<eT>&
|
max@0
|
1649 Mat<eT>::operator/=(const diagview<eT>& X)
|
max@0
|
1650 {
|
max@0
|
1651 arma_extra_debug_sigprint();
|
max@0
|
1652
|
max@0
|
1653 diagview<eT>::div_inplace(*this, X);
|
max@0
|
1654
|
max@0
|
1655 return *this;
|
max@0
|
1656 }
|
max@0
|
1657
|
max@0
|
1658
|
max@0
|
1659
|
max@0
|
1660 template<typename eT>
|
max@0
|
1661 template<typename T1>
|
max@0
|
1662 inline
|
max@0
|
1663 Mat<eT>::Mat(const subview_elem1<eT,T1>& X)
|
max@0
|
1664 : n_rows(0)
|
max@0
|
1665 , n_cols(0)
|
max@0
|
1666 , n_elem(0)
|
max@0
|
1667 , vec_state(0)
|
max@0
|
1668 , mem_state(0)
|
max@0
|
1669 , mem()
|
max@0
|
1670 {
|
max@0
|
1671 arma_extra_debug_sigprint_this(this);
|
max@0
|
1672
|
max@0
|
1673 this->operator=(X);
|
max@0
|
1674 }
|
max@0
|
1675
|
max@0
|
1676
|
max@0
|
1677
|
max@0
|
1678 template<typename eT>
|
max@0
|
1679 template<typename T1>
|
max@0
|
1680 inline
|
max@0
|
1681 const Mat<eT>&
|
max@0
|
1682 Mat<eT>::operator=(const subview_elem1<eT,T1>& X)
|
max@0
|
1683 {
|
max@0
|
1684 arma_extra_debug_sigprint();
|
max@0
|
1685
|
max@0
|
1686 subview_elem1<eT,T1>::extract(*this, X);
|
max@0
|
1687
|
max@0
|
1688 return *this;
|
max@0
|
1689 }
|
max@0
|
1690
|
max@0
|
1691
|
max@0
|
1692
|
max@0
|
1693 template<typename eT>
|
max@0
|
1694 template<typename T1>
|
max@0
|
1695 inline
|
max@0
|
1696 const Mat<eT>&
|
max@0
|
1697 Mat<eT>::operator+=(const subview_elem1<eT,T1>& X)
|
max@0
|
1698 {
|
max@0
|
1699 arma_extra_debug_sigprint();
|
max@0
|
1700
|
max@0
|
1701 subview_elem1<eT,T1>::plus_inplace(*this, X);
|
max@0
|
1702
|
max@0
|
1703 return *this;
|
max@0
|
1704 }
|
max@0
|
1705
|
max@0
|
1706
|
max@0
|
1707
|
max@0
|
1708 template<typename eT>
|
max@0
|
1709 template<typename T1>
|
max@0
|
1710 inline
|
max@0
|
1711 const Mat<eT>&
|
max@0
|
1712 Mat<eT>::operator-=(const subview_elem1<eT,T1>& X)
|
max@0
|
1713 {
|
max@0
|
1714 arma_extra_debug_sigprint();
|
max@0
|
1715
|
max@0
|
1716 subview_elem1<eT,T1>::minus_inplace(*this, X);
|
max@0
|
1717
|
max@0
|
1718 return *this;
|
max@0
|
1719 }
|
max@0
|
1720
|
max@0
|
1721
|
max@0
|
1722
|
max@0
|
1723 template<typename eT>
|
max@0
|
1724 template<typename T1>
|
max@0
|
1725 inline
|
max@0
|
1726 const Mat<eT>&
|
max@0
|
1727 Mat<eT>::operator*=(const subview_elem1<eT,T1>& X)
|
max@0
|
1728 {
|
max@0
|
1729 arma_extra_debug_sigprint();
|
max@0
|
1730
|
max@0
|
1731 glue_times::apply_inplace(*this, X);
|
max@0
|
1732
|
max@0
|
1733 return *this;
|
max@0
|
1734 }
|
max@0
|
1735
|
max@0
|
1736
|
max@0
|
1737
|
max@0
|
1738 template<typename eT>
|
max@0
|
1739 template<typename T1>
|
max@0
|
1740 inline
|
max@0
|
1741 const Mat<eT>&
|
max@0
|
1742 Mat<eT>::operator%=(const subview_elem1<eT,T1>& X)
|
max@0
|
1743 {
|
max@0
|
1744 arma_extra_debug_sigprint();
|
max@0
|
1745
|
max@0
|
1746 subview_elem1<eT,T1>::schur_inplace(*this, X);
|
max@0
|
1747
|
max@0
|
1748 return *this;
|
max@0
|
1749 }
|
max@0
|
1750
|
max@0
|
1751
|
max@0
|
1752
|
max@0
|
1753 template<typename eT>
|
max@0
|
1754 template<typename T1>
|
max@0
|
1755 inline
|
max@0
|
1756 const Mat<eT>&
|
max@0
|
1757 Mat<eT>::operator/=(const subview_elem1<eT,T1>& X)
|
max@0
|
1758 {
|
max@0
|
1759 arma_extra_debug_sigprint();
|
max@0
|
1760
|
max@0
|
1761 subview_elem1<eT,T1>::div_inplace(*this, X);
|
max@0
|
1762
|
max@0
|
1763 return *this;
|
max@0
|
1764 }
|
max@0
|
1765
|
max@0
|
1766
|
max@0
|
1767
|
max@0
|
1768 template<typename eT>
|
max@0
|
1769 inline
|
max@0
|
1770 mat_injector< Mat<eT> >
|
max@0
|
1771 Mat<eT>::operator<<(const eT val)
|
max@0
|
1772 {
|
max@0
|
1773 return mat_injector< Mat<eT> >(*this, val);
|
max@0
|
1774 }
|
max@0
|
1775
|
max@0
|
1776
|
max@0
|
1777
|
max@0
|
1778 template<typename eT>
|
max@0
|
1779 inline
|
max@0
|
1780 mat_injector< Mat<eT> >
|
max@0
|
1781 Mat<eT>::operator<<(const injector_end_of_row& x)
|
max@0
|
1782 {
|
max@0
|
1783 return mat_injector< Mat<eT> >(*this, x);
|
max@0
|
1784 }
|
max@0
|
1785
|
max@0
|
1786
|
max@0
|
1787
|
max@0
|
1788 //! creation of subview (row vector)
|
max@0
|
1789 template<typename eT>
|
max@0
|
1790 arma_inline
|
max@0
|
1791 subview_row<eT>
|
max@0
|
1792 Mat<eT>::row(const uword row_num)
|
max@0
|
1793 {
|
max@0
|
1794 arma_extra_debug_sigprint();
|
max@0
|
1795
|
max@0
|
1796 arma_debug_check( row_num >= n_rows, "Mat::row(): out of bounds" );
|
max@0
|
1797
|
max@0
|
1798 return subview_row<eT>(*this, row_num);
|
max@0
|
1799 }
|
max@0
|
1800
|
max@0
|
1801
|
max@0
|
1802
|
max@0
|
1803 //! creation of subview (row vector)
|
max@0
|
1804 template<typename eT>
|
max@0
|
1805 arma_inline
|
max@0
|
1806 const subview_row<eT>
|
max@0
|
1807 Mat<eT>::row(const uword row_num) const
|
max@0
|
1808 {
|
max@0
|
1809 arma_extra_debug_sigprint();
|
max@0
|
1810
|
max@0
|
1811 arma_debug_check( row_num >= n_rows, "Mat::row(): out of bounds" );
|
max@0
|
1812
|
max@0
|
1813 return subview_row<eT>(*this, row_num);
|
max@0
|
1814 }
|
max@0
|
1815
|
max@0
|
1816
|
max@0
|
1817
|
max@0
|
1818 template<typename eT>
|
max@0
|
1819 inline
|
max@0
|
1820 subview_row<eT>
|
max@0
|
1821 Mat<eT>::operator()(const uword row_num, const span& col_span)
|
max@0
|
1822 {
|
max@0
|
1823 arma_extra_debug_sigprint();
|
max@0
|
1824
|
max@0
|
1825 const bool col_all = col_span.whole;
|
max@0
|
1826
|
max@0
|
1827 const uword local_n_cols = n_cols;
|
max@0
|
1828
|
max@0
|
1829 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
1830 const uword in_col2 = col_span.b;
|
max@0
|
1831 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
1832
|
max@0
|
1833 arma_debug_check
|
max@0
|
1834 (
|
max@0
|
1835 (row_num >= n_rows)
|
max@0
|
1836 ||
|
max@0
|
1837 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
1838 ,
|
max@0
|
1839 "Mat::operator(): indices out of bounds or incorrectly used"
|
max@0
|
1840 );
|
max@0
|
1841
|
max@0
|
1842 return subview_row<eT>(*this, row_num, in_col1, submat_n_cols);
|
max@0
|
1843 }
|
max@0
|
1844
|
max@0
|
1845
|
max@0
|
1846
|
max@0
|
1847 template<typename eT>
|
max@0
|
1848 inline
|
max@0
|
1849 const subview_row<eT>
|
max@0
|
1850 Mat<eT>::operator()(const uword row_num, const span& col_span) const
|
max@0
|
1851 {
|
max@0
|
1852 arma_extra_debug_sigprint();
|
max@0
|
1853
|
max@0
|
1854 const bool col_all = col_span.whole;
|
max@0
|
1855
|
max@0
|
1856 const uword local_n_cols = n_cols;
|
max@0
|
1857
|
max@0
|
1858 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
1859 const uword in_col2 = col_span.b;
|
max@0
|
1860 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
1861
|
max@0
|
1862 arma_debug_check
|
max@0
|
1863 (
|
max@0
|
1864 (row_num >= n_rows)
|
max@0
|
1865 ||
|
max@0
|
1866 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
1867 ,
|
max@0
|
1868 "Mat::operator(): indices out of bounds or incorrectly used"
|
max@0
|
1869 );
|
max@0
|
1870
|
max@0
|
1871 return subview_row<eT>(*this, row_num, in_col1, submat_n_cols);
|
max@0
|
1872 }
|
max@0
|
1873
|
max@0
|
1874
|
max@0
|
1875
|
max@0
|
1876 //! creation of subview (column vector)
|
max@0
|
1877 template<typename eT>
|
max@0
|
1878 arma_inline
|
max@0
|
1879 subview_col<eT>
|
max@0
|
1880 Mat<eT>::col(const uword col_num)
|
max@0
|
1881 {
|
max@0
|
1882 arma_extra_debug_sigprint();
|
max@0
|
1883
|
max@0
|
1884 arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds");
|
max@0
|
1885
|
max@0
|
1886 return subview_col<eT>(*this, col_num);
|
max@0
|
1887 }
|
max@0
|
1888
|
max@0
|
1889
|
max@0
|
1890
|
max@0
|
1891 //! creation of subview (column vector)
|
max@0
|
1892 template<typename eT>
|
max@0
|
1893 arma_inline
|
max@0
|
1894 const subview_col<eT>
|
max@0
|
1895 Mat<eT>::col(const uword col_num) const
|
max@0
|
1896 {
|
max@0
|
1897 arma_extra_debug_sigprint();
|
max@0
|
1898
|
max@0
|
1899 arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds");
|
max@0
|
1900
|
max@0
|
1901 return subview_col<eT>(*this, col_num);
|
max@0
|
1902 }
|
max@0
|
1903
|
max@0
|
1904
|
max@0
|
1905
|
max@0
|
1906 template<typename eT>
|
max@0
|
1907 inline
|
max@0
|
1908 subview_col<eT>
|
max@0
|
1909 Mat<eT>::operator()(const span& row_span, const uword col_num)
|
max@0
|
1910 {
|
max@0
|
1911 arma_extra_debug_sigprint();
|
max@0
|
1912
|
max@0
|
1913 const bool row_all = row_span.whole;
|
max@0
|
1914
|
max@0
|
1915 const uword local_n_rows = n_rows;
|
max@0
|
1916
|
max@0
|
1917 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
1918 const uword in_row2 = row_span.b;
|
max@0
|
1919 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
1920
|
max@0
|
1921 arma_debug_check
|
max@0
|
1922 (
|
max@0
|
1923 (col_num >= n_cols)
|
max@0
|
1924 ||
|
max@0
|
1925 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
1926 ,
|
max@0
|
1927 "Mat::operator(): indices out of bounds or incorrectly used"
|
max@0
|
1928 );
|
max@0
|
1929
|
max@0
|
1930 return subview_col<eT>(*this, col_num, in_row1, submat_n_rows);
|
max@0
|
1931 }
|
max@0
|
1932
|
max@0
|
1933
|
max@0
|
1934
|
max@0
|
1935 template<typename eT>
|
max@0
|
1936 inline
|
max@0
|
1937 const subview_col<eT>
|
max@0
|
1938 Mat<eT>::operator()(const span& row_span, const uword col_num) const
|
max@0
|
1939 {
|
max@0
|
1940 arma_extra_debug_sigprint();
|
max@0
|
1941
|
max@0
|
1942 const bool row_all = row_span.whole;
|
max@0
|
1943
|
max@0
|
1944 const uword local_n_rows = n_rows;
|
max@0
|
1945
|
max@0
|
1946 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
1947 const uword in_row2 = row_span.b;
|
max@0
|
1948 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
1949
|
max@0
|
1950 arma_debug_check
|
max@0
|
1951 (
|
max@0
|
1952 (col_num >= n_cols)
|
max@0
|
1953 ||
|
max@0
|
1954 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
1955 ,
|
max@0
|
1956 "Mat::operator(): indices out of bounds or incorrectly used"
|
max@0
|
1957 );
|
max@0
|
1958
|
max@0
|
1959 return subview_col<eT>(*this, col_num, in_row1, submat_n_rows);
|
max@0
|
1960 }
|
max@0
|
1961
|
max@0
|
1962
|
max@0
|
1963
|
max@0
|
1964 //! create a Col object which uses memory from an existing matrix object.
|
max@0
|
1965 //! this approach is currently not alias safe
|
max@0
|
1966 //! and does not take into account that the parent matrix object could be deleted.
|
max@0
|
1967 //! if deleted memory is accessed by the created Col object,
|
max@0
|
1968 //! it will cause memory corruption and/or a crash
|
max@0
|
1969 template<typename eT>
|
max@0
|
1970 inline
|
max@0
|
1971 Col<eT>
|
max@0
|
1972 Mat<eT>::unsafe_col(const uword col_num)
|
max@0
|
1973 {
|
max@0
|
1974 arma_extra_debug_sigprint();
|
max@0
|
1975
|
max@0
|
1976 arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): out of bounds");
|
max@0
|
1977
|
max@0
|
1978 return Col<eT>(colptr(col_num), n_rows, false, true);
|
max@0
|
1979 }
|
max@0
|
1980
|
max@0
|
1981
|
max@0
|
1982
|
max@0
|
1983 //! create a Col object which uses memory from an existing matrix object.
|
max@0
|
1984 //! this approach is currently not alias safe
|
max@0
|
1985 //! and does not take into account that the parent matrix object could be deleted.
|
max@0
|
1986 //! if deleted memory is accessed by the created Col object,
|
max@0
|
1987 //! it will cause memory corruption and/or a crash
|
max@0
|
1988 template<typename eT>
|
max@0
|
1989 inline
|
max@0
|
1990 const Col<eT>
|
max@0
|
1991 Mat<eT>::unsafe_col(const uword col_num) const
|
max@0
|
1992 {
|
max@0
|
1993 arma_extra_debug_sigprint();
|
max@0
|
1994
|
max@0
|
1995 arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): out of bounds");
|
max@0
|
1996
|
max@0
|
1997 typedef const Col<eT> out_type;
|
max@0
|
1998
|
max@0
|
1999 return out_type(const_cast<eT*>(colptr(col_num)), n_rows, false, true);
|
max@0
|
2000 }
|
max@0
|
2001
|
max@0
|
2002
|
max@0
|
2003
|
max@0
|
2004 //! creation of subview (submatrix comprised of specified row vectors)
|
max@0
|
2005 template<typename eT>
|
max@0
|
2006 arma_inline
|
max@0
|
2007 subview<eT>
|
max@0
|
2008 Mat<eT>::rows(const uword in_row1, const uword in_row2)
|
max@0
|
2009 {
|
max@0
|
2010 arma_extra_debug_sigprint();
|
max@0
|
2011
|
max@0
|
2012 arma_debug_check
|
max@0
|
2013 (
|
max@0
|
2014 (in_row1 > in_row2) || (in_row2 >= n_rows),
|
max@0
|
2015 "Mat::rows(): indices out of bounds or incorrectly used"
|
max@0
|
2016 );
|
max@0
|
2017
|
max@0
|
2018 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
2019
|
max@0
|
2020 return subview<eT>(*this, in_row1, 0, subview_n_rows, n_cols );
|
max@0
|
2021 }
|
max@0
|
2022
|
max@0
|
2023
|
max@0
|
2024
|
max@0
|
2025 //! creation of subview (submatrix comprised of specified row vectors)
|
max@0
|
2026 template<typename eT>
|
max@0
|
2027 arma_inline
|
max@0
|
2028 const subview<eT>
|
max@0
|
2029 Mat<eT>::rows(const uword in_row1, const uword in_row2) const
|
max@0
|
2030 {
|
max@0
|
2031 arma_extra_debug_sigprint();
|
max@0
|
2032
|
max@0
|
2033 arma_debug_check
|
max@0
|
2034 (
|
max@0
|
2035 (in_row1 > in_row2) || (in_row2 >= n_rows),
|
max@0
|
2036 "Mat::rows(): indices out of bounds or incorrectly used"
|
max@0
|
2037 );
|
max@0
|
2038
|
max@0
|
2039 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
2040
|
max@0
|
2041 return subview<eT>(*this, in_row1, 0, subview_n_rows, n_cols );
|
max@0
|
2042 }
|
max@0
|
2043
|
max@0
|
2044
|
max@0
|
2045
|
max@0
|
2046 //! creation of subview (submatrix comprised of specified column vectors)
|
max@0
|
2047 template<typename eT>
|
max@0
|
2048 arma_inline
|
max@0
|
2049 subview<eT>
|
max@0
|
2050 Mat<eT>::cols(const uword in_col1, const uword in_col2)
|
max@0
|
2051 {
|
max@0
|
2052 arma_extra_debug_sigprint();
|
max@0
|
2053
|
max@0
|
2054 arma_debug_check
|
max@0
|
2055 (
|
max@0
|
2056 (in_col1 > in_col2) || (in_col2 >= n_cols),
|
max@0
|
2057 "Mat::cols(): indices out of bounds or incorrectly used"
|
max@0
|
2058 );
|
max@0
|
2059
|
max@0
|
2060 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
2061
|
max@0
|
2062 return subview<eT>(*this, 0, in_col1, n_rows, subview_n_cols);
|
max@0
|
2063 }
|
max@0
|
2064
|
max@0
|
2065
|
max@0
|
2066
|
max@0
|
2067 //! creation of subview (submatrix comprised of specified column vectors)
|
max@0
|
2068 template<typename eT>
|
max@0
|
2069 arma_inline
|
max@0
|
2070 const subview<eT>
|
max@0
|
2071 Mat<eT>::cols(const uword in_col1, const uword in_col2) const
|
max@0
|
2072 {
|
max@0
|
2073 arma_extra_debug_sigprint();
|
max@0
|
2074
|
max@0
|
2075 arma_debug_check
|
max@0
|
2076 (
|
max@0
|
2077 (in_col1 > in_col2) || (in_col2 >= n_cols),
|
max@0
|
2078 "Mat::cols(): indices out of bounds or incorrectly used"
|
max@0
|
2079 );
|
max@0
|
2080
|
max@0
|
2081 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
2082
|
max@0
|
2083 return subview<eT>(*this, 0, in_col1, n_rows, subview_n_cols);
|
max@0
|
2084 }
|
max@0
|
2085
|
max@0
|
2086
|
max@0
|
2087
|
max@0
|
2088 //! creation of subview (submatrix)
|
max@0
|
2089 template<typename eT>
|
max@0
|
2090 arma_inline
|
max@0
|
2091 subview<eT>
|
max@0
|
2092 Mat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2)
|
max@0
|
2093 {
|
max@0
|
2094 arma_extra_debug_sigprint();
|
max@0
|
2095
|
max@0
|
2096 arma_debug_check
|
max@0
|
2097 (
|
max@0
|
2098 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
|
max@0
|
2099 "Mat::submat(): indices out of bounds or incorrectly used"
|
max@0
|
2100 );
|
max@0
|
2101
|
max@0
|
2102 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
2103 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
2104
|
max@0
|
2105 return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_cols);
|
max@0
|
2106 }
|
max@0
|
2107
|
max@0
|
2108
|
max@0
|
2109
|
max@0
|
2110 //! creation of subview (generic submatrix)
|
max@0
|
2111 template<typename eT>
|
max@0
|
2112 arma_inline
|
max@0
|
2113 const subview<eT>
|
max@0
|
2114 Mat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const
|
max@0
|
2115 {
|
max@0
|
2116 arma_extra_debug_sigprint();
|
max@0
|
2117
|
max@0
|
2118 arma_debug_check
|
max@0
|
2119 (
|
max@0
|
2120 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
|
max@0
|
2121 "Mat::submat(): indices out of bounds or incorrectly used"
|
max@0
|
2122 );
|
max@0
|
2123
|
max@0
|
2124 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
2125 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
2126
|
max@0
|
2127 return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_cols);
|
max@0
|
2128 }
|
max@0
|
2129
|
max@0
|
2130
|
max@0
|
2131
|
max@0
|
2132 //! creation of subview (submatrix)
|
max@0
|
2133 template<typename eT>
|
max@0
|
2134 inline
|
max@0
|
2135 subview<eT>
|
max@0
|
2136 Mat<eT>::submat(const span& row_span, const span& col_span)
|
max@0
|
2137 {
|
max@0
|
2138 arma_extra_debug_sigprint();
|
max@0
|
2139
|
max@0
|
2140 const bool row_all = row_span.whole;
|
max@0
|
2141 const bool col_all = col_span.whole;
|
max@0
|
2142
|
max@0
|
2143 const uword local_n_rows = n_rows;
|
max@0
|
2144 const uword local_n_cols = n_cols;
|
max@0
|
2145
|
max@0
|
2146 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
2147 const uword in_row2 = row_span.b;
|
max@0
|
2148 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
2149
|
max@0
|
2150 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
2151 const uword in_col2 = col_span.b;
|
max@0
|
2152 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
2153
|
max@0
|
2154 arma_debug_check
|
max@0
|
2155 (
|
max@0
|
2156 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
2157 ||
|
max@0
|
2158 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
2159 ,
|
max@0
|
2160 "Mat::submat(): indices out of bounds or incorrectly used"
|
max@0
|
2161 );
|
max@0
|
2162
|
max@0
|
2163 return subview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols);
|
max@0
|
2164 }
|
max@0
|
2165
|
max@0
|
2166
|
max@0
|
2167
|
max@0
|
2168 //! creation of subview (generic submatrix)
|
max@0
|
2169 template<typename eT>
|
max@0
|
2170 inline
|
max@0
|
2171 const subview<eT>
|
max@0
|
2172 Mat<eT>::submat(const span& row_span, const span& col_span) const
|
max@0
|
2173 {
|
max@0
|
2174 arma_extra_debug_sigprint();
|
max@0
|
2175
|
max@0
|
2176 const bool row_all = row_span.whole;
|
max@0
|
2177 const bool col_all = col_span.whole;
|
max@0
|
2178
|
max@0
|
2179 const uword local_n_rows = n_rows;
|
max@0
|
2180 const uword local_n_cols = n_cols;
|
max@0
|
2181
|
max@0
|
2182 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
2183 const uword in_row2 = row_span.b;
|
max@0
|
2184 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
2185
|
max@0
|
2186 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
2187 const uword in_col2 = col_span.b;
|
max@0
|
2188 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
2189
|
max@0
|
2190 arma_debug_check
|
max@0
|
2191 (
|
max@0
|
2192 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
2193 ||
|
max@0
|
2194 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
2195 ,
|
max@0
|
2196 "Mat::submat(): indices out of bounds or incorrectly used"
|
max@0
|
2197 );
|
max@0
|
2198
|
max@0
|
2199 return subview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols);
|
max@0
|
2200 }
|
max@0
|
2201
|
max@0
|
2202
|
max@0
|
2203
|
max@0
|
2204 template<typename eT>
|
max@0
|
2205 inline
|
max@0
|
2206 subview<eT>
|
max@0
|
2207 Mat<eT>::operator()(const span& row_span, const span& col_span)
|
max@0
|
2208 {
|
max@0
|
2209 arma_extra_debug_sigprint();
|
max@0
|
2210
|
max@0
|
2211 return (*this).submat(row_span, col_span);
|
max@0
|
2212 }
|
max@0
|
2213
|
max@0
|
2214
|
max@0
|
2215
|
max@0
|
2216 template<typename eT>
|
max@0
|
2217 inline
|
max@0
|
2218 const subview<eT>
|
max@0
|
2219 Mat<eT>::operator()(const span& row_span, const span& col_span) const
|
max@0
|
2220 {
|
max@0
|
2221 arma_extra_debug_sigprint();
|
max@0
|
2222
|
max@0
|
2223 return (*this).submat(row_span, col_span);
|
max@0
|
2224 }
|
max@0
|
2225
|
max@0
|
2226
|
max@0
|
2227
|
max@0
|
2228 template<typename eT>
|
max@0
|
2229 template<typename T1>
|
max@0
|
2230 arma_inline
|
max@0
|
2231 subview_elem1<eT,T1>
|
max@0
|
2232 Mat<eT>::elem(const Base<uword,T1>& a)
|
max@0
|
2233 {
|
max@0
|
2234 arma_extra_debug_sigprint();
|
max@0
|
2235
|
max@0
|
2236 return subview_elem1<eT,T1>(*this, a);
|
max@0
|
2237 }
|
max@0
|
2238
|
max@0
|
2239
|
max@0
|
2240
|
max@0
|
2241 template<typename eT>
|
max@0
|
2242 template<typename T1>
|
max@0
|
2243 arma_inline
|
max@0
|
2244 const subview_elem1<eT,T1>
|
max@0
|
2245 Mat<eT>::elem(const Base<uword,T1>& a) const
|
max@0
|
2246 {
|
max@0
|
2247 arma_extra_debug_sigprint();
|
max@0
|
2248
|
max@0
|
2249 return subview_elem1<eT,T1>(*this, a);
|
max@0
|
2250 }
|
max@0
|
2251
|
max@0
|
2252
|
max@0
|
2253
|
max@0
|
2254 // template<typename eT>
|
max@0
|
2255 // template<typename T1, typename T2>
|
max@0
|
2256 // arma_inline
|
max@0
|
2257 // subview_elem2<eT,T1,T2>
|
max@0
|
2258 // Mat<eT>::elem(const Base<uword,T1>& a, const Base<uword,T2>& b)
|
max@0
|
2259 // {
|
max@0
|
2260 // arma_extra_debug_sigprint();
|
max@0
|
2261 //
|
max@0
|
2262 // return subview_elem2<eT,T1,T2>(*this, a, b);
|
max@0
|
2263 // }
|
max@0
|
2264 //
|
max@0
|
2265 //
|
max@0
|
2266 //
|
max@0
|
2267 // template<typename eT>
|
max@0
|
2268 // template<typename T1, typename T2>
|
max@0
|
2269 // arma_inline
|
max@0
|
2270 // const subview_elem2<eT,T1,T2>
|
max@0
|
2271 // Mat<eT>::elem(const Base<uword,T1>& a, const Base<uword,T2>& b) const
|
max@0
|
2272 // {
|
max@0
|
2273 // arma_extra_debug_sigprint();
|
max@0
|
2274 //
|
max@0
|
2275 // return subview_elem2<eT,T1,T2>(*this, a, b);
|
max@0
|
2276 // }
|
max@0
|
2277
|
max@0
|
2278
|
max@0
|
2279
|
max@0
|
2280 //! creation of diagview (diagonal)
|
max@0
|
2281 template<typename eT>
|
max@0
|
2282 arma_inline
|
max@0
|
2283 diagview<eT>
|
max@0
|
2284 Mat<eT>::diag(const sword in_id)
|
max@0
|
2285 {
|
max@0
|
2286 arma_extra_debug_sigprint();
|
max@0
|
2287
|
max@0
|
2288 const uword row_offset = (in_id < 0) ? uword(-in_id) : 0;
|
max@0
|
2289 const uword col_offset = (in_id > 0) ? uword( in_id) : 0;
|
max@0
|
2290
|
max@0
|
2291 arma_debug_check
|
max@0
|
2292 (
|
max@0
|
2293 ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
|
max@0
|
2294 "Mat::diag(): requested diagonal out of bounds"
|
max@0
|
2295 );
|
max@0
|
2296
|
max@0
|
2297 const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
|
max@0
|
2298
|
max@0
|
2299 return diagview<eT>(*this, row_offset, col_offset, len);
|
max@0
|
2300 }
|
max@0
|
2301
|
max@0
|
2302
|
max@0
|
2303
|
max@0
|
2304 //! creation of diagview (diagonal)
|
max@0
|
2305 template<typename eT>
|
max@0
|
2306 arma_inline
|
max@0
|
2307 const diagview<eT>
|
max@0
|
2308 Mat<eT>::diag(const sword in_id) const
|
max@0
|
2309 {
|
max@0
|
2310 arma_extra_debug_sigprint();
|
max@0
|
2311
|
max@0
|
2312 const uword row_offset = (in_id < 0) ? -in_id : 0;
|
max@0
|
2313 const uword col_offset = (in_id > 0) ? in_id : 0;
|
max@0
|
2314
|
max@0
|
2315 arma_debug_check
|
max@0
|
2316 (
|
max@0
|
2317 ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
|
max@0
|
2318 "Mat::diag(): requested diagonal out of bounds"
|
max@0
|
2319 );
|
max@0
|
2320
|
max@0
|
2321 const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
|
max@0
|
2322
|
max@0
|
2323 return diagview<eT>(*this, row_offset, col_offset, len);
|
max@0
|
2324 }
|
max@0
|
2325
|
max@0
|
2326
|
max@0
|
2327
|
max@0
|
2328 template<typename eT>
|
max@0
|
2329 inline
|
max@0
|
2330 void
|
max@0
|
2331 Mat<eT>::swap_rows(const uword in_row1, const uword in_row2)
|
max@0
|
2332 {
|
max@0
|
2333 arma_extra_debug_sigprint();
|
max@0
|
2334
|
max@0
|
2335 arma_debug_check
|
max@0
|
2336 (
|
max@0
|
2337 (in_row1 >= n_rows) || (in_row2 >= n_rows),
|
max@0
|
2338 "Mat::swap_rows(): out of bounds"
|
max@0
|
2339 );
|
max@0
|
2340
|
max@0
|
2341 for(uword col=0; col<n_cols; ++col)
|
max@0
|
2342 {
|
max@0
|
2343 const uword offset = col*n_rows;
|
max@0
|
2344 const uword pos1 = in_row1 + offset;
|
max@0
|
2345 const uword pos2 = in_row2 + offset;
|
max@0
|
2346
|
max@0
|
2347 const eT tmp = mem[pos1];
|
max@0
|
2348 access::rw(mem[pos1]) = mem[pos2];
|
max@0
|
2349 access::rw(mem[pos2]) = tmp;
|
max@0
|
2350 }
|
max@0
|
2351
|
max@0
|
2352 }
|
max@0
|
2353
|
max@0
|
2354
|
max@0
|
2355
|
max@0
|
2356 template<typename eT>
|
max@0
|
2357 inline
|
max@0
|
2358 void
|
max@0
|
2359 Mat<eT>::swap_cols(const uword in_col1, const uword in_col2)
|
max@0
|
2360 {
|
max@0
|
2361 arma_extra_debug_sigprint();
|
max@0
|
2362
|
max@0
|
2363 arma_debug_check
|
max@0
|
2364 (
|
max@0
|
2365 (in_col1 >= n_cols) || (in_col2 >= n_cols),
|
max@0
|
2366 "Mat::swap_cols(): out of bounds"
|
max@0
|
2367 );
|
max@0
|
2368
|
max@0
|
2369 if(n_elem > 0)
|
max@0
|
2370 {
|
max@0
|
2371 eT* ptr1 = colptr(in_col1);
|
max@0
|
2372 eT* ptr2 = colptr(in_col2);
|
max@0
|
2373
|
max@0
|
2374 for(uword row=0; row<n_rows; ++row)
|
max@0
|
2375 {
|
max@0
|
2376 const eT tmp = ptr1[row];
|
max@0
|
2377 ptr1[row] = ptr2[row];
|
max@0
|
2378 ptr2[row] = tmp;
|
max@0
|
2379 }
|
max@0
|
2380 }
|
max@0
|
2381 }
|
max@0
|
2382
|
max@0
|
2383
|
max@0
|
2384
|
max@0
|
2385 //! remove specified row
|
max@0
|
2386 template<typename eT>
|
max@0
|
2387 inline
|
max@0
|
2388 void
|
max@0
|
2389 Mat<eT>::shed_row(const uword row_num)
|
max@0
|
2390 {
|
max@0
|
2391 arma_extra_debug_sigprint();
|
max@0
|
2392
|
max@0
|
2393 arma_debug_check( row_num >= n_rows, "Mat::shed_row(): out of bounds");
|
max@0
|
2394
|
max@0
|
2395 shed_rows(row_num, row_num);
|
max@0
|
2396 }
|
max@0
|
2397
|
max@0
|
2398
|
max@0
|
2399
|
max@0
|
2400 //! remove specified column
|
max@0
|
2401 template<typename eT>
|
max@0
|
2402 inline
|
max@0
|
2403 void
|
max@0
|
2404 Mat<eT>::shed_col(const uword col_num)
|
max@0
|
2405 {
|
max@0
|
2406 arma_extra_debug_sigprint();
|
max@0
|
2407
|
max@0
|
2408 arma_debug_check( col_num >= n_cols, "Mat::shed_col(): out of bounds");
|
max@0
|
2409
|
max@0
|
2410 shed_cols(col_num, col_num);
|
max@0
|
2411 }
|
max@0
|
2412
|
max@0
|
2413
|
max@0
|
2414
|
max@0
|
2415 //! remove specified rows
|
max@0
|
2416 template<typename eT>
|
max@0
|
2417 inline
|
max@0
|
2418 void
|
max@0
|
2419 Mat<eT>::shed_rows(const uword in_row1, const uword in_row2)
|
max@0
|
2420 {
|
max@0
|
2421 arma_extra_debug_sigprint();
|
max@0
|
2422
|
max@0
|
2423 arma_debug_check
|
max@0
|
2424 (
|
max@0
|
2425 (in_row1 > in_row2) || (in_row2 >= n_rows),
|
max@0
|
2426 "Mat::shed_rows(): indices out of bounds or incorrectly used"
|
max@0
|
2427 );
|
max@0
|
2428
|
max@0
|
2429 const uword n_keep_front = in_row1;
|
max@0
|
2430 const uword n_keep_back = n_rows - (in_row2 + 1);
|
max@0
|
2431
|
max@0
|
2432 Mat<eT> X(n_keep_front + n_keep_back, n_cols);
|
max@0
|
2433
|
max@0
|
2434 if(n_keep_front > 0)
|
max@0
|
2435 {
|
max@0
|
2436 X.rows( 0, (n_keep_front-1) ) = rows( 0, (in_row1-1) );
|
max@0
|
2437 }
|
max@0
|
2438
|
max@0
|
2439 if(n_keep_back > 0)
|
max@0
|
2440 {
|
max@0
|
2441 X.rows( n_keep_front, (n_keep_front+n_keep_back-1) ) = rows( (in_row2+1), (n_rows-1) );
|
max@0
|
2442 }
|
max@0
|
2443
|
max@0
|
2444 steal_mem(X);
|
max@0
|
2445 }
|
max@0
|
2446
|
max@0
|
2447
|
max@0
|
2448
|
max@0
|
2449 //! remove specified columns
|
max@0
|
2450 template<typename eT>
|
max@0
|
2451 inline
|
max@0
|
2452 void
|
max@0
|
2453 Mat<eT>::shed_cols(const uword in_col1, const uword in_col2)
|
max@0
|
2454 {
|
max@0
|
2455 arma_extra_debug_sigprint();
|
max@0
|
2456
|
max@0
|
2457 arma_debug_check
|
max@0
|
2458 (
|
max@0
|
2459 (in_col1 > in_col2) || (in_col2 >= n_cols),
|
max@0
|
2460 "Mat::shed_cols(): indices out of bounds or incorrectly used"
|
max@0
|
2461 );
|
max@0
|
2462
|
max@0
|
2463 const uword n_keep_front = in_col1;
|
max@0
|
2464 const uword n_keep_back = n_cols - (in_col2 + 1);
|
max@0
|
2465
|
max@0
|
2466 Mat<eT> X(n_rows, n_keep_front + n_keep_back);
|
max@0
|
2467
|
max@0
|
2468 if(n_keep_front > 0)
|
max@0
|
2469 {
|
max@0
|
2470 X.cols( 0, (n_keep_front-1) ) = cols( 0, (in_col1-1) );
|
max@0
|
2471 }
|
max@0
|
2472
|
max@0
|
2473 if(n_keep_back > 0)
|
max@0
|
2474 {
|
max@0
|
2475 X.cols( n_keep_front, (n_keep_front+n_keep_back-1) ) = cols( (in_col2+1), (n_cols-1) );
|
max@0
|
2476 }
|
max@0
|
2477
|
max@0
|
2478 steal_mem(X);
|
max@0
|
2479 }
|
max@0
|
2480
|
max@0
|
2481
|
max@0
|
2482
|
max@0
|
2483 //! insert N rows at the specified row position,
|
max@0
|
2484 //! optionally setting the elements of the inserted rows to zero
|
max@0
|
2485 template<typename eT>
|
max@0
|
2486 inline
|
max@0
|
2487 void
|
max@0
|
2488 Mat<eT>::insert_rows(const uword row_num, const uword N, const bool set_to_zero)
|
max@0
|
2489 {
|
max@0
|
2490 arma_extra_debug_sigprint();
|
max@0
|
2491
|
max@0
|
2492 const uword t_n_rows = n_rows;
|
max@0
|
2493 const uword t_n_cols = n_cols;
|
max@0
|
2494
|
max@0
|
2495 const uword A_n_rows = row_num;
|
max@0
|
2496 const uword B_n_rows = t_n_rows - row_num;
|
max@0
|
2497
|
max@0
|
2498 // insertion at row_num == n_rows is in effect an append operation
|
max@0
|
2499 arma_debug_check( (row_num > t_n_rows), "Mat::insert_rows(): out of bounds");
|
max@0
|
2500
|
max@0
|
2501 if(N > 0)
|
max@0
|
2502 {
|
max@0
|
2503 Mat<eT> out(t_n_rows + N, t_n_cols);
|
max@0
|
2504
|
max@0
|
2505 if(A_n_rows > 0)
|
max@0
|
2506 {
|
max@0
|
2507 out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1);
|
max@0
|
2508 }
|
max@0
|
2509
|
max@0
|
2510 if(B_n_rows > 0)
|
max@0
|
2511 {
|
max@0
|
2512 out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows-1);
|
max@0
|
2513 }
|
max@0
|
2514
|
max@0
|
2515 if(set_to_zero == true)
|
max@0
|
2516 {
|
max@0
|
2517 out.rows(row_num, row_num + N - 1).zeros();
|
max@0
|
2518 }
|
max@0
|
2519
|
max@0
|
2520 steal_mem(out);
|
max@0
|
2521 }
|
max@0
|
2522 }
|
max@0
|
2523
|
max@0
|
2524
|
max@0
|
2525
|
max@0
|
2526 //! insert N columns at the specified column position,
|
max@0
|
2527 //! optionally setting the elements of the inserted columns to zero
|
max@0
|
2528 template<typename eT>
|
max@0
|
2529 inline
|
max@0
|
2530 void
|
max@0
|
2531 Mat<eT>::insert_cols(const uword col_num, const uword N, const bool set_to_zero)
|
max@0
|
2532 {
|
max@0
|
2533 arma_extra_debug_sigprint();
|
max@0
|
2534
|
max@0
|
2535 const uword t_n_rows = n_rows;
|
max@0
|
2536 const uword t_n_cols = n_cols;
|
max@0
|
2537
|
max@0
|
2538 const uword A_n_cols = col_num;
|
max@0
|
2539 const uword B_n_cols = t_n_cols - col_num;
|
max@0
|
2540
|
max@0
|
2541 // insertion at col_num == n_cols is in effect an append operation
|
max@0
|
2542 arma_debug_check( (col_num > t_n_cols), "Mat::insert_cols(): out of bounds");
|
max@0
|
2543
|
max@0
|
2544 if(N > 0)
|
max@0
|
2545 {
|
max@0
|
2546 Mat<eT> out(t_n_rows, t_n_cols + N);
|
max@0
|
2547
|
max@0
|
2548 if(A_n_cols > 0)
|
max@0
|
2549 {
|
max@0
|
2550 out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1);
|
max@0
|
2551 }
|
max@0
|
2552
|
max@0
|
2553 if(B_n_cols > 0)
|
max@0
|
2554 {
|
max@0
|
2555 out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols-1);
|
max@0
|
2556 }
|
max@0
|
2557
|
max@0
|
2558 if(set_to_zero == true)
|
max@0
|
2559 {
|
max@0
|
2560 out.cols(col_num, col_num + N - 1).zeros();
|
max@0
|
2561 }
|
max@0
|
2562
|
max@0
|
2563 steal_mem(out);
|
max@0
|
2564 }
|
max@0
|
2565 }
|
max@0
|
2566
|
max@0
|
2567
|
max@0
|
2568
|
max@0
|
2569 //! insert the given object at the specified row position;
|
max@0
|
2570 //! the given object must have the same number of columns as the matrix
|
max@0
|
2571 template<typename eT>
|
max@0
|
2572 template<typename T1>
|
max@0
|
2573 inline
|
max@0
|
2574 void
|
max@0
|
2575 Mat<eT>::insert_rows(const uword row_num, const Base<eT,T1>& X)
|
max@0
|
2576 {
|
max@0
|
2577 arma_extra_debug_sigprint();
|
max@0
|
2578
|
max@0
|
2579 const unwrap<T1> tmp(X.get_ref());
|
max@0
|
2580 const Mat<eT>& C = tmp.M;
|
max@0
|
2581
|
max@0
|
2582 const uword C_n_rows = C.n_rows;
|
max@0
|
2583 const uword C_n_cols = C.n_cols;
|
max@0
|
2584
|
max@0
|
2585 const uword t_n_rows = n_rows;
|
max@0
|
2586 const uword t_n_cols = n_cols;
|
max@0
|
2587
|
max@0
|
2588 const uword A_n_rows = row_num;
|
max@0
|
2589 const uword B_n_rows = t_n_rows - row_num;
|
max@0
|
2590
|
max@0
|
2591 bool err_state = false;
|
max@0
|
2592 char* err_msg = 0;
|
max@0
|
2593
|
max@0
|
2594 // insertion at row_num == n_rows is in effect an append operation
|
max@0
|
2595
|
max@0
|
2596 arma_debug_set_error
|
max@0
|
2597 (
|
max@0
|
2598 err_state,
|
max@0
|
2599 err_msg,
|
max@0
|
2600 (row_num > t_n_rows),
|
max@0
|
2601 "Mat::insert_rows(): out of bounds"
|
max@0
|
2602 );
|
max@0
|
2603
|
max@0
|
2604 arma_debug_set_error
|
max@0
|
2605 (
|
max@0
|
2606 err_state,
|
max@0
|
2607 err_msg,
|
max@0
|
2608 ( (C_n_cols != t_n_cols) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ),
|
max@0
|
2609 "Mat::insert_rows(): given object has an incompatible number of columns"
|
max@0
|
2610 );
|
max@0
|
2611
|
max@0
|
2612 arma_debug_check(err_state, err_msg);
|
max@0
|
2613
|
max@0
|
2614 if(C_n_rows > 0)
|
max@0
|
2615 {
|
max@0
|
2616 Mat<eT> out( t_n_rows + C_n_rows, (std::max)(t_n_cols, C_n_cols) );
|
max@0
|
2617
|
max@0
|
2618 if(t_n_cols > 0)
|
max@0
|
2619 {
|
max@0
|
2620 if(A_n_rows > 0)
|
max@0
|
2621 {
|
max@0
|
2622 out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1);
|
max@0
|
2623 }
|
max@0
|
2624
|
max@0
|
2625 if( (t_n_cols > 0) && (B_n_rows > 0) )
|
max@0
|
2626 {
|
max@0
|
2627 out.rows(row_num + C_n_rows, t_n_rows + C_n_rows - 1) = rows(row_num, t_n_rows - 1);
|
max@0
|
2628 }
|
max@0
|
2629 }
|
max@0
|
2630
|
max@0
|
2631 if(C_n_cols > 0)
|
max@0
|
2632 {
|
max@0
|
2633 out.rows(row_num, row_num + C_n_rows - 1) = C;
|
max@0
|
2634 }
|
max@0
|
2635
|
max@0
|
2636 steal_mem(out);
|
max@0
|
2637 }
|
max@0
|
2638 }
|
max@0
|
2639
|
max@0
|
2640
|
max@0
|
2641
|
max@0
|
2642 //! insert the given object at the specified column position;
|
max@0
|
2643 //! the given object must have the same number of rows as the matrix
|
max@0
|
2644 template<typename eT>
|
max@0
|
2645 template<typename T1>
|
max@0
|
2646 inline
|
max@0
|
2647 void
|
max@0
|
2648 Mat<eT>::insert_cols(const uword col_num, const Base<eT,T1>& X)
|
max@0
|
2649 {
|
max@0
|
2650 arma_extra_debug_sigprint();
|
max@0
|
2651
|
max@0
|
2652 const unwrap<T1> tmp(X.get_ref());
|
max@0
|
2653 const Mat<eT>& C = tmp.M;
|
max@0
|
2654
|
max@0
|
2655 const uword C_n_rows = C.n_rows;
|
max@0
|
2656 const uword C_n_cols = C.n_cols;
|
max@0
|
2657
|
max@0
|
2658 const uword t_n_rows = n_rows;
|
max@0
|
2659 const uword t_n_cols = n_cols;
|
max@0
|
2660
|
max@0
|
2661 const uword A_n_cols = col_num;
|
max@0
|
2662 const uword B_n_cols = t_n_cols - col_num;
|
max@0
|
2663
|
max@0
|
2664 bool err_state = false;
|
max@0
|
2665 char* err_msg = 0;
|
max@0
|
2666
|
max@0
|
2667 // insertion at col_num == n_cols is in effect an append operation
|
max@0
|
2668
|
max@0
|
2669 arma_debug_set_error
|
max@0
|
2670 (
|
max@0
|
2671 err_state,
|
max@0
|
2672 err_msg,
|
max@0
|
2673 (col_num > t_n_cols),
|
max@0
|
2674 "Mat::insert_cols(): out of bounds"
|
max@0
|
2675 );
|
max@0
|
2676
|
max@0
|
2677 arma_debug_set_error
|
max@0
|
2678 (
|
max@0
|
2679 err_state,
|
max@0
|
2680 err_msg,
|
max@0
|
2681 ( (C_n_rows != t_n_rows) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ),
|
max@0
|
2682 "Mat::insert_cols(): given object has an incompatible number of rows"
|
max@0
|
2683 );
|
max@0
|
2684
|
max@0
|
2685 arma_debug_check(err_state, err_msg);
|
max@0
|
2686
|
max@0
|
2687 if(C_n_cols > 0)
|
max@0
|
2688 {
|
max@0
|
2689 Mat<eT> out( (std::max)(t_n_rows, C_n_rows), t_n_cols + C_n_cols );
|
max@0
|
2690
|
max@0
|
2691 if(t_n_rows > 0)
|
max@0
|
2692 {
|
max@0
|
2693 if(A_n_cols > 0)
|
max@0
|
2694 {
|
max@0
|
2695 out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1);
|
max@0
|
2696 }
|
max@0
|
2697
|
max@0
|
2698 if(B_n_cols > 0)
|
max@0
|
2699 {
|
max@0
|
2700 out.cols(col_num + C_n_cols, t_n_cols + C_n_cols - 1) = cols(col_num, t_n_cols - 1);
|
max@0
|
2701 }
|
max@0
|
2702 }
|
max@0
|
2703
|
max@0
|
2704 if(C_n_rows > 0)
|
max@0
|
2705 {
|
max@0
|
2706 out.cols(col_num, col_num + C_n_cols - 1) = C;
|
max@0
|
2707 }
|
max@0
|
2708
|
max@0
|
2709 steal_mem(out);
|
max@0
|
2710 }
|
max@0
|
2711 }
|
max@0
|
2712
|
max@0
|
2713
|
max@0
|
2714
|
max@0
|
2715 template<typename eT>
|
max@0
|
2716 template<typename gen_type>
|
max@0
|
2717 inline
|
max@0
|
2718 Mat<eT>::Mat(const Gen<eT, gen_type>& X)
|
max@0
|
2719 : n_rows(X.n_rows)
|
max@0
|
2720 , n_cols(X.n_cols)
|
max@0
|
2721 , n_elem(n_rows*n_cols)
|
max@0
|
2722 , vec_state(0)
|
max@0
|
2723 , mem_state(0)
|
max@0
|
2724 , mem()
|
max@0
|
2725 {
|
max@0
|
2726 arma_extra_debug_sigprint_this(this);
|
max@0
|
2727
|
max@0
|
2728 init_cold();
|
max@0
|
2729
|
max@0
|
2730 X.apply(*this);
|
max@0
|
2731 }
|
max@0
|
2732
|
max@0
|
2733
|
max@0
|
2734
|
max@0
|
2735 template<typename eT>
|
max@0
|
2736 template<typename gen_type>
|
max@0
|
2737 inline
|
max@0
|
2738 const Mat<eT>&
|
max@0
|
2739 Mat<eT>::operator=(const Gen<eT, gen_type>& X)
|
max@0
|
2740 {
|
max@0
|
2741 arma_extra_debug_sigprint();
|
max@0
|
2742
|
max@0
|
2743 init_warm(X.n_rows, X.n_cols);
|
max@0
|
2744
|
max@0
|
2745 X.apply(*this);
|
max@0
|
2746
|
max@0
|
2747 return *this;
|
max@0
|
2748 }
|
max@0
|
2749
|
max@0
|
2750
|
max@0
|
2751
|
max@0
|
2752 template<typename eT>
|
max@0
|
2753 template<typename gen_type>
|
max@0
|
2754 inline
|
max@0
|
2755 const Mat<eT>&
|
max@0
|
2756 Mat<eT>::operator+=(const Gen<eT, gen_type>& X)
|
max@0
|
2757 {
|
max@0
|
2758 arma_extra_debug_sigprint();
|
max@0
|
2759
|
max@0
|
2760 X.apply_inplace_plus(*this);
|
max@0
|
2761
|
max@0
|
2762 return *this;
|
max@0
|
2763 }
|
max@0
|
2764
|
max@0
|
2765
|
max@0
|
2766
|
max@0
|
2767 template<typename eT>
|
max@0
|
2768 template<typename gen_type>
|
max@0
|
2769 inline
|
max@0
|
2770 const Mat<eT>&
|
max@0
|
2771 Mat<eT>::operator-=(const Gen<eT, gen_type>& X)
|
max@0
|
2772 {
|
max@0
|
2773 arma_extra_debug_sigprint();
|
max@0
|
2774
|
max@0
|
2775 X.apply_inplace_minus(*this);
|
max@0
|
2776
|
max@0
|
2777 return *this;
|
max@0
|
2778 }
|
max@0
|
2779
|
max@0
|
2780
|
max@0
|
2781
|
max@0
|
2782 template<typename eT>
|
max@0
|
2783 template<typename gen_type>
|
max@0
|
2784 inline
|
max@0
|
2785 const Mat<eT>&
|
max@0
|
2786 Mat<eT>::operator*=(const Gen<eT, gen_type>& X)
|
max@0
|
2787 {
|
max@0
|
2788 arma_extra_debug_sigprint();
|
max@0
|
2789
|
max@0
|
2790 const Mat<eT> tmp(X);
|
max@0
|
2791
|
max@0
|
2792 return (*this).operator*=(tmp);
|
max@0
|
2793 }
|
max@0
|
2794
|
max@0
|
2795
|
max@0
|
2796
|
max@0
|
2797 template<typename eT>
|
max@0
|
2798 template<typename gen_type>
|
max@0
|
2799 inline
|
max@0
|
2800 const Mat<eT>&
|
max@0
|
2801 Mat<eT>::operator%=(const Gen<eT, gen_type>& X)
|
max@0
|
2802 {
|
max@0
|
2803 arma_extra_debug_sigprint();
|
max@0
|
2804
|
max@0
|
2805 X.apply_inplace_schur(*this);
|
max@0
|
2806
|
max@0
|
2807 return *this;
|
max@0
|
2808 }
|
max@0
|
2809
|
max@0
|
2810
|
max@0
|
2811
|
max@0
|
2812 template<typename eT>
|
max@0
|
2813 template<typename gen_type>
|
max@0
|
2814 inline
|
max@0
|
2815 const Mat<eT>&
|
max@0
|
2816 Mat<eT>::operator/=(const Gen<eT, gen_type>& X)
|
max@0
|
2817 {
|
max@0
|
2818 arma_extra_debug_sigprint();
|
max@0
|
2819
|
max@0
|
2820 X.apply_inplace_div(*this);
|
max@0
|
2821
|
max@0
|
2822 return *this;
|
max@0
|
2823 }
|
max@0
|
2824
|
max@0
|
2825
|
max@0
|
2826
|
max@0
|
2827 //! create a matrix from Op, i.e. run the previously delayed unary operations
|
max@0
|
2828 template<typename eT>
|
max@0
|
2829 template<typename T1, typename op_type>
|
max@0
|
2830 inline
|
max@0
|
2831 Mat<eT>::Mat(const Op<T1, op_type>& X)
|
max@0
|
2832 : n_rows(0)
|
max@0
|
2833 , n_cols(0)
|
max@0
|
2834 , n_elem(0)
|
max@0
|
2835 , vec_state(0)
|
max@0
|
2836 , mem_state(0)
|
max@0
|
2837 , mem()
|
max@0
|
2838 {
|
max@0
|
2839 arma_extra_debug_sigprint_this(this);
|
max@0
|
2840
|
max@0
|
2841 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2842
|
max@0
|
2843 op_type::apply(*this, X);
|
max@0
|
2844 }
|
max@0
|
2845
|
max@0
|
2846
|
max@0
|
2847
|
max@0
|
2848 //! create a matrix from Op, i.e. run the previously delayed unary operations
|
max@0
|
2849 template<typename eT>
|
max@0
|
2850 template<typename T1, typename op_type>
|
max@0
|
2851 inline
|
max@0
|
2852 const Mat<eT>&
|
max@0
|
2853 Mat<eT>::operator=(const Op<T1, op_type>& X)
|
max@0
|
2854 {
|
max@0
|
2855 arma_extra_debug_sigprint();
|
max@0
|
2856
|
max@0
|
2857 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2858
|
max@0
|
2859 op_type::apply(*this, X);
|
max@0
|
2860
|
max@0
|
2861 return *this;
|
max@0
|
2862 }
|
max@0
|
2863
|
max@0
|
2864
|
max@0
|
2865
|
max@0
|
2866 //! in-place matrix addition, with the right-hand-side operand having delayed operations
|
max@0
|
2867 template<typename eT>
|
max@0
|
2868 template<typename T1, typename op_type>
|
max@0
|
2869 inline
|
max@0
|
2870 const Mat<eT>&
|
max@0
|
2871 Mat<eT>::operator+=(const Op<T1, op_type>& X)
|
max@0
|
2872 {
|
max@0
|
2873 arma_extra_debug_sigprint();
|
max@0
|
2874
|
max@0
|
2875 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2876
|
max@0
|
2877 const Mat<eT> m(X);
|
max@0
|
2878
|
max@0
|
2879 return (*this).operator+=(m);
|
max@0
|
2880 }
|
max@0
|
2881
|
max@0
|
2882
|
max@0
|
2883
|
max@0
|
2884 //! in-place matrix subtraction, with the right-hand-side operand having delayed operations
|
max@0
|
2885 template<typename eT>
|
max@0
|
2886 template<typename T1, typename op_type>
|
max@0
|
2887 inline
|
max@0
|
2888 const Mat<eT>&
|
max@0
|
2889 Mat<eT>::operator-=(const Op<T1, op_type>& X)
|
max@0
|
2890 {
|
max@0
|
2891 arma_extra_debug_sigprint();
|
max@0
|
2892
|
max@0
|
2893 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2894
|
max@0
|
2895 const Mat<eT> m(X);
|
max@0
|
2896
|
max@0
|
2897 return (*this).operator-=(m);
|
max@0
|
2898 }
|
max@0
|
2899
|
max@0
|
2900
|
max@0
|
2901
|
max@0
|
2902 //! in-place matrix multiplication, with the right-hand-side operand having delayed operations
|
max@0
|
2903 template<typename eT>
|
max@0
|
2904 template<typename T1, typename op_type>
|
max@0
|
2905 inline
|
max@0
|
2906 const Mat<eT>&
|
max@0
|
2907 Mat<eT>::operator*=(const Op<T1, op_type>& X)
|
max@0
|
2908 {
|
max@0
|
2909 arma_extra_debug_sigprint();
|
max@0
|
2910
|
max@0
|
2911 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2912
|
max@0
|
2913 glue_times::apply_inplace(*this, X);
|
max@0
|
2914
|
max@0
|
2915 return *this;
|
max@0
|
2916 }
|
max@0
|
2917
|
max@0
|
2918
|
max@0
|
2919
|
max@0
|
2920 //! in-place matrix element-wise multiplication, with the right-hand-side operand having delayed operations
|
max@0
|
2921 template<typename eT>
|
max@0
|
2922 template<typename T1, typename op_type>
|
max@0
|
2923 inline
|
max@0
|
2924 const Mat<eT>&
|
max@0
|
2925 Mat<eT>::operator%=(const Op<T1, op_type>& X)
|
max@0
|
2926 {
|
max@0
|
2927 arma_extra_debug_sigprint();
|
max@0
|
2928
|
max@0
|
2929 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2930
|
max@0
|
2931 const Mat<eT> m(X);
|
max@0
|
2932
|
max@0
|
2933 return (*this).operator%=(m);
|
max@0
|
2934 }
|
max@0
|
2935
|
max@0
|
2936
|
max@0
|
2937
|
max@0
|
2938 //! in-place matrix element-wise division, with the right-hand-side operand having delayed operations
|
max@0
|
2939 template<typename eT>
|
max@0
|
2940 template<typename T1, typename op_type>
|
max@0
|
2941 inline
|
max@0
|
2942 const Mat<eT>&
|
max@0
|
2943 Mat<eT>::operator/=(const Op<T1, op_type>& X)
|
max@0
|
2944 {
|
max@0
|
2945 arma_extra_debug_sigprint();
|
max@0
|
2946
|
max@0
|
2947 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2948
|
max@0
|
2949 const Mat<eT> m(X);
|
max@0
|
2950
|
max@0
|
2951 return (*this).operator/=(m);
|
max@0
|
2952 }
|
max@0
|
2953
|
max@0
|
2954
|
max@0
|
2955
|
max@0
|
2956 //! create a matrix from eOp, i.e. run the previously delayed unary operations
|
max@0
|
2957 template<typename eT>
|
max@0
|
2958 template<typename T1, typename eop_type>
|
max@0
|
2959 inline
|
max@0
|
2960 Mat<eT>::Mat(const eOp<T1, eop_type>& X)
|
max@0
|
2961 : n_rows(X.get_n_rows())
|
max@0
|
2962 , n_cols(X.get_n_cols())
|
max@0
|
2963 , n_elem(X.get_n_elem())
|
max@0
|
2964 , vec_state(0)
|
max@0
|
2965 , mem_state(0)
|
max@0
|
2966 , mem()
|
max@0
|
2967 {
|
max@0
|
2968 arma_extra_debug_sigprint_this(this);
|
max@0
|
2969
|
max@0
|
2970 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2971
|
max@0
|
2972 init_cold();
|
max@0
|
2973
|
max@0
|
2974 eop_type::apply(*this, X);
|
max@0
|
2975 }
|
max@0
|
2976
|
max@0
|
2977
|
max@0
|
2978
|
max@0
|
2979 //! create a matrix from eOp, i.e. run the previously delayed unary operations
|
max@0
|
2980 template<typename eT>
|
max@0
|
2981 template<typename T1, typename eop_type>
|
max@0
|
2982 inline
|
max@0
|
2983 const Mat<eT>&
|
max@0
|
2984 Mat<eT>::operator=(const eOp<T1, eop_type>& X)
|
max@0
|
2985 {
|
max@0
|
2986 arma_extra_debug_sigprint();
|
max@0
|
2987
|
max@0
|
2988 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
2989
|
max@0
|
2990 const bool bad_alias = (X.P.has_subview && X.P.is_alias(*this));
|
max@0
|
2991
|
max@0
|
2992 if(bad_alias == false)
|
max@0
|
2993 {
|
max@0
|
2994 init_warm(X.get_n_rows(), X.get_n_cols());
|
max@0
|
2995
|
max@0
|
2996 eop_type::apply(*this, X);
|
max@0
|
2997 }
|
max@0
|
2998 else
|
max@0
|
2999 {
|
max@0
|
3000 Mat<eT> tmp(X);
|
max@0
|
3001
|
max@0
|
3002 steal_mem(tmp);
|
max@0
|
3003 }
|
max@0
|
3004
|
max@0
|
3005 return *this;
|
max@0
|
3006 }
|
max@0
|
3007
|
max@0
|
3008
|
max@0
|
3009
|
max@0
|
3010 template<typename eT>
|
max@0
|
3011 template<typename T1, typename eop_type>
|
max@0
|
3012 inline
|
max@0
|
3013 const Mat<eT>&
|
max@0
|
3014 Mat<eT>::operator+=(const eOp<T1, eop_type>& X)
|
max@0
|
3015 {
|
max@0
|
3016 arma_extra_debug_sigprint();
|
max@0
|
3017
|
max@0
|
3018 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3019
|
max@0
|
3020 eop_type::apply_inplace_plus(*this, X);
|
max@0
|
3021
|
max@0
|
3022 return *this;
|
max@0
|
3023 }
|
max@0
|
3024
|
max@0
|
3025
|
max@0
|
3026
|
max@0
|
3027 template<typename eT>
|
max@0
|
3028 template<typename T1, typename eop_type>
|
max@0
|
3029 inline
|
max@0
|
3030 const Mat<eT>&
|
max@0
|
3031 Mat<eT>::operator-=(const eOp<T1, eop_type>& X)
|
max@0
|
3032 {
|
max@0
|
3033 arma_extra_debug_sigprint();
|
max@0
|
3034
|
max@0
|
3035 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3036
|
max@0
|
3037 eop_type::apply_inplace_minus(*this, X);
|
max@0
|
3038
|
max@0
|
3039 return *this;
|
max@0
|
3040 }
|
max@0
|
3041
|
max@0
|
3042
|
max@0
|
3043
|
max@0
|
3044 template<typename eT>
|
max@0
|
3045 template<typename T1, typename eop_type>
|
max@0
|
3046 inline
|
max@0
|
3047 const Mat<eT>&
|
max@0
|
3048 Mat<eT>::operator*=(const eOp<T1, eop_type>& X)
|
max@0
|
3049 {
|
max@0
|
3050 arma_extra_debug_sigprint();
|
max@0
|
3051
|
max@0
|
3052 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3053
|
max@0
|
3054 glue_times::apply_inplace(*this, X);
|
max@0
|
3055
|
max@0
|
3056 return *this;
|
max@0
|
3057 }
|
max@0
|
3058
|
max@0
|
3059
|
max@0
|
3060
|
max@0
|
3061 template<typename eT>
|
max@0
|
3062 template<typename T1, typename eop_type>
|
max@0
|
3063 inline
|
max@0
|
3064 const Mat<eT>&
|
max@0
|
3065 Mat<eT>::operator%=(const eOp<T1, eop_type>& X)
|
max@0
|
3066 {
|
max@0
|
3067 arma_extra_debug_sigprint();
|
max@0
|
3068
|
max@0
|
3069 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3070
|
max@0
|
3071 eop_type::apply_inplace_schur(*this, X);
|
max@0
|
3072
|
max@0
|
3073 return *this;
|
max@0
|
3074 }
|
max@0
|
3075
|
max@0
|
3076
|
max@0
|
3077
|
max@0
|
3078 template<typename eT>
|
max@0
|
3079 template<typename T1, typename eop_type>
|
max@0
|
3080 inline
|
max@0
|
3081 const Mat<eT>&
|
max@0
|
3082 Mat<eT>::operator/=(const eOp<T1, eop_type>& X)
|
max@0
|
3083 {
|
max@0
|
3084 arma_extra_debug_sigprint();
|
max@0
|
3085
|
max@0
|
3086 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3087
|
max@0
|
3088 eop_type::apply_inplace_div(*this, X);
|
max@0
|
3089
|
max@0
|
3090 return *this;
|
max@0
|
3091 }
|
max@0
|
3092
|
max@0
|
3093
|
max@0
|
3094
|
max@0
|
3095 //! EXPERIMENTAL
|
max@0
|
3096 template<typename eT>
|
max@0
|
3097 template<typename T1, typename op_type>
|
max@0
|
3098 inline
|
max@0
|
3099 Mat<eT>::Mat(const mtOp<eT, T1, op_type>& X)
|
max@0
|
3100 : n_rows(0)
|
max@0
|
3101 , n_cols(0)
|
max@0
|
3102 , n_elem(0)
|
max@0
|
3103 , vec_state(0)
|
max@0
|
3104 , mem_state(0)
|
max@0
|
3105 , mem()
|
max@0
|
3106 {
|
max@0
|
3107 arma_extra_debug_sigprint_this(this);
|
max@0
|
3108
|
max@0
|
3109 op_type::apply(*this, X);
|
max@0
|
3110 }
|
max@0
|
3111
|
max@0
|
3112
|
max@0
|
3113
|
max@0
|
3114 //! EXPERIMENTAL
|
max@0
|
3115 template<typename eT>
|
max@0
|
3116 template<typename T1, typename op_type>
|
max@0
|
3117 inline
|
max@0
|
3118 const Mat<eT>&
|
max@0
|
3119 Mat<eT>::operator=(const mtOp<eT, T1, op_type>& X)
|
max@0
|
3120 {
|
max@0
|
3121 arma_extra_debug_sigprint();
|
max@0
|
3122
|
max@0
|
3123 op_type::apply(*this, X);
|
max@0
|
3124
|
max@0
|
3125 return *this;
|
max@0
|
3126 }
|
max@0
|
3127
|
max@0
|
3128
|
max@0
|
3129
|
max@0
|
3130 //! EXPERIMENTAL
|
max@0
|
3131 template<typename eT>
|
max@0
|
3132 template<typename T1, typename op_type>
|
max@0
|
3133 inline
|
max@0
|
3134 const Mat<eT>&
|
max@0
|
3135 Mat<eT>::operator+=(const mtOp<eT, T1, op_type>& X)
|
max@0
|
3136 {
|
max@0
|
3137 arma_extra_debug_sigprint();
|
max@0
|
3138
|
max@0
|
3139 const Mat<eT> m(X);
|
max@0
|
3140
|
max@0
|
3141 return (*this).operator+=(m);
|
max@0
|
3142 }
|
max@0
|
3143
|
max@0
|
3144
|
max@0
|
3145
|
max@0
|
3146 //! EXPERIMENTAL
|
max@0
|
3147 template<typename eT>
|
max@0
|
3148 template<typename T1, typename op_type>
|
max@0
|
3149 inline
|
max@0
|
3150 const Mat<eT>&
|
max@0
|
3151 Mat<eT>::operator-=(const mtOp<eT, T1, op_type>& X)
|
max@0
|
3152 {
|
max@0
|
3153 arma_extra_debug_sigprint();
|
max@0
|
3154
|
max@0
|
3155 const Mat<eT> m(X);
|
max@0
|
3156
|
max@0
|
3157 return (*this).operator-=(m);
|
max@0
|
3158 }
|
max@0
|
3159
|
max@0
|
3160
|
max@0
|
3161
|
max@0
|
3162 //! EXPERIMENTAL
|
max@0
|
3163 template<typename eT>
|
max@0
|
3164 template<typename T1, typename op_type>
|
max@0
|
3165 inline
|
max@0
|
3166 const Mat<eT>&
|
max@0
|
3167 Mat<eT>::operator*=(const mtOp<eT, T1, op_type>& X)
|
max@0
|
3168 {
|
max@0
|
3169 arma_extra_debug_sigprint();
|
max@0
|
3170
|
max@0
|
3171 const Mat<eT> m(X);
|
max@0
|
3172
|
max@0
|
3173 return (*this).operator*=(m);
|
max@0
|
3174 }
|
max@0
|
3175
|
max@0
|
3176
|
max@0
|
3177
|
max@0
|
3178 //! EXPERIMENTAL
|
max@0
|
3179 template<typename eT>
|
max@0
|
3180 template<typename T1, typename op_type>
|
max@0
|
3181 inline
|
max@0
|
3182 const Mat<eT>&
|
max@0
|
3183 Mat<eT>::operator%=(const mtOp<eT, T1, op_type>& X)
|
max@0
|
3184 {
|
max@0
|
3185 arma_extra_debug_sigprint();
|
max@0
|
3186
|
max@0
|
3187 const Mat<eT> m(X);
|
max@0
|
3188
|
max@0
|
3189 return (*this).operator%=(m);
|
max@0
|
3190 }
|
max@0
|
3191
|
max@0
|
3192
|
max@0
|
3193
|
max@0
|
3194 //! EXPERIMENTAL
|
max@0
|
3195 template<typename eT>
|
max@0
|
3196 template<typename T1, typename op_type>
|
max@0
|
3197 inline
|
max@0
|
3198 const Mat<eT>&
|
max@0
|
3199 Mat<eT>::operator/=(const mtOp<eT, T1, op_type>& X)
|
max@0
|
3200 {
|
max@0
|
3201 arma_extra_debug_sigprint();
|
max@0
|
3202
|
max@0
|
3203 const Mat<eT> m(X);
|
max@0
|
3204
|
max@0
|
3205 return (*this).operator/=(m);
|
max@0
|
3206 }
|
max@0
|
3207
|
max@0
|
3208
|
max@0
|
3209
|
max@0
|
3210 //! create a matrix from Glue, i.e. run the previously delayed binary operations
|
max@0
|
3211 template<typename eT>
|
max@0
|
3212 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3213 inline
|
max@0
|
3214 Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X)
|
max@0
|
3215 : n_rows(0)
|
max@0
|
3216 , n_cols(0)
|
max@0
|
3217 , n_elem(0)
|
max@0
|
3218 , vec_state(0)
|
max@0
|
3219 , mem_state(0)
|
max@0
|
3220 , mem()
|
max@0
|
3221 {
|
max@0
|
3222 arma_extra_debug_sigprint_this(this);
|
max@0
|
3223
|
max@0
|
3224 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3225 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3226
|
max@0
|
3227 glue_type::apply(*this, X);
|
max@0
|
3228 }
|
max@0
|
3229
|
max@0
|
3230
|
max@0
|
3231
|
max@0
|
3232 //! create a matrix from Glue, i.e. run the previously delayed binary operations
|
max@0
|
3233 template<typename eT>
|
max@0
|
3234 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3235 inline
|
max@0
|
3236 const Mat<eT>&
|
max@0
|
3237 Mat<eT>::operator=(const Glue<T1, T2, glue_type>& X)
|
max@0
|
3238 {
|
max@0
|
3239 arma_extra_debug_sigprint();
|
max@0
|
3240
|
max@0
|
3241 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3242 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3243
|
max@0
|
3244 glue_type::apply(*this, X);
|
max@0
|
3245
|
max@0
|
3246 return *this;
|
max@0
|
3247 }
|
max@0
|
3248
|
max@0
|
3249
|
max@0
|
3250
|
max@0
|
3251 //! in-place matrix addition, with the right-hand-side operands having delayed operations
|
max@0
|
3252 template<typename eT>
|
max@0
|
3253 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3254 inline
|
max@0
|
3255 const Mat<eT>&
|
max@0
|
3256 Mat<eT>::operator+=(const Glue<T1, T2, glue_type>& X)
|
max@0
|
3257 {
|
max@0
|
3258 arma_extra_debug_sigprint();
|
max@0
|
3259
|
max@0
|
3260 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3261 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3262
|
max@0
|
3263 const Mat<eT> m(X);
|
max@0
|
3264
|
max@0
|
3265 return (*this).operator+=(m);
|
max@0
|
3266 }
|
max@0
|
3267
|
max@0
|
3268
|
max@0
|
3269
|
max@0
|
3270 //! in-place matrix subtraction, with the right-hand-side operands having delayed operations
|
max@0
|
3271 template<typename eT>
|
max@0
|
3272 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3273 inline
|
max@0
|
3274 const Mat<eT>&
|
max@0
|
3275 Mat<eT>::operator-=(const Glue<T1, T2, glue_type>& X)
|
max@0
|
3276 {
|
max@0
|
3277 arma_extra_debug_sigprint();
|
max@0
|
3278
|
max@0
|
3279 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3280 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3281
|
max@0
|
3282 const Mat<eT> m(X);
|
max@0
|
3283
|
max@0
|
3284 return (*this).operator-=(m);
|
max@0
|
3285 }
|
max@0
|
3286
|
max@0
|
3287
|
max@0
|
3288
|
max@0
|
3289 //! in-place matrix multiplications, with the right-hand-side operands having delayed operations
|
max@0
|
3290 template<typename eT>
|
max@0
|
3291 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3292 inline
|
max@0
|
3293 const Mat<eT>&
|
max@0
|
3294 Mat<eT>::operator*=(const Glue<T1, T2, glue_type>& X)
|
max@0
|
3295 {
|
max@0
|
3296 arma_extra_debug_sigprint();
|
max@0
|
3297
|
max@0
|
3298 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3299 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3300
|
max@0
|
3301 glue_times::apply_inplace(*this, X);
|
max@0
|
3302
|
max@0
|
3303 return *this;
|
max@0
|
3304 }
|
max@0
|
3305
|
max@0
|
3306
|
max@0
|
3307
|
max@0
|
3308 //! in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations
|
max@0
|
3309 template<typename eT>
|
max@0
|
3310 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3311 inline
|
max@0
|
3312 const Mat<eT>&
|
max@0
|
3313 Mat<eT>::operator%=(const Glue<T1, T2, glue_type>& X)
|
max@0
|
3314 {
|
max@0
|
3315 arma_extra_debug_sigprint();
|
max@0
|
3316
|
max@0
|
3317 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3318 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3319
|
max@0
|
3320 const Mat<eT> m(X);
|
max@0
|
3321
|
max@0
|
3322 return (*this).operator%=(m);
|
max@0
|
3323 }
|
max@0
|
3324
|
max@0
|
3325
|
max@0
|
3326
|
max@0
|
3327 //! in-place matrix element-wise division, with the right-hand-side operands having delayed operations
|
max@0
|
3328 template<typename eT>
|
max@0
|
3329 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3330 inline
|
max@0
|
3331 const Mat<eT>&
|
max@0
|
3332 Mat<eT>::operator/=(const Glue<T1, T2, glue_type>& X)
|
max@0
|
3333 {
|
max@0
|
3334 arma_extra_debug_sigprint();
|
max@0
|
3335
|
max@0
|
3336 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3337 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3338
|
max@0
|
3339 const Mat<eT> m(X);
|
max@0
|
3340
|
max@0
|
3341 return (*this).operator/=(m);
|
max@0
|
3342 }
|
max@0
|
3343
|
max@0
|
3344
|
max@0
|
3345
|
max@0
|
3346 template<typename eT>
|
max@0
|
3347 template<typename T1, typename T2>
|
max@0
|
3348 inline
|
max@0
|
3349 const Mat<eT>&
|
max@0
|
3350 Mat<eT>::operator+=(const Glue<T1, T2, glue_times>& X)
|
max@0
|
3351 {
|
max@0
|
3352 arma_extra_debug_sigprint();
|
max@0
|
3353
|
max@0
|
3354 glue_times::apply_inplace_plus(*this, X, sword(+1));
|
max@0
|
3355
|
max@0
|
3356 return *this;
|
max@0
|
3357 }
|
max@0
|
3358
|
max@0
|
3359
|
max@0
|
3360
|
max@0
|
3361 template<typename eT>
|
max@0
|
3362 template<typename T1, typename T2>
|
max@0
|
3363 inline
|
max@0
|
3364 const Mat<eT>&
|
max@0
|
3365 Mat<eT>::operator-=(const Glue<T1, T2, glue_times>& X)
|
max@0
|
3366 {
|
max@0
|
3367 arma_extra_debug_sigprint();
|
max@0
|
3368
|
max@0
|
3369 glue_times::apply_inplace_plus(*this, X, sword(-1));
|
max@0
|
3370
|
max@0
|
3371 return *this;
|
max@0
|
3372 }
|
max@0
|
3373
|
max@0
|
3374
|
max@0
|
3375
|
max@0
|
3376 //! create a matrix from eGlue, i.e. run the previously delayed binary operations
|
max@0
|
3377 template<typename eT>
|
max@0
|
3378 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
3379 inline
|
max@0
|
3380 Mat<eT>::Mat(const eGlue<T1, T2, eglue_type>& X)
|
max@0
|
3381 : n_rows(X.get_n_rows())
|
max@0
|
3382 , n_cols(X.get_n_cols())
|
max@0
|
3383 , n_elem(X.get_n_elem())
|
max@0
|
3384 , vec_state(0)
|
max@0
|
3385 , mem_state(0)
|
max@0
|
3386 , mem()
|
max@0
|
3387 {
|
max@0
|
3388 arma_extra_debug_sigprint_this(this);
|
max@0
|
3389
|
max@0
|
3390 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3391 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3392
|
max@0
|
3393 init_cold();
|
max@0
|
3394
|
max@0
|
3395 eglue_type::apply(*this, X);
|
max@0
|
3396 }
|
max@0
|
3397
|
max@0
|
3398
|
max@0
|
3399
|
max@0
|
3400 //! create a matrix from eGlue, i.e. run the previously delayed binary operations
|
max@0
|
3401 template<typename eT>
|
max@0
|
3402 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
3403 inline
|
max@0
|
3404 const Mat<eT>&
|
max@0
|
3405 Mat<eT>::operator=(const eGlue<T1, T2, eglue_type>& X)
|
max@0
|
3406 {
|
max@0
|
3407 arma_extra_debug_sigprint();
|
max@0
|
3408
|
max@0
|
3409 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3410 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3411
|
max@0
|
3412 const bool bad_alias = ( (X.P1.has_subview && X.P1.is_alias(*this)) || ( X.P2.has_subview && X.P2.is_alias(*this)) );
|
max@0
|
3413
|
max@0
|
3414 if(bad_alias == false)
|
max@0
|
3415 {
|
max@0
|
3416 init_warm(X.get_n_rows(), X.get_n_cols());
|
max@0
|
3417
|
max@0
|
3418 eglue_type::apply(*this, X);
|
max@0
|
3419 }
|
max@0
|
3420 else
|
max@0
|
3421 {
|
max@0
|
3422 Mat<eT> tmp(X);
|
max@0
|
3423
|
max@0
|
3424 steal_mem(tmp);
|
max@0
|
3425 }
|
max@0
|
3426
|
max@0
|
3427 return *this;
|
max@0
|
3428 }
|
max@0
|
3429
|
max@0
|
3430
|
max@0
|
3431
|
max@0
|
3432 //! in-place matrix addition, with the right-hand-side operands having delayed operations
|
max@0
|
3433 template<typename eT>
|
max@0
|
3434 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
3435 inline
|
max@0
|
3436 const Mat<eT>&
|
max@0
|
3437 Mat<eT>::operator+=(const eGlue<T1, T2, eglue_type>& X)
|
max@0
|
3438 {
|
max@0
|
3439 arma_extra_debug_sigprint();
|
max@0
|
3440
|
max@0
|
3441 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3442 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3443
|
max@0
|
3444 eglue_type::apply_inplace_plus(*this, X);
|
max@0
|
3445
|
max@0
|
3446 return *this;
|
max@0
|
3447 }
|
max@0
|
3448
|
max@0
|
3449
|
max@0
|
3450
|
max@0
|
3451 //! in-place matrix subtraction, with the right-hand-side operands having delayed operations
|
max@0
|
3452 template<typename eT>
|
max@0
|
3453 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
3454 inline
|
max@0
|
3455 const Mat<eT>&
|
max@0
|
3456 Mat<eT>::operator-=(const eGlue<T1, T2, eglue_type>& X)
|
max@0
|
3457 {
|
max@0
|
3458 arma_extra_debug_sigprint();
|
max@0
|
3459
|
max@0
|
3460 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3461 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3462
|
max@0
|
3463 eglue_type::apply_inplace_minus(*this, X);
|
max@0
|
3464
|
max@0
|
3465 return *this;
|
max@0
|
3466 }
|
max@0
|
3467
|
max@0
|
3468
|
max@0
|
3469
|
max@0
|
3470 template<typename eT>
|
max@0
|
3471 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
3472 inline
|
max@0
|
3473 const Mat<eT>&
|
max@0
|
3474 Mat<eT>::operator*=(const eGlue<T1, T2, eglue_type>& X)
|
max@0
|
3475 {
|
max@0
|
3476 arma_extra_debug_sigprint();
|
max@0
|
3477
|
max@0
|
3478 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3479 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3480
|
max@0
|
3481 glue_times::apply_inplace(*this, X);
|
max@0
|
3482 return *this;
|
max@0
|
3483 }
|
max@0
|
3484
|
max@0
|
3485
|
max@0
|
3486
|
max@0
|
3487 template<typename eT>
|
max@0
|
3488 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
3489 inline
|
max@0
|
3490 const Mat<eT>&
|
max@0
|
3491 Mat<eT>::operator%=(const eGlue<T1, T2, eglue_type>& X)
|
max@0
|
3492 {
|
max@0
|
3493 arma_extra_debug_sigprint();
|
max@0
|
3494
|
max@0
|
3495 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3496 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3497
|
max@0
|
3498 eglue_type::apply_inplace_schur(*this, X);
|
max@0
|
3499 return *this;
|
max@0
|
3500 }
|
max@0
|
3501
|
max@0
|
3502
|
max@0
|
3503
|
max@0
|
3504 template<typename eT>
|
max@0
|
3505 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
3506 inline
|
max@0
|
3507 const Mat<eT>&
|
max@0
|
3508 Mat<eT>::operator/=(const eGlue<T1, T2, eglue_type>& X)
|
max@0
|
3509 {
|
max@0
|
3510 arma_extra_debug_sigprint();
|
max@0
|
3511
|
max@0
|
3512 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
3513 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
3514
|
max@0
|
3515 eglue_type::apply_inplace_div(*this, X);
|
max@0
|
3516 return *this;
|
max@0
|
3517 }
|
max@0
|
3518
|
max@0
|
3519
|
max@0
|
3520
|
max@0
|
3521 //! EXPERIMENTAL: create a matrix from mtGlue, i.e. run the previously delayed binary operations
|
max@0
|
3522 template<typename eT>
|
max@0
|
3523 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3524 inline
|
max@0
|
3525 Mat<eT>::Mat(const mtGlue<eT, T1, T2, glue_type>& X)
|
max@0
|
3526 : n_rows(0)
|
max@0
|
3527 , n_cols(0)
|
max@0
|
3528 , n_elem(0)
|
max@0
|
3529 , vec_state(0)
|
max@0
|
3530 , mem_state(0)
|
max@0
|
3531 , mem()
|
max@0
|
3532 {
|
max@0
|
3533 arma_extra_debug_sigprint_this(this);
|
max@0
|
3534
|
max@0
|
3535 glue_type::apply(*this, X);
|
max@0
|
3536 }
|
max@0
|
3537
|
max@0
|
3538
|
max@0
|
3539
|
max@0
|
3540 //! EXPERIMENTAL: create a matrix from Glue, i.e. run the previously delayed binary operations
|
max@0
|
3541 template<typename eT>
|
max@0
|
3542 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3543 inline
|
max@0
|
3544 const Mat<eT>&
|
max@0
|
3545 Mat<eT>::operator=(const mtGlue<eT, T1, T2, glue_type>& X)
|
max@0
|
3546 {
|
max@0
|
3547 arma_extra_debug_sigprint();
|
max@0
|
3548
|
max@0
|
3549 glue_type::apply(*this, X);
|
max@0
|
3550
|
max@0
|
3551 return *this;
|
max@0
|
3552 }
|
max@0
|
3553
|
max@0
|
3554
|
max@0
|
3555
|
max@0
|
3556 //! EXPERIMENTAL: in-place matrix addition, with the right-hand-side operands having delayed operations
|
max@0
|
3557 template<typename eT>
|
max@0
|
3558 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3559 inline
|
max@0
|
3560 const Mat<eT>&
|
max@0
|
3561 Mat<eT>::operator+=(const mtGlue<eT, T1, T2, glue_type>& X)
|
max@0
|
3562 {
|
max@0
|
3563 arma_extra_debug_sigprint();
|
max@0
|
3564
|
max@0
|
3565 const Mat<eT> m(X);
|
max@0
|
3566
|
max@0
|
3567 return (*this).operator+=(m);
|
max@0
|
3568 }
|
max@0
|
3569
|
max@0
|
3570
|
max@0
|
3571
|
max@0
|
3572 //! EXPERIMENTAL: in-place matrix subtraction, with the right-hand-side operands having delayed operations
|
max@0
|
3573 template<typename eT>
|
max@0
|
3574 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3575 inline
|
max@0
|
3576 const Mat<eT>&
|
max@0
|
3577 Mat<eT>::operator-=(const mtGlue<eT, T1, T2, glue_type>& X)
|
max@0
|
3578 {
|
max@0
|
3579 arma_extra_debug_sigprint();
|
max@0
|
3580
|
max@0
|
3581 const Mat<eT> m(X);
|
max@0
|
3582
|
max@0
|
3583 return (*this).operator-=(m);
|
max@0
|
3584 }
|
max@0
|
3585
|
max@0
|
3586
|
max@0
|
3587
|
max@0
|
3588 //! EXPERIMENTAL: in-place matrix multiplications, with the right-hand-side operands having delayed operations
|
max@0
|
3589 template<typename eT>
|
max@0
|
3590 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3591 inline
|
max@0
|
3592 const Mat<eT>&
|
max@0
|
3593 Mat<eT>::operator*=(const mtGlue<eT, T1, T2, glue_type>& X)
|
max@0
|
3594 {
|
max@0
|
3595 arma_extra_debug_sigprint();
|
max@0
|
3596
|
max@0
|
3597 const Mat<eT> m(X);
|
max@0
|
3598
|
max@0
|
3599 glue_times::apply_inplace(*this, m);
|
max@0
|
3600
|
max@0
|
3601 return *this;
|
max@0
|
3602 }
|
max@0
|
3603
|
max@0
|
3604
|
max@0
|
3605
|
max@0
|
3606 //! EXPERIMENTAL: in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations
|
max@0
|
3607 template<typename eT>
|
max@0
|
3608 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3609 inline
|
max@0
|
3610 const Mat<eT>&
|
max@0
|
3611 Mat<eT>::operator%=(const mtGlue<eT, T1, T2, glue_type>& X)
|
max@0
|
3612 {
|
max@0
|
3613 arma_extra_debug_sigprint();
|
max@0
|
3614
|
max@0
|
3615 const Mat<eT> m(X);
|
max@0
|
3616
|
max@0
|
3617 return (*this).operator%=(m);
|
max@0
|
3618 }
|
max@0
|
3619
|
max@0
|
3620
|
max@0
|
3621
|
max@0
|
3622 //! EXPERIMENTAL: in-place matrix element-wise division, with the right-hand-side operands having delayed operations
|
max@0
|
3623 template<typename eT>
|
max@0
|
3624 template<typename T1, typename T2, typename glue_type>
|
max@0
|
3625 inline
|
max@0
|
3626 const Mat<eT>&
|
max@0
|
3627 Mat<eT>::operator/=(const mtGlue<eT, T1, T2, glue_type>& X)
|
max@0
|
3628 {
|
max@0
|
3629 arma_extra_debug_sigprint();
|
max@0
|
3630
|
max@0
|
3631 const Mat<eT> m(X);
|
max@0
|
3632
|
max@0
|
3633 return (*this).operator/=(m);
|
max@0
|
3634 }
|
max@0
|
3635
|
max@0
|
3636
|
max@0
|
3637
|
max@0
|
3638 //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
|
max@0
|
3639 template<typename eT>
|
max@0
|
3640 arma_inline
|
max@0
|
3641 arma_warn_unused
|
max@0
|
3642 eT&
|
max@0
|
3643 Mat<eT>::operator() (const uword i)
|
max@0
|
3644 {
|
max@0
|
3645 arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds");
|
max@0
|
3646 return access::rw(mem[i]);
|
max@0
|
3647 }
|
max@0
|
3648
|
max@0
|
3649
|
max@0
|
3650
|
max@0
|
3651 //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
|
max@0
|
3652 template<typename eT>
|
max@0
|
3653 arma_inline
|
max@0
|
3654 arma_warn_unused
|
max@0
|
3655 eT
|
max@0
|
3656 Mat<eT>::operator() (const uword i) const
|
max@0
|
3657 {
|
max@0
|
3658 arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds");
|
max@0
|
3659 return mem[i];
|
max@0
|
3660 }
|
max@0
|
3661
|
max@0
|
3662
|
max@0
|
3663 //! linear element accessor (treats the matrix as a vector); no bounds check.
|
max@0
|
3664 template<typename eT>
|
max@0
|
3665 arma_inline
|
max@0
|
3666 arma_warn_unused
|
max@0
|
3667 eT&
|
max@0
|
3668 Mat<eT>::operator[] (const uword i)
|
max@0
|
3669 {
|
max@0
|
3670 return access::rw(mem[i]);
|
max@0
|
3671 }
|
max@0
|
3672
|
max@0
|
3673
|
max@0
|
3674
|
max@0
|
3675 //! linear element accessor (treats the matrix as a vector); no bounds check
|
max@0
|
3676 template<typename eT>
|
max@0
|
3677 arma_inline
|
max@0
|
3678 arma_warn_unused
|
max@0
|
3679 eT
|
max@0
|
3680 Mat<eT>::operator[] (const uword i) const
|
max@0
|
3681 {
|
max@0
|
3682 return mem[i];
|
max@0
|
3683 }
|
max@0
|
3684
|
max@0
|
3685
|
max@0
|
3686
|
max@0
|
3687 //! linear element accessor (treats the matrix as a vector); no bounds check.
|
max@0
|
3688 template<typename eT>
|
max@0
|
3689 arma_inline
|
max@0
|
3690 arma_warn_unused
|
max@0
|
3691 eT&
|
max@0
|
3692 Mat<eT>::at(const uword i)
|
max@0
|
3693 {
|
max@0
|
3694 return access::rw(mem[i]);
|
max@0
|
3695 }
|
max@0
|
3696
|
max@0
|
3697
|
max@0
|
3698
|
max@0
|
3699 //! linear element accessor (treats the matrix as a vector); no bounds check
|
max@0
|
3700 template<typename eT>
|
max@0
|
3701 arma_inline
|
max@0
|
3702 arma_warn_unused
|
max@0
|
3703 eT
|
max@0
|
3704 Mat<eT>::at(const uword i) const
|
max@0
|
3705 {
|
max@0
|
3706 return mem[i];
|
max@0
|
3707 }
|
max@0
|
3708
|
max@0
|
3709
|
max@0
|
3710
|
max@0
|
3711 //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
|
max@0
|
3712 template<typename eT>
|
max@0
|
3713 arma_inline
|
max@0
|
3714 arma_warn_unused
|
max@0
|
3715 eT&
|
max@0
|
3716 Mat<eT>::operator() (const uword in_row, const uword in_col)
|
max@0
|
3717 {
|
max@0
|
3718 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): out of bounds");
|
max@0
|
3719 return access::rw(mem[in_row + in_col*n_rows]);
|
max@0
|
3720 }
|
max@0
|
3721
|
max@0
|
3722
|
max@0
|
3723
|
max@0
|
3724 //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
|
max@0
|
3725 template<typename eT>
|
max@0
|
3726 arma_inline
|
max@0
|
3727 arma_warn_unused
|
max@0
|
3728 eT
|
max@0
|
3729 Mat<eT>::operator() (const uword in_row, const uword in_col) const
|
max@0
|
3730 {
|
max@0
|
3731 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): out of bounds");
|
max@0
|
3732 return mem[in_row + in_col*n_rows];
|
max@0
|
3733 }
|
max@0
|
3734
|
max@0
|
3735
|
max@0
|
3736
|
max@0
|
3737 //! element accessor; no bounds check
|
max@0
|
3738 template<typename eT>
|
max@0
|
3739 arma_inline
|
max@0
|
3740 arma_warn_unused
|
max@0
|
3741 eT&
|
max@0
|
3742 Mat<eT>::at(const uword in_row, const uword in_col)
|
max@0
|
3743 {
|
max@0
|
3744 return access::rw( mem[in_row + in_col*n_rows] );
|
max@0
|
3745 }
|
max@0
|
3746
|
max@0
|
3747
|
max@0
|
3748
|
max@0
|
3749 //! element accessor; no bounds check
|
max@0
|
3750 template<typename eT>
|
max@0
|
3751 arma_inline
|
max@0
|
3752 arma_warn_unused
|
max@0
|
3753 eT
|
max@0
|
3754 Mat<eT>::at(const uword in_row, const uword in_col) const
|
max@0
|
3755 {
|
max@0
|
3756 return mem[in_row + in_col*n_rows];
|
max@0
|
3757 }
|
max@0
|
3758
|
max@0
|
3759
|
max@0
|
3760
|
max@0
|
3761 //! prefix ++
|
max@0
|
3762 template<typename eT>
|
max@0
|
3763 arma_inline
|
max@0
|
3764 const Mat<eT>&
|
max@0
|
3765 Mat<eT>::operator++()
|
max@0
|
3766 {
|
max@0
|
3767 Mat_aux::prefix_pp(*this);
|
max@0
|
3768 return *this;
|
max@0
|
3769 }
|
max@0
|
3770
|
max@0
|
3771
|
max@0
|
3772
|
max@0
|
3773 //! postfix ++ (must not return the object by reference)
|
max@0
|
3774 template<typename eT>
|
max@0
|
3775 arma_inline
|
max@0
|
3776 void
|
max@0
|
3777 Mat<eT>::operator++(int)
|
max@0
|
3778 {
|
max@0
|
3779 Mat_aux::postfix_pp(*this);
|
max@0
|
3780 }
|
max@0
|
3781
|
max@0
|
3782
|
max@0
|
3783
|
max@0
|
3784 //! prefix --
|
max@0
|
3785 template<typename eT>
|
max@0
|
3786 arma_inline
|
max@0
|
3787 const Mat<eT>&
|
max@0
|
3788 Mat<eT>::operator--()
|
max@0
|
3789 {
|
max@0
|
3790 Mat_aux::prefix_mm(*this);
|
max@0
|
3791 return *this;
|
max@0
|
3792 }
|
max@0
|
3793
|
max@0
|
3794
|
max@0
|
3795
|
max@0
|
3796 //! postfix -- (must not return the object by reference)
|
max@0
|
3797 template<typename eT>
|
max@0
|
3798 arma_inline
|
max@0
|
3799 void
|
max@0
|
3800 Mat<eT>::operator--(int)
|
max@0
|
3801 {
|
max@0
|
3802 Mat_aux::postfix_mm(*this);
|
max@0
|
3803 }
|
max@0
|
3804
|
max@0
|
3805
|
max@0
|
3806
|
max@0
|
3807 //! returns true if the matrix has no elements
|
max@0
|
3808 template<typename eT>
|
max@0
|
3809 arma_inline
|
max@0
|
3810 arma_warn_unused
|
max@0
|
3811 bool
|
max@0
|
3812 Mat<eT>::is_empty() const
|
max@0
|
3813 {
|
max@0
|
3814 return (n_elem == 0);
|
max@0
|
3815 }
|
max@0
|
3816
|
max@0
|
3817
|
max@0
|
3818
|
max@0
|
3819 //! returns true if the object can be interpreted as a column or row vector
|
max@0
|
3820 template<typename eT>
|
max@0
|
3821 arma_inline
|
max@0
|
3822 arma_warn_unused
|
max@0
|
3823 bool
|
max@0
|
3824 Mat<eT>::is_vec() const
|
max@0
|
3825 {
|
max@0
|
3826 return ( (n_rows == 1) || (n_cols == 1) );
|
max@0
|
3827 }
|
max@0
|
3828
|
max@0
|
3829
|
max@0
|
3830
|
max@0
|
3831 //! returns true if the object can be interpreted as a row vector
|
max@0
|
3832 template<typename eT>
|
max@0
|
3833 arma_inline
|
max@0
|
3834 arma_warn_unused
|
max@0
|
3835 bool
|
max@0
|
3836 Mat<eT>::is_rowvec() const
|
max@0
|
3837 {
|
max@0
|
3838 return (n_rows == 1);
|
max@0
|
3839 }
|
max@0
|
3840
|
max@0
|
3841
|
max@0
|
3842
|
max@0
|
3843 //! returns true if the object can be interpreted as a column vector
|
max@0
|
3844 template<typename eT>
|
max@0
|
3845 arma_inline
|
max@0
|
3846 arma_warn_unused
|
max@0
|
3847 bool
|
max@0
|
3848 Mat<eT>::is_colvec() const
|
max@0
|
3849 {
|
max@0
|
3850 return (n_cols == 1);
|
max@0
|
3851 }
|
max@0
|
3852
|
max@0
|
3853
|
max@0
|
3854
|
max@0
|
3855 //! returns true if the object has the same number of non-zero rows and columnns
|
max@0
|
3856 template<typename eT>
|
max@0
|
3857 arma_inline
|
max@0
|
3858 arma_warn_unused
|
max@0
|
3859 bool
|
max@0
|
3860 Mat<eT>::is_square() const
|
max@0
|
3861 {
|
max@0
|
3862 return (n_rows == n_cols);
|
max@0
|
3863 }
|
max@0
|
3864
|
max@0
|
3865
|
max@0
|
3866
|
max@0
|
3867 //! returns true if all of the elements are finite
|
max@0
|
3868 template<typename eT>
|
max@0
|
3869 inline
|
max@0
|
3870 arma_warn_unused
|
max@0
|
3871 bool
|
max@0
|
3872 Mat<eT>::is_finite() const
|
max@0
|
3873 {
|
max@0
|
3874 return arrayops::is_finite( memptr(), n_elem );
|
max@0
|
3875 }
|
max@0
|
3876
|
max@0
|
3877
|
max@0
|
3878
|
max@0
|
3879 //! returns true if the given index is currently in range
|
max@0
|
3880 template<typename eT>
|
max@0
|
3881 arma_inline
|
max@0
|
3882 arma_warn_unused
|
max@0
|
3883 bool
|
max@0
|
3884 Mat<eT>::in_range(const uword i) const
|
max@0
|
3885 {
|
max@0
|
3886 return (i < n_elem);
|
max@0
|
3887 }
|
max@0
|
3888
|
max@0
|
3889
|
max@0
|
3890
|
max@0
|
3891 //! returns true if the given start and end indices are currently in range
|
max@0
|
3892 template<typename eT>
|
max@0
|
3893 arma_inline
|
max@0
|
3894 arma_warn_unused
|
max@0
|
3895 bool
|
max@0
|
3896 Mat<eT>::in_range(const span& x) const
|
max@0
|
3897 {
|
max@0
|
3898 arma_extra_debug_sigprint();
|
max@0
|
3899
|
max@0
|
3900 if(x.whole == true)
|
max@0
|
3901 {
|
max@0
|
3902 return true;
|
max@0
|
3903 }
|
max@0
|
3904 else
|
max@0
|
3905 {
|
max@0
|
3906 const uword a = x.a;
|
max@0
|
3907 const uword b = x.b;
|
max@0
|
3908
|
max@0
|
3909 return ( (a <= b) && (b < n_elem) );
|
max@0
|
3910 }
|
max@0
|
3911 }
|
max@0
|
3912
|
max@0
|
3913
|
max@0
|
3914
|
max@0
|
3915 //! returns true if the given location is currently in range
|
max@0
|
3916 template<typename eT>
|
max@0
|
3917 arma_inline
|
max@0
|
3918 arma_warn_unused
|
max@0
|
3919 bool
|
max@0
|
3920 Mat<eT>::in_range(const uword in_row, const uword in_col) const
|
max@0
|
3921 {
|
max@0
|
3922 return ( (in_row < n_rows) && (in_col < n_cols) );
|
max@0
|
3923 }
|
max@0
|
3924
|
max@0
|
3925
|
max@0
|
3926
|
max@0
|
3927 template<typename eT>
|
max@0
|
3928 arma_inline
|
max@0
|
3929 arma_warn_unused
|
max@0
|
3930 bool
|
max@0
|
3931 Mat<eT>::in_range(const span& row_span, const uword in_col) const
|
max@0
|
3932 {
|
max@0
|
3933 arma_extra_debug_sigprint();
|
max@0
|
3934
|
max@0
|
3935 if(row_span.whole == true)
|
max@0
|
3936 {
|
max@0
|
3937 return (in_col < n_cols);
|
max@0
|
3938 }
|
max@0
|
3939 else
|
max@0
|
3940 {
|
max@0
|
3941 const uword in_row1 = row_span.a;
|
max@0
|
3942 const uword in_row2 = row_span.b;
|
max@0
|
3943
|
max@0
|
3944 return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) );
|
max@0
|
3945 }
|
max@0
|
3946 }
|
max@0
|
3947
|
max@0
|
3948
|
max@0
|
3949
|
max@0
|
3950 template<typename eT>
|
max@0
|
3951 arma_inline
|
max@0
|
3952 arma_warn_unused
|
max@0
|
3953 bool
|
max@0
|
3954 Mat<eT>::in_range(const uword in_row, const span& col_span) const
|
max@0
|
3955 {
|
max@0
|
3956 arma_extra_debug_sigprint();
|
max@0
|
3957
|
max@0
|
3958 if(col_span.whole == true)
|
max@0
|
3959 {
|
max@0
|
3960 return (in_row < n_rows);
|
max@0
|
3961 }
|
max@0
|
3962 else
|
max@0
|
3963 {
|
max@0
|
3964 const uword in_col1 = col_span.a;
|
max@0
|
3965 const uword in_col2 = col_span.b;
|
max@0
|
3966
|
max@0
|
3967 return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) );
|
max@0
|
3968 }
|
max@0
|
3969 }
|
max@0
|
3970
|
max@0
|
3971
|
max@0
|
3972
|
max@0
|
3973 template<typename eT>
|
max@0
|
3974 arma_inline
|
max@0
|
3975 arma_warn_unused
|
max@0
|
3976 bool
|
max@0
|
3977 Mat<eT>::in_range(const span& row_span, const span& col_span) const
|
max@0
|
3978 {
|
max@0
|
3979 arma_extra_debug_sigprint();
|
max@0
|
3980
|
max@0
|
3981 const uword in_row1 = row_span.a;
|
max@0
|
3982 const uword in_row2 = row_span.b;
|
max@0
|
3983
|
max@0
|
3984 const uword in_col1 = col_span.a;
|
max@0
|
3985 const uword in_col2 = col_span.b;
|
max@0
|
3986
|
max@0
|
3987 const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) );
|
max@0
|
3988 const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) );
|
max@0
|
3989
|
max@0
|
3990 return ( (rows_ok == true) && (cols_ok == true) );
|
max@0
|
3991 }
|
max@0
|
3992
|
max@0
|
3993
|
max@0
|
3994
|
max@0
|
3995 //! returns a pointer to array of eTs for a specified column; no bounds check
|
max@0
|
3996 template<typename eT>
|
max@0
|
3997 arma_inline
|
max@0
|
3998 arma_warn_unused
|
max@0
|
3999 eT*
|
max@0
|
4000 Mat<eT>::colptr(const uword in_col)
|
max@0
|
4001 {
|
max@0
|
4002 return & access::rw(mem[in_col*n_rows]);
|
max@0
|
4003 }
|
max@0
|
4004
|
max@0
|
4005
|
max@0
|
4006
|
max@0
|
4007 //! returns a pointer to array of eTs for a specified column; no bounds check
|
max@0
|
4008 template<typename eT>
|
max@0
|
4009 arma_inline
|
max@0
|
4010 arma_warn_unused
|
max@0
|
4011 const eT*
|
max@0
|
4012 Mat<eT>::colptr(const uword in_col) const
|
max@0
|
4013 {
|
max@0
|
4014 return & mem[in_col*n_rows];
|
max@0
|
4015 }
|
max@0
|
4016
|
max@0
|
4017
|
max@0
|
4018
|
max@0
|
4019 //! returns a pointer to array of eTs used by the matrix
|
max@0
|
4020 template<typename eT>
|
max@0
|
4021 arma_inline
|
max@0
|
4022 arma_warn_unused
|
max@0
|
4023 eT*
|
max@0
|
4024 Mat<eT>::memptr()
|
max@0
|
4025 {
|
max@0
|
4026 return const_cast<eT*>(mem);
|
max@0
|
4027 }
|
max@0
|
4028
|
max@0
|
4029
|
max@0
|
4030
|
max@0
|
4031 //! returns a pointer to array of eTs used by the matrix
|
max@0
|
4032 template<typename eT>
|
max@0
|
4033 arma_inline
|
max@0
|
4034 arma_warn_unused
|
max@0
|
4035 const eT*
|
max@0
|
4036 Mat<eT>::memptr() const
|
max@0
|
4037 {
|
max@0
|
4038 return mem;
|
max@0
|
4039 }
|
max@0
|
4040
|
max@0
|
4041
|
max@0
|
4042
|
max@0
|
4043 //! print contents of the matrix (to the cout stream),
|
max@0
|
4044 //! optionally preceding with a user specified line of text.
|
max@0
|
4045 //! the precision and cell width are modified.
|
max@0
|
4046 //! on return, the stream's state are restored to their original values.
|
max@0
|
4047 template<typename eT>
|
max@0
|
4048 inline
|
max@0
|
4049 void
|
max@0
|
4050 Mat<eT>::impl_print(const std::string& extra_text) const
|
max@0
|
4051 {
|
max@0
|
4052 arma_extra_debug_sigprint();
|
max@0
|
4053
|
max@0
|
4054 if(extra_text.length() != 0)
|
max@0
|
4055 {
|
max@0
|
4056 const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width();
|
max@0
|
4057
|
max@0
|
4058 ARMA_DEFAULT_OSTREAM << extra_text << '\n';
|
max@0
|
4059
|
max@0
|
4060 ARMA_DEFAULT_OSTREAM.width(orig_width);
|
max@0
|
4061 }
|
max@0
|
4062
|
max@0
|
4063 arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true);
|
max@0
|
4064 }
|
max@0
|
4065
|
max@0
|
4066
|
max@0
|
4067
|
max@0
|
4068 //! print contents of the matrix to a user specified stream,
|
max@0
|
4069 //! optionally preceding with a user specified line of text.
|
max@0
|
4070 //! the precision and cell width are modified.
|
max@0
|
4071 //! on return, the stream's state are restored to their original values.
|
max@0
|
4072 template<typename eT>
|
max@0
|
4073 inline
|
max@0
|
4074 void
|
max@0
|
4075 Mat<eT>::impl_print(std::ostream& user_stream, const std::string& extra_text) const
|
max@0
|
4076 {
|
max@0
|
4077 arma_extra_debug_sigprint();
|
max@0
|
4078
|
max@0
|
4079 if(extra_text.length() != 0)
|
max@0
|
4080 {
|
max@0
|
4081 const std::streamsize orig_width = user_stream.width();
|
max@0
|
4082
|
max@0
|
4083 user_stream << extra_text << '\n';
|
max@0
|
4084
|
max@0
|
4085 user_stream.width(orig_width);
|
max@0
|
4086 }
|
max@0
|
4087
|
max@0
|
4088 arma_ostream::print(user_stream, *this, true);
|
max@0
|
4089 }
|
max@0
|
4090
|
max@0
|
4091
|
max@0
|
4092
|
max@0
|
4093 //! DEPRECATED FUNCTION
|
max@0
|
4094 template<typename eT>
|
max@0
|
4095 inline
|
max@0
|
4096 void
|
max@0
|
4097 Mat<eT>::impl_print_trans(const std::string& extra_text) const
|
max@0
|
4098 {
|
max@0
|
4099 arma_extra_debug_sigprint();
|
max@0
|
4100
|
max@0
|
4101 Mat<eT> tmp;
|
max@0
|
4102 op_strans::apply_noalias(tmp, *this);
|
max@0
|
4103
|
max@0
|
4104 tmp.impl_print(extra_text);
|
max@0
|
4105 }
|
max@0
|
4106
|
max@0
|
4107
|
max@0
|
4108
|
max@0
|
4109 //! DEPRECATED FUNCTION
|
max@0
|
4110 template<typename eT>
|
max@0
|
4111 inline
|
max@0
|
4112 void
|
max@0
|
4113 Mat<eT>::impl_print_trans(std::ostream& user_stream, const std::string& extra_text) const
|
max@0
|
4114 {
|
max@0
|
4115 arma_extra_debug_sigprint();
|
max@0
|
4116
|
max@0
|
4117 Mat<eT> tmp;
|
max@0
|
4118 op_strans::apply_noalias(tmp, *this);
|
max@0
|
4119
|
max@0
|
4120 tmp.impl_print(user_stream, extra_text);
|
max@0
|
4121 }
|
max@0
|
4122
|
max@0
|
4123
|
max@0
|
4124
|
max@0
|
4125 //! print contents of the matrix (to the cout stream),
|
max@0
|
4126 //! optionally preceding with a user specified line of text.
|
max@0
|
4127 //! the stream's state are used as is and are not modified
|
max@0
|
4128 //! (i.e. the precision and cell width are not modified).
|
max@0
|
4129 template<typename eT>
|
max@0
|
4130 inline
|
max@0
|
4131 void
|
max@0
|
4132 Mat<eT>::impl_raw_print(const std::string& extra_text) const
|
max@0
|
4133 {
|
max@0
|
4134 arma_extra_debug_sigprint();
|
max@0
|
4135
|
max@0
|
4136 if(extra_text.length() != 0)
|
max@0
|
4137 {
|
max@0
|
4138 const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width();
|
max@0
|
4139
|
max@0
|
4140 ARMA_DEFAULT_OSTREAM << extra_text << '\n';
|
max@0
|
4141
|
max@0
|
4142 ARMA_DEFAULT_OSTREAM.width(orig_width);
|
max@0
|
4143 }
|
max@0
|
4144
|
max@0
|
4145 arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false);
|
max@0
|
4146 }
|
max@0
|
4147
|
max@0
|
4148
|
max@0
|
4149
|
max@0
|
4150 //! print contents of the matrix to a user specified stream,
|
max@0
|
4151 //! optionally preceding with a user specified line of text.
|
max@0
|
4152 //! the stream's state are used as is and are not modified.
|
max@0
|
4153 //! (i.e. the precision and cell width are not modified).
|
max@0
|
4154 template<typename eT>
|
max@0
|
4155 inline
|
max@0
|
4156 void
|
max@0
|
4157 Mat<eT>::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const
|
max@0
|
4158 {
|
max@0
|
4159 arma_extra_debug_sigprint();
|
max@0
|
4160
|
max@0
|
4161 if(extra_text.length() != 0)
|
max@0
|
4162 {
|
max@0
|
4163 const std::streamsize orig_width = user_stream.width();
|
max@0
|
4164
|
max@0
|
4165 user_stream << extra_text << '\n';
|
max@0
|
4166
|
max@0
|
4167 user_stream.width(orig_width);
|
max@0
|
4168 }
|
max@0
|
4169
|
max@0
|
4170 arma_ostream::print(user_stream, *this, false);
|
max@0
|
4171 }
|
max@0
|
4172
|
max@0
|
4173
|
max@0
|
4174
|
max@0
|
4175 //! DEPRECATED FUNCTION
|
max@0
|
4176 template<typename eT>
|
max@0
|
4177 inline
|
max@0
|
4178 void
|
max@0
|
4179 Mat<eT>::impl_raw_print_trans(const std::string& extra_text) const
|
max@0
|
4180 {
|
max@0
|
4181 arma_extra_debug_sigprint();
|
max@0
|
4182
|
max@0
|
4183 Mat<eT> tmp;
|
max@0
|
4184 op_strans::apply_noalias(tmp, *this);
|
max@0
|
4185
|
max@0
|
4186 tmp.impl_raw_print(extra_text);
|
max@0
|
4187 }
|
max@0
|
4188
|
max@0
|
4189
|
max@0
|
4190
|
max@0
|
4191 //! DEPRECATED FUNCTION
|
max@0
|
4192 template<typename eT>
|
max@0
|
4193 inline
|
max@0
|
4194 void
|
max@0
|
4195 Mat<eT>::impl_raw_print_trans(std::ostream& user_stream, const std::string& extra_text) const
|
max@0
|
4196 {
|
max@0
|
4197 arma_extra_debug_sigprint();
|
max@0
|
4198
|
max@0
|
4199 Mat<eT> tmp;
|
max@0
|
4200 op_strans::apply_noalias(tmp, *this);
|
max@0
|
4201
|
max@0
|
4202 tmp.impl_raw_print(user_stream, extra_text);
|
max@0
|
4203 }
|
max@0
|
4204
|
max@0
|
4205
|
max@0
|
4206
|
max@0
|
4207 //! change the matrix to have user specified dimensions (data is not preserved)
|
max@0
|
4208 template<typename eT>
|
max@0
|
4209 inline
|
max@0
|
4210 void
|
max@0
|
4211 Mat<eT>::set_size(const uword in_elem)
|
max@0
|
4212 {
|
max@0
|
4213 arma_extra_debug_sigprint();
|
max@0
|
4214
|
max@0
|
4215 switch(vec_state)
|
max@0
|
4216 {
|
max@0
|
4217 case 0:
|
max@0
|
4218 case 1:
|
max@0
|
4219 init_warm(in_elem, 1);
|
max@0
|
4220 break;
|
max@0
|
4221
|
max@0
|
4222 case 2:
|
max@0
|
4223 init_warm(1, in_elem);
|
max@0
|
4224 break;
|
max@0
|
4225
|
max@0
|
4226 default:
|
max@0
|
4227 ;
|
max@0
|
4228 }
|
max@0
|
4229 }
|
max@0
|
4230
|
max@0
|
4231
|
max@0
|
4232
|
max@0
|
4233 //! change the matrix to have user specified dimensions (data is not preserved)
|
max@0
|
4234 template<typename eT>
|
max@0
|
4235 inline
|
max@0
|
4236 void
|
max@0
|
4237 Mat<eT>::set_size(const uword in_rows, const uword in_cols)
|
max@0
|
4238 {
|
max@0
|
4239 arma_extra_debug_sigprint();
|
max@0
|
4240
|
max@0
|
4241 init_warm(in_rows, in_cols);
|
max@0
|
4242 }
|
max@0
|
4243
|
max@0
|
4244
|
max@0
|
4245
|
max@0
|
4246 //! change the matrix to have user specified dimensions (data is preserved)
|
max@0
|
4247 template<typename eT>
|
max@0
|
4248 inline
|
max@0
|
4249 void
|
max@0
|
4250 Mat<eT>::resize(const uword in_elem)
|
max@0
|
4251 {
|
max@0
|
4252 arma_extra_debug_sigprint();
|
max@0
|
4253
|
max@0
|
4254 switch(vec_state)
|
max@0
|
4255 {
|
max@0
|
4256 case 0:
|
max@0
|
4257 case 1:
|
max@0
|
4258 (*this).resize(in_elem, 1);
|
max@0
|
4259 break;
|
max@0
|
4260
|
max@0
|
4261 case 2:
|
max@0
|
4262 (*this).resize(1, in_elem);
|
max@0
|
4263 break;
|
max@0
|
4264
|
max@0
|
4265 default:
|
max@0
|
4266 ;
|
max@0
|
4267 }
|
max@0
|
4268 }
|
max@0
|
4269
|
max@0
|
4270
|
max@0
|
4271
|
max@0
|
4272 //! change the matrix to have user specified dimensions (data is preserved)
|
max@0
|
4273 template<typename eT>
|
max@0
|
4274 inline
|
max@0
|
4275 void
|
max@0
|
4276 Mat<eT>::resize(const uword in_rows, const uword in_cols)
|
max@0
|
4277 {
|
max@0
|
4278 arma_extra_debug_sigprint();
|
max@0
|
4279
|
max@0
|
4280 *this = arma::resize(*this, in_rows, in_cols);
|
max@0
|
4281 }
|
max@0
|
4282
|
max@0
|
4283
|
max@0
|
4284
|
max@0
|
4285 //! change the matrix to have user specified dimensions (data is preserved)
|
max@0
|
4286 template<typename eT>
|
max@0
|
4287 inline
|
max@0
|
4288 void
|
max@0
|
4289 Mat<eT>::reshape(const uword in_rows, const uword in_cols, const uword dim)
|
max@0
|
4290 {
|
max@0
|
4291 arma_extra_debug_sigprint();
|
max@0
|
4292
|
max@0
|
4293 *this = arma::reshape(*this, in_rows, in_cols, dim);
|
max@0
|
4294 }
|
max@0
|
4295
|
max@0
|
4296
|
max@0
|
4297
|
max@0
|
4298 //! change the matrix (without preserving data) to have the same dimensions as the given matrix
|
max@0
|
4299 template<typename eT>
|
max@0
|
4300 template<typename eT2>
|
max@0
|
4301 inline
|
max@0
|
4302 void
|
max@0
|
4303 Mat<eT>::copy_size(const Mat<eT2>& m)
|
max@0
|
4304 {
|
max@0
|
4305 arma_extra_debug_sigprint();
|
max@0
|
4306
|
max@0
|
4307 init_warm(m.n_rows, m.n_cols);
|
max@0
|
4308 }
|
max@0
|
4309
|
max@0
|
4310
|
max@0
|
4311
|
max@0
|
4312 //! fill the matrix with the specified value
|
max@0
|
4313 template<typename eT>
|
max@0
|
4314 arma_hot
|
max@0
|
4315 inline
|
max@0
|
4316 const Mat<eT>&
|
max@0
|
4317 Mat<eT>::fill(const eT val)
|
max@0
|
4318 {
|
max@0
|
4319 arma_extra_debug_sigprint();
|
max@0
|
4320
|
max@0
|
4321 arrayops::inplace_set( memptr(), val, n_elem );
|
max@0
|
4322
|
max@0
|
4323 return *this;
|
max@0
|
4324 }
|
max@0
|
4325
|
max@0
|
4326
|
max@0
|
4327
|
max@0
|
4328 template<typename eT>
|
max@0
|
4329 inline
|
max@0
|
4330 const Mat<eT>&
|
max@0
|
4331 Mat<eT>::zeros()
|
max@0
|
4332 {
|
max@0
|
4333 arma_extra_debug_sigprint();
|
max@0
|
4334
|
max@0
|
4335 return fill(eT(0));
|
max@0
|
4336 }
|
max@0
|
4337
|
max@0
|
4338
|
max@0
|
4339
|
max@0
|
4340 template<typename eT>
|
max@0
|
4341 inline
|
max@0
|
4342 const Mat<eT>&
|
max@0
|
4343 Mat<eT>::zeros(const uword in_elem)
|
max@0
|
4344 {
|
max@0
|
4345 arma_extra_debug_sigprint();
|
max@0
|
4346
|
max@0
|
4347 set_size(in_elem);
|
max@0
|
4348
|
max@0
|
4349 return fill(eT(0));
|
max@0
|
4350 }
|
max@0
|
4351
|
max@0
|
4352
|
max@0
|
4353
|
max@0
|
4354 template<typename eT>
|
max@0
|
4355 inline
|
max@0
|
4356 const Mat<eT>&
|
max@0
|
4357 Mat<eT>::zeros(const uword in_rows, const uword in_cols)
|
max@0
|
4358 {
|
max@0
|
4359 arma_extra_debug_sigprint();
|
max@0
|
4360
|
max@0
|
4361 set_size(in_rows, in_cols);
|
max@0
|
4362
|
max@0
|
4363 return fill(eT(0));
|
max@0
|
4364 }
|
max@0
|
4365
|
max@0
|
4366
|
max@0
|
4367
|
max@0
|
4368 template<typename eT>
|
max@0
|
4369 inline
|
max@0
|
4370 const Mat<eT>&
|
max@0
|
4371 Mat<eT>::ones()
|
max@0
|
4372 {
|
max@0
|
4373 arma_extra_debug_sigprint();
|
max@0
|
4374
|
max@0
|
4375 return fill(eT(1));
|
max@0
|
4376 }
|
max@0
|
4377
|
max@0
|
4378
|
max@0
|
4379
|
max@0
|
4380 template<typename eT>
|
max@0
|
4381 inline
|
max@0
|
4382 const Mat<eT>&
|
max@0
|
4383 Mat<eT>::ones(const uword in_elem)
|
max@0
|
4384 {
|
max@0
|
4385 arma_extra_debug_sigprint();
|
max@0
|
4386
|
max@0
|
4387 set_size(in_elem);
|
max@0
|
4388
|
max@0
|
4389 return fill(eT(1));
|
max@0
|
4390 }
|
max@0
|
4391
|
max@0
|
4392
|
max@0
|
4393
|
max@0
|
4394 template<typename eT>
|
max@0
|
4395 inline
|
max@0
|
4396 const Mat<eT>&
|
max@0
|
4397 Mat<eT>::ones(const uword in_rows, const uword in_cols)
|
max@0
|
4398 {
|
max@0
|
4399 arma_extra_debug_sigprint();
|
max@0
|
4400
|
max@0
|
4401 set_size(in_rows, in_cols);
|
max@0
|
4402
|
max@0
|
4403 return fill(eT(1));
|
max@0
|
4404 }
|
max@0
|
4405
|
max@0
|
4406
|
max@0
|
4407
|
max@0
|
4408 template<typename eT>
|
max@0
|
4409 inline
|
max@0
|
4410 const Mat<eT>&
|
max@0
|
4411 Mat<eT>::randu()
|
max@0
|
4412 {
|
max@0
|
4413 arma_extra_debug_sigprint();
|
max@0
|
4414
|
max@0
|
4415 const uword N = n_elem;
|
max@0
|
4416 eT* ptr = memptr();
|
max@0
|
4417
|
max@0
|
4418 uword i,j;
|
max@0
|
4419
|
max@0
|
4420 for(i=0, j=1; j<N; i+=2, j+=2)
|
max@0
|
4421 {
|
max@0
|
4422 const eT tmp_i = eT(eop_aux_randu<eT>());
|
max@0
|
4423 const eT tmp_j = eT(eop_aux_randu<eT>());
|
max@0
|
4424
|
max@0
|
4425 ptr[i] = tmp_i;
|
max@0
|
4426 ptr[j] = tmp_j;
|
max@0
|
4427 }
|
max@0
|
4428
|
max@0
|
4429 if(i < N)
|
max@0
|
4430 {
|
max@0
|
4431 ptr[i] = eT(eop_aux_randu<eT>());
|
max@0
|
4432 }
|
max@0
|
4433
|
max@0
|
4434 return *this;
|
max@0
|
4435 }
|
max@0
|
4436
|
max@0
|
4437
|
max@0
|
4438
|
max@0
|
4439 template<typename eT>
|
max@0
|
4440 inline
|
max@0
|
4441 const Mat<eT>&
|
max@0
|
4442 Mat<eT>::randu(const uword in_elem)
|
max@0
|
4443 {
|
max@0
|
4444 arma_extra_debug_sigprint();
|
max@0
|
4445
|
max@0
|
4446 set_size(in_elem);
|
max@0
|
4447
|
max@0
|
4448 return (*this).randu();
|
max@0
|
4449 }
|
max@0
|
4450
|
max@0
|
4451
|
max@0
|
4452
|
max@0
|
4453 template<typename eT>
|
max@0
|
4454 inline
|
max@0
|
4455 const Mat<eT>&
|
max@0
|
4456 Mat<eT>::randu(const uword in_rows, const uword in_cols)
|
max@0
|
4457 {
|
max@0
|
4458 arma_extra_debug_sigprint();
|
max@0
|
4459
|
max@0
|
4460 set_size(in_rows, in_cols);
|
max@0
|
4461
|
max@0
|
4462 return (*this).randu();
|
max@0
|
4463 }
|
max@0
|
4464
|
max@0
|
4465
|
max@0
|
4466
|
max@0
|
4467 template<typename eT>
|
max@0
|
4468 inline
|
max@0
|
4469 const Mat<eT>&
|
max@0
|
4470 Mat<eT>::randn()
|
max@0
|
4471 {
|
max@0
|
4472 arma_extra_debug_sigprint();
|
max@0
|
4473
|
max@0
|
4474 const uword N = n_elem;
|
max@0
|
4475 eT* ptr = memptr();
|
max@0
|
4476
|
max@0
|
4477 for(uword i=0; i<N; ++i)
|
max@0
|
4478 {
|
max@0
|
4479 ptr[i] = eT(eop_aux_randn<eT>());
|
max@0
|
4480 }
|
max@0
|
4481
|
max@0
|
4482 return *this;
|
max@0
|
4483 }
|
max@0
|
4484
|
max@0
|
4485
|
max@0
|
4486
|
max@0
|
4487 template<typename eT>
|
max@0
|
4488 inline
|
max@0
|
4489 const Mat<eT>&
|
max@0
|
4490 Mat<eT>::randn(const uword in_elem)
|
max@0
|
4491 {
|
max@0
|
4492 arma_extra_debug_sigprint();
|
max@0
|
4493
|
max@0
|
4494 set_size(in_elem);
|
max@0
|
4495
|
max@0
|
4496 return (*this).randn();
|
max@0
|
4497 }
|
max@0
|
4498
|
max@0
|
4499
|
max@0
|
4500
|
max@0
|
4501 template<typename eT>
|
max@0
|
4502 inline
|
max@0
|
4503 const Mat<eT>&
|
max@0
|
4504 Mat<eT>::randn(const uword in_rows, const uword in_cols)
|
max@0
|
4505 {
|
max@0
|
4506 arma_extra_debug_sigprint();
|
max@0
|
4507
|
max@0
|
4508 set_size(in_rows, in_cols);
|
max@0
|
4509
|
max@0
|
4510 return (*this).randn();
|
max@0
|
4511 }
|
max@0
|
4512
|
max@0
|
4513
|
max@0
|
4514
|
max@0
|
4515 template<typename eT>
|
max@0
|
4516 inline
|
max@0
|
4517 const Mat<eT>&
|
max@0
|
4518 Mat<eT>::eye()
|
max@0
|
4519 {
|
max@0
|
4520 arma_extra_debug_sigprint();
|
max@0
|
4521
|
max@0
|
4522 fill(eT(0));
|
max@0
|
4523
|
max@0
|
4524 const uword N = (std::min)(n_rows, n_cols);
|
max@0
|
4525
|
max@0
|
4526 for(uword i=0; i<N; ++i)
|
max@0
|
4527 {
|
max@0
|
4528 at(i,i) = eT(1);
|
max@0
|
4529 }
|
max@0
|
4530
|
max@0
|
4531 return *this;
|
max@0
|
4532 }
|
max@0
|
4533
|
max@0
|
4534
|
max@0
|
4535
|
max@0
|
4536 template<typename eT>
|
max@0
|
4537 inline
|
max@0
|
4538 const Mat<eT>&
|
max@0
|
4539 Mat<eT>::eye(const uword in_rows, const uword in_cols)
|
max@0
|
4540 {
|
max@0
|
4541 arma_extra_debug_sigprint();
|
max@0
|
4542
|
max@0
|
4543 set_size(in_rows, in_cols);
|
max@0
|
4544
|
max@0
|
4545 return (*this).eye();
|
max@0
|
4546 }
|
max@0
|
4547
|
max@0
|
4548
|
max@0
|
4549
|
max@0
|
4550 template<typename eT>
|
max@0
|
4551 inline
|
max@0
|
4552 void
|
max@0
|
4553 Mat<eT>::reset()
|
max@0
|
4554 {
|
max@0
|
4555 arma_extra_debug_sigprint();
|
max@0
|
4556
|
max@0
|
4557 switch(vec_state)
|
max@0
|
4558 {
|
max@0
|
4559 default:
|
max@0
|
4560 init_warm(0, 0);
|
max@0
|
4561 break;
|
max@0
|
4562
|
max@0
|
4563 case 1:
|
max@0
|
4564 init_warm(0, 1);
|
max@0
|
4565 break;
|
max@0
|
4566
|
max@0
|
4567 case 2:
|
max@0
|
4568 init_warm(1, 0);
|
max@0
|
4569 break;
|
max@0
|
4570 }
|
max@0
|
4571 }
|
max@0
|
4572
|
max@0
|
4573
|
max@0
|
4574
|
max@0
|
4575 template<typename eT>
|
max@0
|
4576 template<typename T1>
|
max@0
|
4577 inline
|
max@0
|
4578 void
|
max@0
|
4579 Mat<eT>::set_real(const Base<typename Mat<eT>::pod_type,T1>& X)
|
max@0
|
4580 {
|
max@0
|
4581 arma_extra_debug_sigprint();
|
max@0
|
4582
|
max@0
|
4583 Mat_aux::set_real(*this, X);
|
max@0
|
4584 }
|
max@0
|
4585
|
max@0
|
4586
|
max@0
|
4587
|
max@0
|
4588 template<typename eT>
|
max@0
|
4589 template<typename T1>
|
max@0
|
4590 inline
|
max@0
|
4591 void
|
max@0
|
4592 Mat<eT>::set_imag(const Base<typename Mat<eT>::pod_type,T1>& X)
|
max@0
|
4593 {
|
max@0
|
4594 arma_extra_debug_sigprint();
|
max@0
|
4595
|
max@0
|
4596 Mat_aux::set_imag(*this, X);
|
max@0
|
4597 }
|
max@0
|
4598
|
max@0
|
4599
|
max@0
|
4600
|
max@0
|
4601 template<typename eT>
|
max@0
|
4602 inline
|
max@0
|
4603 arma_warn_unused
|
max@0
|
4604 eT
|
max@0
|
4605 Mat<eT>::min() const
|
max@0
|
4606 {
|
max@0
|
4607 arma_extra_debug_sigprint();
|
max@0
|
4608
|
max@0
|
4609 arma_debug_check( (n_elem == 0), "min(): object has no elements" );
|
max@0
|
4610
|
max@0
|
4611 return op_min::direct_min(memptr(), n_elem);
|
max@0
|
4612 }
|
max@0
|
4613
|
max@0
|
4614
|
max@0
|
4615
|
max@0
|
4616 template<typename eT>
|
max@0
|
4617 inline
|
max@0
|
4618 arma_warn_unused
|
max@0
|
4619 eT
|
max@0
|
4620 Mat<eT>::max() const
|
max@0
|
4621 {
|
max@0
|
4622 arma_extra_debug_sigprint();
|
max@0
|
4623
|
max@0
|
4624 arma_debug_check( (n_elem == 0), "max(): object has no elements" );
|
max@0
|
4625
|
max@0
|
4626 return op_max::direct_max(memptr(), n_elem);
|
max@0
|
4627 }
|
max@0
|
4628
|
max@0
|
4629
|
max@0
|
4630
|
max@0
|
4631 template<typename eT>
|
max@0
|
4632 inline
|
max@0
|
4633 eT
|
max@0
|
4634 Mat<eT>::min(uword& index_of_min_val) const
|
max@0
|
4635 {
|
max@0
|
4636 arma_extra_debug_sigprint();
|
max@0
|
4637
|
max@0
|
4638 arma_debug_check( (n_elem == 0), "min(): object has no elements" );
|
max@0
|
4639
|
max@0
|
4640 return op_min::direct_min(memptr(), n_elem, index_of_min_val);
|
max@0
|
4641 }
|
max@0
|
4642
|
max@0
|
4643
|
max@0
|
4644
|
max@0
|
4645 template<typename eT>
|
max@0
|
4646 inline
|
max@0
|
4647 eT
|
max@0
|
4648 Mat<eT>::max(uword& index_of_max_val) const
|
max@0
|
4649 {
|
max@0
|
4650 arma_extra_debug_sigprint();
|
max@0
|
4651
|
max@0
|
4652 arma_debug_check( (n_elem == 0), "max(): object has no elements" );
|
max@0
|
4653
|
max@0
|
4654 return op_max::direct_max(memptr(), n_elem, index_of_max_val);
|
max@0
|
4655 }
|
max@0
|
4656
|
max@0
|
4657
|
max@0
|
4658
|
max@0
|
4659 template<typename eT>
|
max@0
|
4660 inline
|
max@0
|
4661 eT
|
max@0
|
4662 Mat<eT>::min(uword& row_of_min_val, uword& col_of_min_val) const
|
max@0
|
4663 {
|
max@0
|
4664 arma_extra_debug_sigprint();
|
max@0
|
4665
|
max@0
|
4666 arma_debug_check( (n_elem == 0), "min(): object has no elements" );
|
max@0
|
4667
|
max@0
|
4668 uword i;
|
max@0
|
4669
|
max@0
|
4670 eT val = op_min::direct_min(memptr(), n_elem, i);
|
max@0
|
4671
|
max@0
|
4672 row_of_min_val = i % n_rows;
|
max@0
|
4673 col_of_min_val = i / n_rows;
|
max@0
|
4674
|
max@0
|
4675 return val;
|
max@0
|
4676 }
|
max@0
|
4677
|
max@0
|
4678
|
max@0
|
4679
|
max@0
|
4680 template<typename eT>
|
max@0
|
4681 inline
|
max@0
|
4682 eT
|
max@0
|
4683 Mat<eT>::max(uword& row_of_max_val, uword& col_of_max_val) const
|
max@0
|
4684 {
|
max@0
|
4685 arma_extra_debug_sigprint();
|
max@0
|
4686
|
max@0
|
4687 arma_debug_check( (n_elem == 0), "max(): object has no elements" );
|
max@0
|
4688
|
max@0
|
4689 uword i;
|
max@0
|
4690
|
max@0
|
4691 eT val = op_max::direct_max(memptr(), n_elem, i);
|
max@0
|
4692
|
max@0
|
4693 row_of_max_val = i % n_rows;
|
max@0
|
4694 col_of_max_val = i / n_rows;
|
max@0
|
4695
|
max@0
|
4696 return val;
|
max@0
|
4697 }
|
max@0
|
4698
|
max@0
|
4699
|
max@0
|
4700
|
max@0
|
4701 //! save the matrix to a file
|
max@0
|
4702 template<typename eT>
|
max@0
|
4703 inline
|
max@0
|
4704 bool
|
max@0
|
4705 Mat<eT>::save(const std::string name, const file_type type, const bool print_status) const
|
max@0
|
4706 {
|
max@0
|
4707 arma_extra_debug_sigprint();
|
max@0
|
4708
|
max@0
|
4709 bool save_okay;
|
max@0
|
4710
|
max@0
|
4711 switch(type)
|
max@0
|
4712 {
|
max@0
|
4713 case raw_ascii:
|
max@0
|
4714 save_okay = diskio::save_raw_ascii(*this, name);
|
max@0
|
4715 break;
|
max@0
|
4716
|
max@0
|
4717 case arma_ascii:
|
max@0
|
4718 save_okay = diskio::save_arma_ascii(*this, name);
|
max@0
|
4719 break;
|
max@0
|
4720
|
max@0
|
4721 case csv_ascii:
|
max@0
|
4722 save_okay = diskio::save_csv_ascii(*this, name);
|
max@0
|
4723 break;
|
max@0
|
4724
|
max@0
|
4725 case raw_binary:
|
max@0
|
4726 save_okay = diskio::save_raw_binary(*this, name);
|
max@0
|
4727 break;
|
max@0
|
4728
|
max@0
|
4729 case arma_binary:
|
max@0
|
4730 save_okay = diskio::save_arma_binary(*this, name);
|
max@0
|
4731 break;
|
max@0
|
4732
|
max@0
|
4733 case pgm_binary:
|
max@0
|
4734 save_okay = diskio::save_pgm_binary(*this, name);
|
max@0
|
4735 break;
|
max@0
|
4736
|
max@0
|
4737 default:
|
max@0
|
4738 arma_warn(print_status, "Mat::save(): unsupported file type");
|
max@0
|
4739 save_okay = false;
|
max@0
|
4740 }
|
max@0
|
4741
|
max@0
|
4742 arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to ", name);
|
max@0
|
4743
|
max@0
|
4744 return save_okay;
|
max@0
|
4745 }
|
max@0
|
4746
|
max@0
|
4747
|
max@0
|
4748
|
max@0
|
4749 //! save the matrix to a stream
|
max@0
|
4750 template<typename eT>
|
max@0
|
4751 inline
|
max@0
|
4752 bool
|
max@0
|
4753 Mat<eT>::save(std::ostream& os, const file_type type, const bool print_status) const
|
max@0
|
4754 {
|
max@0
|
4755 arma_extra_debug_sigprint();
|
max@0
|
4756
|
max@0
|
4757 bool save_okay;
|
max@0
|
4758
|
max@0
|
4759 switch(type)
|
max@0
|
4760 {
|
max@0
|
4761 case raw_ascii:
|
max@0
|
4762 save_okay = diskio::save_raw_ascii(*this, os);
|
max@0
|
4763 break;
|
max@0
|
4764
|
max@0
|
4765 case arma_ascii:
|
max@0
|
4766 save_okay = diskio::save_arma_ascii(*this, os);
|
max@0
|
4767 break;
|
max@0
|
4768
|
max@0
|
4769 case csv_ascii:
|
max@0
|
4770 save_okay = diskio::save_csv_ascii(*this, os);
|
max@0
|
4771 break;
|
max@0
|
4772
|
max@0
|
4773 case raw_binary:
|
max@0
|
4774 save_okay = diskio::save_raw_binary(*this, os);
|
max@0
|
4775 break;
|
max@0
|
4776
|
max@0
|
4777 case arma_binary:
|
max@0
|
4778 save_okay = diskio::save_arma_binary(*this, os);
|
max@0
|
4779 break;
|
max@0
|
4780
|
max@0
|
4781 case pgm_binary:
|
max@0
|
4782 save_okay = diskio::save_pgm_binary(*this, os);
|
max@0
|
4783 break;
|
max@0
|
4784
|
max@0
|
4785 default:
|
max@0
|
4786 arma_warn(print_status, "Mat::save(): unsupported file type");
|
max@0
|
4787 save_okay = false;
|
max@0
|
4788 }
|
max@0
|
4789
|
max@0
|
4790 arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to the given stream");
|
max@0
|
4791
|
max@0
|
4792 return save_okay;
|
max@0
|
4793 }
|
max@0
|
4794
|
max@0
|
4795
|
max@0
|
4796
|
max@0
|
4797 //! load a matrix from a file
|
max@0
|
4798 template<typename eT>
|
max@0
|
4799 inline
|
max@0
|
4800 bool
|
max@0
|
4801 Mat<eT>::load(const std::string name, const file_type type, const bool print_status)
|
max@0
|
4802 {
|
max@0
|
4803 arma_extra_debug_sigprint();
|
max@0
|
4804
|
max@0
|
4805 bool load_okay;
|
max@0
|
4806 std::string err_msg;
|
max@0
|
4807
|
max@0
|
4808 switch(type)
|
max@0
|
4809 {
|
max@0
|
4810 case auto_detect:
|
max@0
|
4811 load_okay = diskio::load_auto_detect(*this, name, err_msg);
|
max@0
|
4812 break;
|
max@0
|
4813
|
max@0
|
4814 case raw_ascii:
|
max@0
|
4815 load_okay = diskio::load_raw_ascii(*this, name, err_msg);
|
max@0
|
4816 break;
|
max@0
|
4817
|
max@0
|
4818 case arma_ascii:
|
max@0
|
4819 load_okay = diskio::load_arma_ascii(*this, name, err_msg);
|
max@0
|
4820 break;
|
max@0
|
4821
|
max@0
|
4822 case csv_ascii:
|
max@0
|
4823 load_okay = diskio::load_csv_ascii(*this, name, err_msg);
|
max@0
|
4824 break;
|
max@0
|
4825
|
max@0
|
4826 case raw_binary:
|
max@0
|
4827 load_okay = diskio::load_raw_binary(*this, name, err_msg);
|
max@0
|
4828 break;
|
max@0
|
4829
|
max@0
|
4830 case arma_binary:
|
max@0
|
4831 load_okay = diskio::load_arma_binary(*this, name, err_msg);
|
max@0
|
4832 break;
|
max@0
|
4833
|
max@0
|
4834 case pgm_binary:
|
max@0
|
4835 load_okay = diskio::load_pgm_binary(*this, name, err_msg);
|
max@0
|
4836 break;
|
max@0
|
4837
|
max@0
|
4838 default:
|
max@0
|
4839 arma_warn(print_status, "Mat::load(): unsupported file type");
|
max@0
|
4840 load_okay = false;
|
max@0
|
4841 }
|
max@0
|
4842
|
max@0
|
4843 if( (print_status == true) && (load_okay == false) )
|
max@0
|
4844 {
|
max@0
|
4845 if(err_msg.length() > 0)
|
max@0
|
4846 {
|
max@0
|
4847 arma_warn(true, "Mat::load(): ", err_msg, name);
|
max@0
|
4848 }
|
max@0
|
4849 else
|
max@0
|
4850 {
|
max@0
|
4851 arma_warn(true, "Mat::load(): couldn't read ", name);
|
max@0
|
4852 }
|
max@0
|
4853 }
|
max@0
|
4854
|
max@0
|
4855 if(load_okay == false)
|
max@0
|
4856 {
|
max@0
|
4857 (*this).reset();
|
max@0
|
4858 }
|
max@0
|
4859
|
max@0
|
4860 return load_okay;
|
max@0
|
4861 }
|
max@0
|
4862
|
max@0
|
4863
|
max@0
|
4864
|
max@0
|
4865 //! load a matrix from a stream
|
max@0
|
4866 template<typename eT>
|
max@0
|
4867 inline
|
max@0
|
4868 bool
|
max@0
|
4869 Mat<eT>::load(std::istream& is, const file_type type, const bool print_status)
|
max@0
|
4870 {
|
max@0
|
4871 arma_extra_debug_sigprint();
|
max@0
|
4872
|
max@0
|
4873 bool load_okay;
|
max@0
|
4874 std::string err_msg;
|
max@0
|
4875
|
max@0
|
4876 switch(type)
|
max@0
|
4877 {
|
max@0
|
4878 case auto_detect:
|
max@0
|
4879 load_okay = diskio::load_auto_detect(*this, is, err_msg);
|
max@0
|
4880 break;
|
max@0
|
4881
|
max@0
|
4882 case raw_ascii:
|
max@0
|
4883 load_okay = diskio::load_raw_ascii(*this, is, err_msg);
|
max@0
|
4884 break;
|
max@0
|
4885
|
max@0
|
4886 case arma_ascii:
|
max@0
|
4887 load_okay = diskio::load_arma_ascii(*this, is, err_msg);
|
max@0
|
4888 break;
|
max@0
|
4889
|
max@0
|
4890 case csv_ascii:
|
max@0
|
4891 load_okay = diskio::load_csv_ascii(*this, is, err_msg);
|
max@0
|
4892 break;
|
max@0
|
4893
|
max@0
|
4894 case raw_binary:
|
max@0
|
4895 load_okay = diskio::load_raw_binary(*this, is, err_msg);
|
max@0
|
4896 break;
|
max@0
|
4897
|
max@0
|
4898 case arma_binary:
|
max@0
|
4899 load_okay = diskio::load_arma_binary(*this, is, err_msg);
|
max@0
|
4900 break;
|
max@0
|
4901
|
max@0
|
4902 case pgm_binary:
|
max@0
|
4903 load_okay = diskio::load_pgm_binary(*this, is, err_msg);
|
max@0
|
4904 break;
|
max@0
|
4905
|
max@0
|
4906 default:
|
max@0
|
4907 arma_warn(print_status, "Mat::load(): unsupported file type");
|
max@0
|
4908 load_okay = false;
|
max@0
|
4909 }
|
max@0
|
4910
|
max@0
|
4911
|
max@0
|
4912 if( (print_status == true) && (load_okay == false) )
|
max@0
|
4913 {
|
max@0
|
4914 if(err_msg.length() > 0)
|
max@0
|
4915 {
|
max@0
|
4916 arma_warn(true, "Mat::load(): ", err_msg, "the given stream");
|
max@0
|
4917 }
|
max@0
|
4918 else
|
max@0
|
4919 {
|
max@0
|
4920 arma_warn(true, "Mat::load(): couldn't load from the given stream");
|
max@0
|
4921 }
|
max@0
|
4922 }
|
max@0
|
4923
|
max@0
|
4924 if(load_okay == false)
|
max@0
|
4925 {
|
max@0
|
4926 (*this).reset();
|
max@0
|
4927 }
|
max@0
|
4928
|
max@0
|
4929 return load_okay;
|
max@0
|
4930 }
|
max@0
|
4931
|
max@0
|
4932
|
max@0
|
4933
|
max@0
|
4934 //! save the matrix to a file, without printing any error messages
|
max@0
|
4935 template<typename eT>
|
max@0
|
4936 inline
|
max@0
|
4937 bool
|
max@0
|
4938 Mat<eT>::quiet_save(const std::string name, const file_type type) const
|
max@0
|
4939 {
|
max@0
|
4940 arma_extra_debug_sigprint();
|
max@0
|
4941
|
max@0
|
4942 return (*this).save(name, type, false);
|
max@0
|
4943 }
|
max@0
|
4944
|
max@0
|
4945
|
max@0
|
4946
|
max@0
|
4947 //! save the matrix to a stream, without printing any error messages
|
max@0
|
4948 template<typename eT>
|
max@0
|
4949 inline
|
max@0
|
4950 bool
|
max@0
|
4951 Mat<eT>::quiet_save(std::ostream& os, const file_type type) const
|
max@0
|
4952 {
|
max@0
|
4953 arma_extra_debug_sigprint();
|
max@0
|
4954
|
max@0
|
4955 return (*this).save(os, type, false);
|
max@0
|
4956 }
|
max@0
|
4957
|
max@0
|
4958
|
max@0
|
4959
|
max@0
|
4960 //! load a matrix from a file, without printing any error messages
|
max@0
|
4961 template<typename eT>
|
max@0
|
4962 inline
|
max@0
|
4963 bool
|
max@0
|
4964 Mat<eT>::quiet_load(const std::string name, const file_type type)
|
max@0
|
4965 {
|
max@0
|
4966 arma_extra_debug_sigprint();
|
max@0
|
4967
|
max@0
|
4968 return (*this).load(name, type, false);
|
max@0
|
4969 }
|
max@0
|
4970
|
max@0
|
4971
|
max@0
|
4972
|
max@0
|
4973 //! load a matrix from a stream, without printing any error messages
|
max@0
|
4974 template<typename eT>
|
max@0
|
4975 inline
|
max@0
|
4976 bool
|
max@0
|
4977 Mat<eT>::quiet_load(std::istream& is, const file_type type)
|
max@0
|
4978 {
|
max@0
|
4979 arma_extra_debug_sigprint();
|
max@0
|
4980
|
max@0
|
4981 return (*this).load(is, type, false);
|
max@0
|
4982 }
|
max@0
|
4983
|
max@0
|
4984
|
max@0
|
4985
|
max@0
|
4986 template<typename eT>
|
max@0
|
4987 inline
|
max@0
|
4988 Mat<eT>::row_iterator::row_iterator(Mat<eT>& in_M, const uword in_row)
|
max@0
|
4989 : M (in_M )
|
max@0
|
4990 , row(in_row)
|
max@0
|
4991 , col(0 )
|
max@0
|
4992 {
|
max@0
|
4993 arma_extra_debug_sigprint();
|
max@0
|
4994 }
|
max@0
|
4995
|
max@0
|
4996
|
max@0
|
4997
|
max@0
|
4998 template<typename eT>
|
max@0
|
4999 inline
|
max@0
|
5000 eT&
|
max@0
|
5001 Mat<eT>::row_iterator::operator*()
|
max@0
|
5002 {
|
max@0
|
5003 return M.at(row,col);
|
max@0
|
5004 }
|
max@0
|
5005
|
max@0
|
5006
|
max@0
|
5007
|
max@0
|
5008 template<typename eT>
|
max@0
|
5009 inline
|
max@0
|
5010 typename Mat<eT>::row_iterator&
|
max@0
|
5011 Mat<eT>::row_iterator::operator++()
|
max@0
|
5012 {
|
max@0
|
5013 ++col;
|
max@0
|
5014
|
max@0
|
5015 if(col >= M.n_cols)
|
max@0
|
5016 {
|
max@0
|
5017 col = 0;
|
max@0
|
5018 ++row;
|
max@0
|
5019 }
|
max@0
|
5020
|
max@0
|
5021 return *this;
|
max@0
|
5022 }
|
max@0
|
5023
|
max@0
|
5024
|
max@0
|
5025
|
max@0
|
5026 template<typename eT>
|
max@0
|
5027 inline
|
max@0
|
5028 void
|
max@0
|
5029 Mat<eT>::row_iterator::operator++(int)
|
max@0
|
5030 {
|
max@0
|
5031 operator++();
|
max@0
|
5032 }
|
max@0
|
5033
|
max@0
|
5034
|
max@0
|
5035
|
max@0
|
5036 template<typename eT>
|
max@0
|
5037 inline
|
max@0
|
5038 typename Mat<eT>::row_iterator&
|
max@0
|
5039 Mat<eT>::row_iterator::operator--()
|
max@0
|
5040 {
|
max@0
|
5041 if(col > 0)
|
max@0
|
5042 {
|
max@0
|
5043 --col;
|
max@0
|
5044 }
|
max@0
|
5045 else
|
max@0
|
5046 {
|
max@0
|
5047 if(row > 0)
|
max@0
|
5048 {
|
max@0
|
5049 col = M.n_cols - 1;
|
max@0
|
5050 --row;
|
max@0
|
5051 }
|
max@0
|
5052 }
|
max@0
|
5053
|
max@0
|
5054 return *this;
|
max@0
|
5055 }
|
max@0
|
5056
|
max@0
|
5057
|
max@0
|
5058
|
max@0
|
5059 template<typename eT>
|
max@0
|
5060 inline
|
max@0
|
5061 void
|
max@0
|
5062 Mat<eT>::row_iterator::operator--(int)
|
max@0
|
5063 {
|
max@0
|
5064 operator--();
|
max@0
|
5065 }
|
max@0
|
5066
|
max@0
|
5067
|
max@0
|
5068
|
max@0
|
5069 template<typename eT>
|
max@0
|
5070 inline
|
max@0
|
5071 bool
|
max@0
|
5072 Mat<eT>::row_iterator::operator!=(const typename Mat<eT>::row_iterator& X) const
|
max@0
|
5073 {
|
max@0
|
5074 return ( (row != X.row) || (col != X.col) ) ? true : false;
|
max@0
|
5075 }
|
max@0
|
5076
|
max@0
|
5077
|
max@0
|
5078
|
max@0
|
5079 template<typename eT>
|
max@0
|
5080 inline
|
max@0
|
5081 bool
|
max@0
|
5082 Mat<eT>::row_iterator::operator==(const typename Mat<eT>::row_iterator& X) const
|
max@0
|
5083 {
|
max@0
|
5084 return ( (row == X.row) && (col == X.col) ) ? true : false;
|
max@0
|
5085 }
|
max@0
|
5086
|
max@0
|
5087
|
max@0
|
5088
|
max@0
|
5089 template<typename eT>
|
max@0
|
5090 inline
|
max@0
|
5091 Mat<eT>::const_row_iterator::const_row_iterator(const Mat<eT>& in_M, const uword in_row)
|
max@0
|
5092 : M (in_M )
|
max@0
|
5093 , row(in_row)
|
max@0
|
5094 , col(0 )
|
max@0
|
5095 {
|
max@0
|
5096 arma_extra_debug_sigprint();
|
max@0
|
5097 }
|
max@0
|
5098
|
max@0
|
5099
|
max@0
|
5100
|
max@0
|
5101 template<typename eT>
|
max@0
|
5102 inline
|
max@0
|
5103 Mat<eT>::const_row_iterator::const_row_iterator(const typename Mat<eT>::row_iterator& X)
|
max@0
|
5104 : M (X.M)
|
max@0
|
5105 , row(X.row)
|
max@0
|
5106 , col(X.col)
|
max@0
|
5107 {
|
max@0
|
5108 arma_extra_debug_sigprint();
|
max@0
|
5109 }
|
max@0
|
5110
|
max@0
|
5111
|
max@0
|
5112
|
max@0
|
5113 template<typename eT>
|
max@0
|
5114 inline
|
max@0
|
5115 eT
|
max@0
|
5116 Mat<eT>::const_row_iterator::operator*() const
|
max@0
|
5117 {
|
max@0
|
5118 return M.at(row,col);
|
max@0
|
5119 }
|
max@0
|
5120
|
max@0
|
5121
|
max@0
|
5122
|
max@0
|
5123 template<typename eT>
|
max@0
|
5124 inline
|
max@0
|
5125 typename Mat<eT>::const_row_iterator&
|
max@0
|
5126 Mat<eT>::const_row_iterator::operator++()
|
max@0
|
5127 {
|
max@0
|
5128 ++col;
|
max@0
|
5129
|
max@0
|
5130 if(col >= M.n_cols)
|
max@0
|
5131 {
|
max@0
|
5132 col = 0;
|
max@0
|
5133 ++row;
|
max@0
|
5134 }
|
max@0
|
5135
|
max@0
|
5136 return *this;
|
max@0
|
5137 }
|
max@0
|
5138
|
max@0
|
5139
|
max@0
|
5140
|
max@0
|
5141 template<typename eT>
|
max@0
|
5142 inline
|
max@0
|
5143 void
|
max@0
|
5144 Mat<eT>::const_row_iterator::operator++(int)
|
max@0
|
5145 {
|
max@0
|
5146 operator++();
|
max@0
|
5147 }
|
max@0
|
5148
|
max@0
|
5149
|
max@0
|
5150
|
max@0
|
5151 template<typename eT>
|
max@0
|
5152 inline
|
max@0
|
5153 typename Mat<eT>::const_row_iterator&
|
max@0
|
5154 Mat<eT>::const_row_iterator::operator--()
|
max@0
|
5155 {
|
max@0
|
5156 if(col > 0)
|
max@0
|
5157 {
|
max@0
|
5158 --col;
|
max@0
|
5159 }
|
max@0
|
5160 else
|
max@0
|
5161 {
|
max@0
|
5162 if(row > 0)
|
max@0
|
5163 {
|
max@0
|
5164 col = M.n_cols - 1;
|
max@0
|
5165 --row;
|
max@0
|
5166 }
|
max@0
|
5167 }
|
max@0
|
5168
|
max@0
|
5169 return *this;
|
max@0
|
5170 }
|
max@0
|
5171
|
max@0
|
5172
|
max@0
|
5173
|
max@0
|
5174 template<typename eT>
|
max@0
|
5175 inline
|
max@0
|
5176 void
|
max@0
|
5177 Mat<eT>::const_row_iterator::operator--(int)
|
max@0
|
5178 {
|
max@0
|
5179 operator--();
|
max@0
|
5180 }
|
max@0
|
5181
|
max@0
|
5182
|
max@0
|
5183
|
max@0
|
5184 template<typename eT>
|
max@0
|
5185 inline
|
max@0
|
5186 bool
|
max@0
|
5187 Mat<eT>::const_row_iterator::operator!=(const typename Mat<eT>::const_row_iterator& X) const
|
max@0
|
5188 {
|
max@0
|
5189 return ( (row != X.row) || (col != X.col) ) ? true : false;
|
max@0
|
5190 }
|
max@0
|
5191
|
max@0
|
5192
|
max@0
|
5193
|
max@0
|
5194 template<typename eT>
|
max@0
|
5195 inline
|
max@0
|
5196 bool
|
max@0
|
5197 Mat<eT>::const_row_iterator::operator==(const typename Mat<eT>::const_row_iterator& X) const
|
max@0
|
5198 {
|
max@0
|
5199 return ( (row == X.row) && (col == X.col) ) ? true : false;
|
max@0
|
5200 }
|
max@0
|
5201
|
max@0
|
5202
|
max@0
|
5203
|
max@0
|
5204 template<typename eT>
|
max@0
|
5205 inline
|
max@0
|
5206 typename Mat<eT>::iterator
|
max@0
|
5207 Mat<eT>::begin()
|
max@0
|
5208 {
|
max@0
|
5209 arma_extra_debug_sigprint();
|
max@0
|
5210
|
max@0
|
5211 return memptr();
|
max@0
|
5212 }
|
max@0
|
5213
|
max@0
|
5214
|
max@0
|
5215
|
max@0
|
5216 template<typename eT>
|
max@0
|
5217 inline
|
max@0
|
5218 typename Mat<eT>::const_iterator
|
max@0
|
5219 Mat<eT>::begin() const
|
max@0
|
5220 {
|
max@0
|
5221 arma_extra_debug_sigprint();
|
max@0
|
5222
|
max@0
|
5223 return memptr();
|
max@0
|
5224 }
|
max@0
|
5225
|
max@0
|
5226
|
max@0
|
5227
|
max@0
|
5228 template<typename eT>
|
max@0
|
5229 inline
|
max@0
|
5230 typename Mat<eT>::iterator
|
max@0
|
5231 Mat<eT>::end()
|
max@0
|
5232 {
|
max@0
|
5233 arma_extra_debug_sigprint();
|
max@0
|
5234
|
max@0
|
5235 return memptr() + n_elem;
|
max@0
|
5236 }
|
max@0
|
5237
|
max@0
|
5238
|
max@0
|
5239
|
max@0
|
5240 template<typename eT>
|
max@0
|
5241 inline
|
max@0
|
5242 typename Mat<eT>::const_iterator
|
max@0
|
5243 Mat<eT>::end() const
|
max@0
|
5244 {
|
max@0
|
5245 arma_extra_debug_sigprint();
|
max@0
|
5246
|
max@0
|
5247 return memptr() + n_elem;
|
max@0
|
5248 }
|
max@0
|
5249
|
max@0
|
5250
|
max@0
|
5251
|
max@0
|
5252 template<typename eT>
|
max@0
|
5253 inline
|
max@0
|
5254 typename Mat<eT>::col_iterator
|
max@0
|
5255 Mat<eT>::begin_col(const uword col_num)
|
max@0
|
5256 {
|
max@0
|
5257 arma_extra_debug_sigprint();
|
max@0
|
5258
|
max@0
|
5259 arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds");
|
max@0
|
5260
|
max@0
|
5261 return colptr(col_num);
|
max@0
|
5262 }
|
max@0
|
5263
|
max@0
|
5264
|
max@0
|
5265
|
max@0
|
5266 template<typename eT>
|
max@0
|
5267 inline
|
max@0
|
5268 typename Mat<eT>::const_col_iterator
|
max@0
|
5269 Mat<eT>::begin_col(const uword col_num) const
|
max@0
|
5270 {
|
max@0
|
5271 arma_extra_debug_sigprint();
|
max@0
|
5272
|
max@0
|
5273 arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds");
|
max@0
|
5274
|
max@0
|
5275 return colptr(col_num);
|
max@0
|
5276 }
|
max@0
|
5277
|
max@0
|
5278
|
max@0
|
5279
|
max@0
|
5280 template<typename eT>
|
max@0
|
5281 inline
|
max@0
|
5282 typename Mat<eT>::col_iterator
|
max@0
|
5283 Mat<eT>::end_col(const uword col_num)
|
max@0
|
5284 {
|
max@0
|
5285 arma_extra_debug_sigprint();
|
max@0
|
5286
|
max@0
|
5287 arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds");
|
max@0
|
5288
|
max@0
|
5289 return colptr(col_num) + n_rows;
|
max@0
|
5290 }
|
max@0
|
5291
|
max@0
|
5292
|
max@0
|
5293
|
max@0
|
5294 template<typename eT>
|
max@0
|
5295 inline
|
max@0
|
5296 typename Mat<eT>::const_col_iterator
|
max@0
|
5297 Mat<eT>::end_col(const uword col_num) const
|
max@0
|
5298 {
|
max@0
|
5299 arma_extra_debug_sigprint();
|
max@0
|
5300
|
max@0
|
5301 arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds");
|
max@0
|
5302
|
max@0
|
5303 return colptr(col_num) + n_rows;
|
max@0
|
5304 }
|
max@0
|
5305
|
max@0
|
5306
|
max@0
|
5307
|
max@0
|
5308 template<typename eT>
|
max@0
|
5309 inline
|
max@0
|
5310 typename Mat<eT>::row_iterator
|
max@0
|
5311 Mat<eT>::begin_row(const uword row_num)
|
max@0
|
5312 {
|
max@0
|
5313 arma_extra_debug_sigprint();
|
max@0
|
5314
|
max@0
|
5315 arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" );
|
max@0
|
5316
|
max@0
|
5317 return typename Mat<eT>::row_iterator(*this, row_num);
|
max@0
|
5318 }
|
max@0
|
5319
|
max@0
|
5320
|
max@0
|
5321
|
max@0
|
5322 template<typename eT>
|
max@0
|
5323 inline
|
max@0
|
5324 typename Mat<eT>::const_row_iterator
|
max@0
|
5325 Mat<eT>::begin_row(const uword row_num) const
|
max@0
|
5326 {
|
max@0
|
5327 arma_extra_debug_sigprint();
|
max@0
|
5328
|
max@0
|
5329 arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" );
|
max@0
|
5330
|
max@0
|
5331 return typename Mat<eT>::const_row_iterator(*this, row_num);
|
max@0
|
5332 }
|
max@0
|
5333
|
max@0
|
5334
|
max@0
|
5335
|
max@0
|
5336 template<typename eT>
|
max@0
|
5337 inline
|
max@0
|
5338 typename Mat<eT>::row_iterator
|
max@0
|
5339 Mat<eT>::end_row(const uword row_num)
|
max@0
|
5340 {
|
max@0
|
5341 arma_extra_debug_sigprint();
|
max@0
|
5342
|
max@0
|
5343 arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" );
|
max@0
|
5344
|
max@0
|
5345 return typename Mat<eT>::row_iterator(*this, row_num + 1);
|
max@0
|
5346 }
|
max@0
|
5347
|
max@0
|
5348
|
max@0
|
5349
|
max@0
|
5350 template<typename eT>
|
max@0
|
5351 inline
|
max@0
|
5352 typename Mat<eT>::const_row_iterator
|
max@0
|
5353 Mat<eT>::end_row(const uword row_num) const
|
max@0
|
5354 {
|
max@0
|
5355 arma_extra_debug_sigprint();
|
max@0
|
5356
|
max@0
|
5357 arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" );
|
max@0
|
5358
|
max@0
|
5359 return typename Mat<eT>::const_row_iterator(*this, row_num + 1);
|
max@0
|
5360 }
|
max@0
|
5361
|
max@0
|
5362
|
max@0
|
5363
|
max@0
|
5364 //! resets this matrix to an empty matrix
|
max@0
|
5365 template<typename eT>
|
max@0
|
5366 inline
|
max@0
|
5367 void
|
max@0
|
5368 Mat<eT>::clear()
|
max@0
|
5369 {
|
max@0
|
5370 reset();
|
max@0
|
5371 }
|
max@0
|
5372
|
max@0
|
5373
|
max@0
|
5374
|
max@0
|
5375 //! returns true if the matrix has no elements
|
max@0
|
5376 template<typename eT>
|
max@0
|
5377 inline
|
max@0
|
5378 bool
|
max@0
|
5379 Mat<eT>::empty() const
|
max@0
|
5380 {
|
max@0
|
5381 return (n_elem == 0);
|
max@0
|
5382 }
|
max@0
|
5383
|
max@0
|
5384
|
max@0
|
5385
|
max@0
|
5386 //! returns the number of elements in this matrix
|
max@0
|
5387 template<typename eT>
|
max@0
|
5388 inline
|
max@0
|
5389 uword
|
max@0
|
5390 Mat<eT>::size() const
|
max@0
|
5391 {
|
max@0
|
5392 return n_elem;
|
max@0
|
5393 }
|
max@0
|
5394
|
max@0
|
5395
|
max@0
|
5396
|
max@0
|
5397 template<typename eT>
|
max@0
|
5398 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5399 arma_inline
|
max@0
|
5400 void
|
max@0
|
5401 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::mem_setup()
|
max@0
|
5402 {
|
max@0
|
5403 arma_extra_debug_sigprint();
|
max@0
|
5404
|
max@0
|
5405 access::rw(Mat<eT>::n_rows) = fixed_n_rows;
|
max@0
|
5406 access::rw(Mat<eT>::n_cols) = fixed_n_cols;
|
max@0
|
5407 access::rw(Mat<eT>::n_elem) = fixed_n_elem;
|
max@0
|
5408 access::rw(Mat<eT>::vec_state) = 0;
|
max@0
|
5409 access::rw(Mat<eT>::mem_state) = 3;
|
max@0
|
5410 access::rw(Mat<eT>::mem) = (use_extra) ? mem_local_extra : mem_local;
|
max@0
|
5411 }
|
max@0
|
5412
|
max@0
|
5413
|
max@0
|
5414
|
max@0
|
5415 template<typename eT>
|
max@0
|
5416 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5417 arma_inline
|
max@0
|
5418 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed()
|
max@0
|
5419 {
|
max@0
|
5420 arma_extra_debug_sigprint_this(this);
|
max@0
|
5421
|
max@0
|
5422 mem_setup();
|
max@0
|
5423 }
|
max@0
|
5424
|
max@0
|
5425
|
max@0
|
5426
|
max@0
|
5427 template<typename eT>
|
max@0
|
5428 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5429 arma_inline
|
max@0
|
5430 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const fixed<fixed_n_rows, fixed_n_cols>& X)
|
max@0
|
5431 {
|
max@0
|
5432 arma_extra_debug_sigprint_this(this);
|
max@0
|
5433
|
max@0
|
5434 mem_setup();
|
max@0
|
5435
|
max@0
|
5436 eT* dest = (use_extra) ? mem_local_extra : mem_local;
|
max@0
|
5437
|
max@0
|
5438 arrayops::copy( dest, X.mem, fixed_n_elem );
|
max@0
|
5439 }
|
max@0
|
5440
|
max@0
|
5441
|
max@0
|
5442
|
max@0
|
5443 template<typename eT>
|
max@0
|
5444 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5445 template<typename T1>
|
max@0
|
5446 inline
|
max@0
|
5447 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const Base<eT,T1>& A)
|
max@0
|
5448 {
|
max@0
|
5449 arma_extra_debug_sigprint_this(this);
|
max@0
|
5450
|
max@0
|
5451 mem_setup();
|
max@0
|
5452
|
max@0
|
5453 Mat<eT>::operator=(A.get_ref());
|
max@0
|
5454 }
|
max@0
|
5455
|
max@0
|
5456
|
max@0
|
5457
|
max@0
|
5458 template<typename eT>
|
max@0
|
5459 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5460 template<typename T1, typename T2>
|
max@0
|
5461 inline
|
max@0
|
5462 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B)
|
max@0
|
5463 {
|
max@0
|
5464 arma_extra_debug_sigprint_this(this);
|
max@0
|
5465
|
max@0
|
5466 mem_setup();
|
max@0
|
5467
|
max@0
|
5468 Mat<eT>::init(A,B);
|
max@0
|
5469 }
|
max@0
|
5470
|
max@0
|
5471
|
max@0
|
5472
|
max@0
|
5473 template<typename eT>
|
max@0
|
5474 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5475 inline
|
max@0
|
5476 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(eT* aux_mem, const bool copy_aux_mem)
|
max@0
|
5477 {
|
max@0
|
5478 arma_extra_debug_sigprint_this(this);
|
max@0
|
5479
|
max@0
|
5480 access::rw(Mat<eT>::n_rows) = fixed_n_rows;
|
max@0
|
5481 access::rw(Mat<eT>::n_cols) = fixed_n_cols;
|
max@0
|
5482 access::rw(Mat<eT>::n_elem) = fixed_n_elem;
|
max@0
|
5483 access::rw(Mat<eT>::vec_state) = 0;
|
max@0
|
5484 access::rw(Mat<eT>::mem_state) = 3;
|
max@0
|
5485
|
max@0
|
5486 if(copy_aux_mem == true)
|
max@0
|
5487 {
|
max@0
|
5488 eT* dest = (use_extra) ? mem_local_extra : mem_local;
|
max@0
|
5489
|
max@0
|
5490 access::rw(Mat<eT>::mem) = dest;
|
max@0
|
5491
|
max@0
|
5492 arrayops::copy( dest, aux_mem, fixed_n_elem );
|
max@0
|
5493 }
|
max@0
|
5494 else
|
max@0
|
5495 {
|
max@0
|
5496 access::rw(Mat<eT>::mem) = aux_mem;
|
max@0
|
5497 }
|
max@0
|
5498 }
|
max@0
|
5499
|
max@0
|
5500
|
max@0
|
5501
|
max@0
|
5502 template<typename eT>
|
max@0
|
5503 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5504 inline
|
max@0
|
5505 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const eT* aux_mem)
|
max@0
|
5506 {
|
max@0
|
5507 arma_extra_debug_sigprint_this(this);
|
max@0
|
5508
|
max@0
|
5509 mem_setup();
|
max@0
|
5510
|
max@0
|
5511 arrayops::copy( const_cast<eT*>(Mat<eT>::mem), aux_mem, fixed_n_elem );
|
max@0
|
5512 }
|
max@0
|
5513
|
max@0
|
5514
|
max@0
|
5515
|
max@0
|
5516 template<typename eT>
|
max@0
|
5517 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5518 inline
|
max@0
|
5519 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const char* text)
|
max@0
|
5520 {
|
max@0
|
5521 arma_extra_debug_sigprint_this(this);
|
max@0
|
5522
|
max@0
|
5523 mem_setup();
|
max@0
|
5524
|
max@0
|
5525 Mat<eT>::operator=(text);
|
max@0
|
5526 }
|
max@0
|
5527
|
max@0
|
5528
|
max@0
|
5529
|
max@0
|
5530 template<typename eT>
|
max@0
|
5531 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5532 inline
|
max@0
|
5533 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const std::string& text)
|
max@0
|
5534 {
|
max@0
|
5535 arma_extra_debug_sigprint_this(this);
|
max@0
|
5536
|
max@0
|
5537 mem_setup();
|
max@0
|
5538
|
max@0
|
5539 Mat<eT>::operator=(text);
|
max@0
|
5540 }
|
max@0
|
5541
|
max@0
|
5542
|
max@0
|
5543
|
max@0
|
5544 template<typename eT>
|
max@0
|
5545 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5546 template<typename T1>
|
max@0
|
5547 inline
|
max@0
|
5548 const Mat<eT>&
|
max@0
|
5549 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const Base<eT,T1>& A)
|
max@0
|
5550 {
|
max@0
|
5551 Mat<eT>::operator=(A.get_ref());
|
max@0
|
5552
|
max@0
|
5553 return *this;
|
max@0
|
5554 }
|
max@0
|
5555
|
max@0
|
5556
|
max@0
|
5557
|
max@0
|
5558 template<typename eT>
|
max@0
|
5559 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5560 inline
|
max@0
|
5561 const Mat<eT>&
|
max@0
|
5562 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const eT val)
|
max@0
|
5563 {
|
max@0
|
5564 arma_extra_debug_sigprint();
|
max@0
|
5565
|
max@0
|
5566 Mat<eT>::operator=(val);
|
max@0
|
5567
|
max@0
|
5568 return *this;
|
max@0
|
5569 }
|
max@0
|
5570
|
max@0
|
5571
|
max@0
|
5572
|
max@0
|
5573 template<typename eT>
|
max@0
|
5574 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5575 inline
|
max@0
|
5576 const Mat<eT>&
|
max@0
|
5577 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const char* text)
|
max@0
|
5578 {
|
max@0
|
5579 arma_extra_debug_sigprint();
|
max@0
|
5580
|
max@0
|
5581 Mat<eT>::operator=(text);
|
max@0
|
5582
|
max@0
|
5583 return *this;
|
max@0
|
5584 }
|
max@0
|
5585
|
max@0
|
5586
|
max@0
|
5587
|
max@0
|
5588 template<typename eT>
|
max@0
|
5589 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5590 inline
|
max@0
|
5591 const Mat<eT>&
|
max@0
|
5592 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const std::string& text)
|
max@0
|
5593 {
|
max@0
|
5594 arma_extra_debug_sigprint();
|
max@0
|
5595
|
max@0
|
5596 Mat<eT>::operator=(text);
|
max@0
|
5597
|
max@0
|
5598 return *this;
|
max@0
|
5599 }
|
max@0
|
5600
|
max@0
|
5601
|
max@0
|
5602
|
max@0
|
5603 template<typename eT>
|
max@0
|
5604 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5605 inline
|
max@0
|
5606 subview_row<eT>
|
max@0
|
5607 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const uword row_num, const span& col_span)
|
max@0
|
5608 {
|
max@0
|
5609 arma_extra_debug_sigprint();
|
max@0
|
5610
|
max@0
|
5611 return Mat<eT>::operator()(row_num, col_span);
|
max@0
|
5612 }
|
max@0
|
5613
|
max@0
|
5614
|
max@0
|
5615
|
max@0
|
5616 template<typename eT>
|
max@0
|
5617 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5618 inline
|
max@0
|
5619 const subview_row<eT>
|
max@0
|
5620 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const uword row_num, const span& col_span) const
|
max@0
|
5621 {
|
max@0
|
5622 arma_extra_debug_sigprint();
|
max@0
|
5623
|
max@0
|
5624 return Mat<eT>::operator()(row_num, col_span);
|
max@0
|
5625 }
|
max@0
|
5626
|
max@0
|
5627
|
max@0
|
5628
|
max@0
|
5629 template<typename eT>
|
max@0
|
5630 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5631 inline
|
max@0
|
5632 subview_col<eT>
|
max@0
|
5633 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span, const uword col_num)
|
max@0
|
5634 {
|
max@0
|
5635 arma_extra_debug_sigprint();
|
max@0
|
5636
|
max@0
|
5637 return Mat<eT>::operator()(row_span, col_num);
|
max@0
|
5638 }
|
max@0
|
5639
|
max@0
|
5640
|
max@0
|
5641
|
max@0
|
5642 template<typename eT>
|
max@0
|
5643 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5644 inline
|
max@0
|
5645 const subview_col<eT>
|
max@0
|
5646 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span, const uword col_num) const
|
max@0
|
5647 {
|
max@0
|
5648 arma_extra_debug_sigprint();
|
max@0
|
5649
|
max@0
|
5650 return Mat<eT>::operator()(row_span, col_num);
|
max@0
|
5651 }
|
max@0
|
5652
|
max@0
|
5653
|
max@0
|
5654
|
max@0
|
5655 template<typename eT>
|
max@0
|
5656 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5657 inline
|
max@0
|
5658 subview<eT>
|
max@0
|
5659 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span, const span& col_span)
|
max@0
|
5660 {
|
max@0
|
5661 arma_extra_debug_sigprint();
|
max@0
|
5662
|
max@0
|
5663 return Mat<eT>::operator()(row_span, col_span);
|
max@0
|
5664 }
|
max@0
|
5665
|
max@0
|
5666
|
max@0
|
5667
|
max@0
|
5668 template<typename eT>
|
max@0
|
5669 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5670 inline
|
max@0
|
5671 const subview<eT>
|
max@0
|
5672 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span, const span& col_span) const
|
max@0
|
5673 {
|
max@0
|
5674 arma_extra_debug_sigprint();
|
max@0
|
5675
|
max@0
|
5676 return Mat<eT>::operator()(row_span, col_span);
|
max@0
|
5677 }
|
max@0
|
5678
|
max@0
|
5679
|
max@0
|
5680
|
max@0
|
5681 template<typename eT>
|
max@0
|
5682 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5683 arma_inline
|
max@0
|
5684 arma_warn_unused
|
max@0
|
5685 eT&
|
max@0
|
5686 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword i)
|
max@0
|
5687 {
|
max@0
|
5688 return access::rw( Mat<eT>::mem[i] );
|
max@0
|
5689 }
|
max@0
|
5690
|
max@0
|
5691
|
max@0
|
5692
|
max@0
|
5693 template<typename eT>
|
max@0
|
5694 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5695 arma_inline
|
max@0
|
5696 arma_warn_unused
|
max@0
|
5697 eT
|
max@0
|
5698 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword i) const
|
max@0
|
5699 {
|
max@0
|
5700 return ( Mat<eT>::mem[i] );
|
max@0
|
5701 }
|
max@0
|
5702
|
max@0
|
5703
|
max@0
|
5704
|
max@0
|
5705 template<typename eT>
|
max@0
|
5706 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5707 arma_inline
|
max@0
|
5708 arma_warn_unused
|
max@0
|
5709 eT&
|
max@0
|
5710 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword i)
|
max@0
|
5711 {
|
max@0
|
5712 return access::rw( Mat<eT>::mem[i] );
|
max@0
|
5713 }
|
max@0
|
5714
|
max@0
|
5715
|
max@0
|
5716
|
max@0
|
5717 template<typename eT>
|
max@0
|
5718 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5719 arma_inline
|
max@0
|
5720 arma_warn_unused
|
max@0
|
5721 eT
|
max@0
|
5722 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword i) const
|
max@0
|
5723 {
|
max@0
|
5724 return ( Mat<eT>::mem[i] );
|
max@0
|
5725 }
|
max@0
|
5726
|
max@0
|
5727
|
max@0
|
5728
|
max@0
|
5729 template<typename eT>
|
max@0
|
5730 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5731 arma_inline
|
max@0
|
5732 arma_warn_unused
|
max@0
|
5733 eT&
|
max@0
|
5734 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword i)
|
max@0
|
5735 {
|
max@0
|
5736 arma_debug_check( (i >= fixed_n_elem), "Mat::fixed::operator(): out of bounds");
|
max@0
|
5737
|
max@0
|
5738 return access::rw( Mat<eT>::mem[i] );
|
max@0
|
5739 }
|
max@0
|
5740
|
max@0
|
5741
|
max@0
|
5742
|
max@0
|
5743 template<typename eT>
|
max@0
|
5744 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5745 arma_inline
|
max@0
|
5746 arma_warn_unused
|
max@0
|
5747 eT
|
max@0
|
5748 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword i) const
|
max@0
|
5749 {
|
max@0
|
5750 arma_debug_check( (i >= fixed_n_elem), "Mat::fixed::operator(): out of bounds");
|
max@0
|
5751
|
max@0
|
5752 return ( Mat<eT>::mem[i] );
|
max@0
|
5753 }
|
max@0
|
5754
|
max@0
|
5755
|
max@0
|
5756
|
max@0
|
5757 template<typename eT>
|
max@0
|
5758 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5759 arma_inline
|
max@0
|
5760 arma_warn_unused
|
max@0
|
5761 eT&
|
max@0
|
5762 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uword in_col)
|
max@0
|
5763 {
|
max@0
|
5764 const uword i = in_row + in_col*fixed_n_rows;
|
max@0
|
5765
|
max@0
|
5766 return access::rw( Mat<eT>::mem[i] );
|
max@0
|
5767 }
|
max@0
|
5768
|
max@0
|
5769
|
max@0
|
5770
|
max@0
|
5771 template<typename eT>
|
max@0
|
5772 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5773 arma_inline
|
max@0
|
5774 arma_warn_unused
|
max@0
|
5775 eT
|
max@0
|
5776 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uword in_col) const
|
max@0
|
5777 {
|
max@0
|
5778 const uword i = in_row + in_col*fixed_n_rows;
|
max@0
|
5779
|
max@0
|
5780 return ( Mat<eT>::mem[i] );
|
max@0
|
5781 }
|
max@0
|
5782
|
max@0
|
5783
|
max@0
|
5784
|
max@0
|
5785 template<typename eT>
|
max@0
|
5786 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5787 arma_inline
|
max@0
|
5788 arma_warn_unused
|
max@0
|
5789 eT&
|
max@0
|
5790 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row, const uword in_col)
|
max@0
|
5791 {
|
max@0
|
5792 arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::fixed::operator(): out of bounds");
|
max@0
|
5793
|
max@0
|
5794 const uword i = in_row + in_col*fixed_n_rows;
|
max@0
|
5795
|
max@0
|
5796 return access::rw( Mat<eT>::mem[i] );
|
max@0
|
5797 }
|
max@0
|
5798
|
max@0
|
5799
|
max@0
|
5800
|
max@0
|
5801 template<typename eT>
|
max@0
|
5802 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5803 arma_inline
|
max@0
|
5804 arma_warn_unused
|
max@0
|
5805 eT
|
max@0
|
5806 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row, const uword in_col) const
|
max@0
|
5807 {
|
max@0
|
5808 arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::fixed::operator(): out of bounds");
|
max@0
|
5809
|
max@0
|
5810 const uword i = in_row + in_col*fixed_n_rows;
|
max@0
|
5811
|
max@0
|
5812 return ( Mat<eT>::mem[i] );
|
max@0
|
5813 }
|
max@0
|
5814
|
max@0
|
5815
|
max@0
|
5816
|
max@0
|
5817 template<typename eT>
|
max@0
|
5818 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5819 arma_hot
|
max@0
|
5820 inline
|
max@0
|
5821 const Mat<eT>&
|
max@0
|
5822 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fill(const eT val)
|
max@0
|
5823 {
|
max@0
|
5824 arma_extra_debug_sigprint();
|
max@0
|
5825
|
max@0
|
5826 arrayops::inplace_set( const_cast<eT*>(Mat<eT>::mem), val, fixed_n_elem );
|
max@0
|
5827
|
max@0
|
5828 return *this;
|
max@0
|
5829 }
|
max@0
|
5830
|
max@0
|
5831
|
max@0
|
5832
|
max@0
|
5833 template<typename eT>
|
max@0
|
5834 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5835 arma_hot
|
max@0
|
5836 inline
|
max@0
|
5837 const Mat<eT>&
|
max@0
|
5838 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::zeros()
|
max@0
|
5839 {
|
max@0
|
5840 arma_extra_debug_sigprint();
|
max@0
|
5841
|
max@0
|
5842 arrayops::inplace_set( const_cast<eT*>(Mat<eT>::mem), eT(0), fixed_n_elem );
|
max@0
|
5843
|
max@0
|
5844 return *this;
|
max@0
|
5845 }
|
max@0
|
5846
|
max@0
|
5847
|
max@0
|
5848
|
max@0
|
5849 template<typename eT>
|
max@0
|
5850 template<uword fixed_n_rows, uword fixed_n_cols>
|
max@0
|
5851 arma_hot
|
max@0
|
5852 inline
|
max@0
|
5853 const Mat<eT>&
|
max@0
|
5854 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::ones()
|
max@0
|
5855 {
|
max@0
|
5856 arma_extra_debug_sigprint();
|
max@0
|
5857
|
max@0
|
5858 arrayops::inplace_set( const_cast<eT*>(Mat<eT>::mem), eT(1), fixed_n_elem );
|
max@0
|
5859
|
max@0
|
5860 return *this;
|
max@0
|
5861 }
|
max@0
|
5862
|
max@0
|
5863
|
max@0
|
5864
|
max@0
|
5865 //! prefix ++
|
max@0
|
5866 template<typename eT>
|
max@0
|
5867 arma_inline
|
max@0
|
5868 void
|
max@0
|
5869 Mat_aux::prefix_pp(Mat<eT>& x)
|
max@0
|
5870 {
|
max@0
|
5871 eT* memptr = x.memptr();
|
max@0
|
5872 const uword n_elem = x.n_elem;
|
max@0
|
5873
|
max@0
|
5874 uword i,j;
|
max@0
|
5875
|
max@0
|
5876 for(i=0, j=1; j<n_elem; i+=2, j+=2)
|
max@0
|
5877 {
|
max@0
|
5878 ++(memptr[i]);
|
max@0
|
5879 ++(memptr[j]);
|
max@0
|
5880 }
|
max@0
|
5881
|
max@0
|
5882 if(i < n_elem)
|
max@0
|
5883 {
|
max@0
|
5884 ++(memptr[i]);
|
max@0
|
5885 }
|
max@0
|
5886 }
|
max@0
|
5887
|
max@0
|
5888
|
max@0
|
5889
|
max@0
|
5890 //! prefix ++ for complex numbers (work around for limitations of the std::complex class)
|
max@0
|
5891 template<typename T>
|
max@0
|
5892 arma_inline
|
max@0
|
5893 void
|
max@0
|
5894 Mat_aux::prefix_pp(Mat< std::complex<T> >& x)
|
max@0
|
5895 {
|
max@0
|
5896 x += T(1);
|
max@0
|
5897 }
|
max@0
|
5898
|
max@0
|
5899
|
max@0
|
5900
|
max@0
|
5901 //! postfix ++
|
max@0
|
5902 template<typename eT>
|
max@0
|
5903 arma_inline
|
max@0
|
5904 void
|
max@0
|
5905 Mat_aux::postfix_pp(Mat<eT>& x)
|
max@0
|
5906 {
|
max@0
|
5907 eT* memptr = x.memptr();
|
max@0
|
5908 const uword n_elem = x.n_elem;
|
max@0
|
5909
|
max@0
|
5910 uword i,j;
|
max@0
|
5911
|
max@0
|
5912 for(i=0, j=1; j<n_elem; i+=2, j+=2)
|
max@0
|
5913 {
|
max@0
|
5914 (memptr[i])++;
|
max@0
|
5915 (memptr[j])++;
|
max@0
|
5916 }
|
max@0
|
5917
|
max@0
|
5918 if(i < n_elem)
|
max@0
|
5919 {
|
max@0
|
5920 (memptr[i])++;
|
max@0
|
5921 }
|
max@0
|
5922 }
|
max@0
|
5923
|
max@0
|
5924
|
max@0
|
5925
|
max@0
|
5926 //! postfix ++ for complex numbers (work around for limitations of the std::complex class)
|
max@0
|
5927 template<typename T>
|
max@0
|
5928 arma_inline
|
max@0
|
5929 void
|
max@0
|
5930 Mat_aux::postfix_pp(Mat< std::complex<T> >& x)
|
max@0
|
5931 {
|
max@0
|
5932 x += T(1);
|
max@0
|
5933 }
|
max@0
|
5934
|
max@0
|
5935
|
max@0
|
5936
|
max@0
|
5937 //! prefix --
|
max@0
|
5938 template<typename eT>
|
max@0
|
5939 arma_inline
|
max@0
|
5940 void
|
max@0
|
5941 Mat_aux::prefix_mm(Mat<eT>& x)
|
max@0
|
5942 {
|
max@0
|
5943 eT* memptr = x.memptr();
|
max@0
|
5944 const uword n_elem = x.n_elem;
|
max@0
|
5945
|
max@0
|
5946 uword i,j;
|
max@0
|
5947
|
max@0
|
5948 for(i=0, j=1; j<n_elem; i+=2, j+=2)
|
max@0
|
5949 {
|
max@0
|
5950 --(memptr[i]);
|
max@0
|
5951 --(memptr[j]);
|
max@0
|
5952 }
|
max@0
|
5953
|
max@0
|
5954 if(i < n_elem)
|
max@0
|
5955 {
|
max@0
|
5956 --(memptr[i]);
|
max@0
|
5957 }
|
max@0
|
5958 }
|
max@0
|
5959
|
max@0
|
5960
|
max@0
|
5961
|
max@0
|
5962 //! prefix -- for complex numbers (work around for limitations of the std::complex class)
|
max@0
|
5963 template<typename T>
|
max@0
|
5964 arma_inline
|
max@0
|
5965 void
|
max@0
|
5966 Mat_aux::prefix_mm(Mat< std::complex<T> >& x)
|
max@0
|
5967 {
|
max@0
|
5968 x -= T(1);
|
max@0
|
5969 }
|
max@0
|
5970
|
max@0
|
5971
|
max@0
|
5972
|
max@0
|
5973 //! postfix --
|
max@0
|
5974 template<typename eT>
|
max@0
|
5975 arma_inline
|
max@0
|
5976 void
|
max@0
|
5977 Mat_aux::postfix_mm(Mat<eT>& x)
|
max@0
|
5978 {
|
max@0
|
5979 eT* memptr = x.memptr();
|
max@0
|
5980 const uword n_elem = x.n_elem;
|
max@0
|
5981
|
max@0
|
5982 uword i,j;
|
max@0
|
5983
|
max@0
|
5984 for(i=0, j=1; j<n_elem; i+=2, j+=2)
|
max@0
|
5985 {
|
max@0
|
5986 (memptr[i])--;
|
max@0
|
5987 (memptr[j])--;
|
max@0
|
5988 }
|
max@0
|
5989
|
max@0
|
5990 if(i < n_elem)
|
max@0
|
5991 {
|
max@0
|
5992 (memptr[i])--;
|
max@0
|
5993 }
|
max@0
|
5994 }
|
max@0
|
5995
|
max@0
|
5996
|
max@0
|
5997
|
max@0
|
5998 //! postfix ++ for complex numbers (work around for limitations of the std::complex class)
|
max@0
|
5999 template<typename T>
|
max@0
|
6000 arma_inline
|
max@0
|
6001 void
|
max@0
|
6002 Mat_aux::postfix_mm(Mat< std::complex<T> >& x)
|
max@0
|
6003 {
|
max@0
|
6004 x -= T(1);
|
max@0
|
6005 }
|
max@0
|
6006
|
max@0
|
6007
|
max@0
|
6008
|
max@0
|
6009 template<typename eT, typename T1>
|
max@0
|
6010 inline
|
max@0
|
6011 void
|
max@0
|
6012 Mat_aux::set_real(Mat<eT>& out, const Base<eT,T1>& X)
|
max@0
|
6013 {
|
max@0
|
6014 arma_extra_debug_sigprint();
|
max@0
|
6015
|
max@0
|
6016 const unwrap<T1> tmp(X.get_ref());
|
max@0
|
6017 const Mat<eT>& A = tmp.M;
|
max@0
|
6018
|
max@0
|
6019 arma_debug_assert_same_size( out, A, "Mat::set_real()" );
|
max@0
|
6020
|
max@0
|
6021 out = A;
|
max@0
|
6022 }
|
max@0
|
6023
|
max@0
|
6024
|
max@0
|
6025
|
max@0
|
6026 template<typename eT, typename T1>
|
max@0
|
6027 inline
|
max@0
|
6028 void
|
max@0
|
6029 Mat_aux::set_imag(Mat<eT>& out, const Base<eT,T1>& X)
|
max@0
|
6030 {
|
max@0
|
6031 arma_extra_debug_sigprint();
|
max@0
|
6032 }
|
max@0
|
6033
|
max@0
|
6034
|
max@0
|
6035
|
max@0
|
6036 template<typename T, typename T1>
|
max@0
|
6037 inline
|
max@0
|
6038 void
|
max@0
|
6039 Mat_aux::set_real(Mat< std::complex<T> >& out, const Base<T,T1>& X)
|
max@0
|
6040 {
|
max@0
|
6041 arma_extra_debug_sigprint();
|
max@0
|
6042
|
max@0
|
6043 typedef typename std::complex<T> eT;
|
max@0
|
6044 typedef typename Proxy<T1>::ea_type ea_type;
|
max@0
|
6045
|
max@0
|
6046 const Proxy<T1> A(X.get_ref());
|
max@0
|
6047
|
max@0
|
6048 arma_debug_assert_same_size( out, A, "Mat::set_real()" );
|
max@0
|
6049
|
max@0
|
6050 const uword n_elem = out.n_elem;
|
max@0
|
6051 eT* out_mem = out.memptr();
|
max@0
|
6052 ea_type PA = A.get_ea();
|
max@0
|
6053
|
max@0
|
6054 for(uword i=0; i<n_elem; ++i)
|
max@0
|
6055 {
|
max@0
|
6056 //out_mem[i].real() = PA[i];
|
max@0
|
6057 out_mem[i] = std::complex<T>( PA[i], out_mem[i].imag() );
|
max@0
|
6058 }
|
max@0
|
6059 }
|
max@0
|
6060
|
max@0
|
6061
|
max@0
|
6062
|
max@0
|
6063 template<typename T, typename T1>
|
max@0
|
6064 inline
|
max@0
|
6065 void
|
max@0
|
6066 Mat_aux::set_imag(Mat< std::complex<T> >& out, const Base<T,T1>& X)
|
max@0
|
6067 {
|
max@0
|
6068 arma_extra_debug_sigprint();
|
max@0
|
6069
|
max@0
|
6070 typedef typename std::complex<T> eT;
|
max@0
|
6071 typedef typename Proxy<T1>::ea_type ea_type;
|
max@0
|
6072
|
max@0
|
6073 const Proxy<T1> A(X.get_ref());
|
max@0
|
6074
|
max@0
|
6075 arma_debug_assert_same_size( out, A, "Mat::set_imag()" );
|
max@0
|
6076
|
max@0
|
6077 const uword n_elem = out.n_elem;
|
max@0
|
6078 eT* out_mem = out.memptr();
|
max@0
|
6079 ea_type PA = A.get_ea();
|
max@0
|
6080
|
max@0
|
6081 for(uword i=0; i<n_elem; ++i)
|
max@0
|
6082 {
|
max@0
|
6083 //out_mem[i].imag() = PA[i];
|
max@0
|
6084 out_mem[i] = std::complex<T>( out_mem[i].real(), PA[i] );
|
max@0
|
6085 }
|
max@0
|
6086 }
|
max@0
|
6087
|
max@0
|
6088
|
max@0
|
6089
|
max@0
|
6090 #ifdef ARMA_EXTRA_MAT_MEAT
|
max@0
|
6091 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT)
|
max@0
|
6092 #endif
|
max@0
|
6093
|
max@0
|
6094
|
max@0
|
6095
|
max@0
|
6096 //! @}
|