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 Cube
|
max@0
|
15 //! @{
|
max@0
|
16
|
max@0
|
17
|
max@0
|
18 template<typename eT>
|
max@0
|
19 inline
|
max@0
|
20 Cube<eT>::~Cube()
|
max@0
|
21 {
|
max@0
|
22 arma_extra_debug_sigprint_this(this);
|
max@0
|
23
|
max@0
|
24 delete_mat();
|
max@0
|
25
|
max@0
|
26 if(mem_state == 0)
|
max@0
|
27 {
|
max@0
|
28 if(n_elem > Cube_prealloc::mem_n_elem)
|
max@0
|
29 {
|
max@0
|
30 #if defined(ARMA_USE_TBB_ALLOC)
|
max@0
|
31 scalable_free((void *)(mem));
|
max@0
|
32 #else
|
max@0
|
33 delete [] mem;
|
max@0
|
34 #endif
|
max@0
|
35 }
|
max@0
|
36 }
|
max@0
|
37
|
max@0
|
38 if(arma_config::debug == true)
|
max@0
|
39 {
|
max@0
|
40 // try to expose buggy user code that accesses deleted objects
|
max@0
|
41 access::rw(n_rows) = 0;
|
max@0
|
42 access::rw(n_cols) = 0;
|
max@0
|
43 access::rw(n_slices) = 0;
|
max@0
|
44 access::rw(n_elem) = 0;
|
max@0
|
45 access::rw(mat_ptrs) = 0;
|
max@0
|
46 access::rw(mem) = 0;
|
max@0
|
47 }
|
max@0
|
48
|
max@0
|
49 arma_type_check(( is_supported_elem_type<eT>::value == false ));
|
max@0
|
50 }
|
max@0
|
51
|
max@0
|
52
|
max@0
|
53
|
max@0
|
54 template<typename eT>
|
max@0
|
55 inline
|
max@0
|
56 Cube<eT>::Cube()
|
max@0
|
57 : n_rows(0)
|
max@0
|
58 , n_cols(0)
|
max@0
|
59 , n_elem_slice(0)
|
max@0
|
60 , n_slices(0)
|
max@0
|
61 , n_elem(0)
|
max@0
|
62 , mem_state(0)
|
max@0
|
63 , mat_ptrs()
|
max@0
|
64 , mem()
|
max@0
|
65 {
|
max@0
|
66 arma_extra_debug_sigprint_this(this);
|
max@0
|
67 }
|
max@0
|
68
|
max@0
|
69
|
max@0
|
70
|
max@0
|
71 //! construct the cube to have user specified dimensions
|
max@0
|
72 template<typename eT>
|
max@0
|
73 inline
|
max@0
|
74 Cube<eT>::Cube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
|
max@0
|
75 : n_rows(in_n_rows)
|
max@0
|
76 , n_cols(in_n_cols)
|
max@0
|
77 , n_elem_slice(in_n_rows*in_n_cols)
|
max@0
|
78 , n_slices(in_n_slices)
|
max@0
|
79 , n_elem(in_n_rows*in_n_cols*in_n_slices)
|
max@0
|
80 , mem_state(0)
|
max@0
|
81 , mat_ptrs()
|
max@0
|
82 , mem()
|
max@0
|
83 {
|
max@0
|
84 arma_extra_debug_sigprint_this(this);
|
max@0
|
85
|
max@0
|
86 init_cold();
|
max@0
|
87 }
|
max@0
|
88
|
max@0
|
89
|
max@0
|
90
|
max@0
|
91 template<typename eT>
|
max@0
|
92 inline
|
max@0
|
93 void
|
max@0
|
94 Cube<eT>::init_cold()
|
max@0
|
95 {
|
max@0
|
96 arma_extra_debug_sigprint( arma_boost::format("n_rows = %d, n_cols = %d, n_slices = %d") % n_rows % n_cols % n_slices );
|
max@0
|
97
|
max@0
|
98 arma_debug_check
|
max@0
|
99 (
|
max@0
|
100 (
|
max@0
|
101 ( (n_rows > 0x0FFF) || (n_cols > 0x0FFF) || (n_slices > 0xFF) )
|
max@0
|
102 ? ( (float(n_rows) * float(n_cols) * float(n_slices)) > float(ARMA_MAX_UWORD) )
|
max@0
|
103 : false
|
max@0
|
104 ),
|
max@0
|
105 "Cube::init(): requested size is too large"
|
max@0
|
106 );
|
max@0
|
107
|
max@0
|
108 if(n_elem <= Cube_prealloc::mem_n_elem)
|
max@0
|
109 {
|
max@0
|
110 access::rw(mem) = mem_local;
|
max@0
|
111 }
|
max@0
|
112 else
|
max@0
|
113 {
|
max@0
|
114 arma_extra_debug_print("Cube::init(): allocating memory");
|
max@0
|
115
|
max@0
|
116 #if defined(ARMA_USE_TBB_ALLOC)
|
max@0
|
117 access::rw(mem) = (eT *)scalable_malloc(sizeof(eT)*n_elem);
|
max@0
|
118 #else
|
max@0
|
119 access::rw(mem) = new(std::nothrow) eT[n_elem];
|
max@0
|
120 #endif
|
max@0
|
121
|
max@0
|
122 arma_check_bad_alloc( (mem == 0), "Cube::init(): out of memory" );
|
max@0
|
123 }
|
max@0
|
124
|
max@0
|
125
|
max@0
|
126 if(n_elem == 0)
|
max@0
|
127 {
|
max@0
|
128 access::rw(n_rows) = 0;
|
max@0
|
129 access::rw(n_cols) = 0;
|
max@0
|
130 access::rw(n_elem_slice) = 0;
|
max@0
|
131 access::rw(n_slices) = 0;
|
max@0
|
132 }
|
max@0
|
133 else
|
max@0
|
134 {
|
max@0
|
135 create_mat();
|
max@0
|
136 }
|
max@0
|
137 }
|
max@0
|
138
|
max@0
|
139
|
max@0
|
140
|
max@0
|
141 //! internal cube construction; if the requested size is small enough, memory from the stack is used.
|
max@0
|
142 //! otherwise memory is allocated via 'new'
|
max@0
|
143 template<typename eT>
|
max@0
|
144 inline
|
max@0
|
145 void
|
max@0
|
146 Cube<eT>::init_warm(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
|
max@0
|
147 {
|
max@0
|
148 arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols = %d, in_n_slices = %d") % in_n_rows % in_n_cols % in_n_slices );
|
max@0
|
149
|
max@0
|
150 if( (n_rows == in_n_rows) && (n_cols == in_n_cols) && (n_slices == in_n_slices) )
|
max@0
|
151 {
|
max@0
|
152 return;
|
max@0
|
153 }
|
max@0
|
154
|
max@0
|
155 const uword t_mem_state = mem_state;
|
max@0
|
156
|
max@0
|
157 bool err_state = false;
|
max@0
|
158 char* err_msg = 0;
|
max@0
|
159
|
max@0
|
160 arma_debug_set_error
|
max@0
|
161 (
|
max@0
|
162 err_state,
|
max@0
|
163 err_msg,
|
max@0
|
164 (t_mem_state == 3),
|
max@0
|
165 "Cube::init(): size is fixed and hence cannot be changed"
|
max@0
|
166 );
|
max@0
|
167
|
max@0
|
168 arma_debug_set_error
|
max@0
|
169 (
|
max@0
|
170 err_state,
|
max@0
|
171 err_msg,
|
max@0
|
172 (
|
max@0
|
173 ( (in_n_rows > 0x0FFF) || (in_n_cols > 0x0FFF) || (in_n_slices > 0xFF) )
|
max@0
|
174 ? ( (float(in_n_rows) * float(in_n_cols) * float(in_n_slices)) > float(ARMA_MAX_UWORD) )
|
max@0
|
175 : false
|
max@0
|
176 ),
|
max@0
|
177 "Cube::init(): requested size is too large"
|
max@0
|
178 );
|
max@0
|
179
|
max@0
|
180 arma_debug_check(err_state, err_msg);
|
max@0
|
181
|
max@0
|
182 const uword old_n_elem = n_elem;
|
max@0
|
183 const uword new_n_elem = in_n_rows * in_n_cols * in_n_slices;
|
max@0
|
184
|
max@0
|
185 if(old_n_elem == new_n_elem)
|
max@0
|
186 {
|
max@0
|
187 delete_mat();
|
max@0
|
188
|
max@0
|
189 if(new_n_elem > 0)
|
max@0
|
190 {
|
max@0
|
191 access::rw(n_rows) = in_n_rows;
|
max@0
|
192 access::rw(n_cols) = in_n_cols;
|
max@0
|
193 access::rw(n_elem_slice) = in_n_rows*in_n_cols;
|
max@0
|
194 access::rw(n_slices) = in_n_slices;
|
max@0
|
195
|
max@0
|
196 create_mat();
|
max@0
|
197 }
|
max@0
|
198 }
|
max@0
|
199 else
|
max@0
|
200 {
|
max@0
|
201 arma_debug_check( (t_mem_state == 2), "Cube::init(): requested size is not compatible with the size of auxiliary memory" );
|
max@0
|
202
|
max@0
|
203 delete_mat();
|
max@0
|
204
|
max@0
|
205 if(t_mem_state == 0)
|
max@0
|
206 {
|
max@0
|
207 if(n_elem > Cube_prealloc::mem_n_elem )
|
max@0
|
208 {
|
max@0
|
209 arma_extra_debug_print("Cube::init(): freeing memory");
|
max@0
|
210
|
max@0
|
211 #if defined(ARMA_USE_TBB_ALLOC)
|
max@0
|
212 scalable_free((void *)(mem));
|
max@0
|
213 #else
|
max@0
|
214 delete [] mem;
|
max@0
|
215 #endif
|
max@0
|
216 }
|
max@0
|
217 }
|
max@0
|
218
|
max@0
|
219 access::rw(mem_state) = 0;
|
max@0
|
220
|
max@0
|
221 if(new_n_elem <= Cube_prealloc::mem_n_elem)
|
max@0
|
222 {
|
max@0
|
223 access::rw(mem) = mem_local;
|
max@0
|
224 }
|
max@0
|
225 else
|
max@0
|
226 {
|
max@0
|
227 arma_extra_debug_print("Cube::init(): allocating memory");
|
max@0
|
228
|
max@0
|
229 #if defined(ARMA_USE_TBB_ALLOC)
|
max@0
|
230 access::rw(mem) = (eT *)scalable_malloc(sizeof(eT)*new_n_elem);
|
max@0
|
231 #else
|
max@0
|
232 access::rw(mem) = new(std::nothrow) eT[new_n_elem];
|
max@0
|
233 #endif
|
max@0
|
234
|
max@0
|
235 arma_check_bad_alloc( (mem == 0), "Cube::init(): out of memory" );
|
max@0
|
236 }
|
max@0
|
237
|
max@0
|
238 if(new_n_elem > 0)
|
max@0
|
239 {
|
max@0
|
240 access::rw(n_rows) = in_n_rows;
|
max@0
|
241 access::rw(n_cols) = in_n_cols;
|
max@0
|
242 access::rw(n_elem_slice) = in_n_rows*in_n_cols;
|
max@0
|
243 access::rw(n_slices) = in_n_slices;
|
max@0
|
244 access::rw(n_elem) = new_n_elem;
|
max@0
|
245
|
max@0
|
246 create_mat();
|
max@0
|
247 }
|
max@0
|
248 }
|
max@0
|
249
|
max@0
|
250
|
max@0
|
251 if(new_n_elem == 0)
|
max@0
|
252 {
|
max@0
|
253 access::rw(n_rows) = 0;
|
max@0
|
254 access::rw(n_cols) = 0;
|
max@0
|
255 access::rw(n_elem_slice) = 0;
|
max@0
|
256 access::rw(n_slices) = 0;
|
max@0
|
257 access::rw(n_elem) = 0;
|
max@0
|
258 }
|
max@0
|
259 }
|
max@0
|
260
|
max@0
|
261
|
max@0
|
262
|
max@0
|
263 //! for constructing a complex cube out of two non-complex cubes
|
max@0
|
264 template<typename eT>
|
max@0
|
265 template<typename T1, typename T2>
|
max@0
|
266 inline
|
max@0
|
267 void
|
max@0
|
268 Cube<eT>::init
|
max@0
|
269 (
|
max@0
|
270 const BaseCube<typename Cube<eT>::pod_type,T1>& A,
|
max@0
|
271 const BaseCube<typename Cube<eT>::pod_type,T2>& B
|
max@0
|
272 )
|
max@0
|
273 {
|
max@0
|
274 arma_extra_debug_sigprint();
|
max@0
|
275
|
max@0
|
276 typedef typename T1::elem_type T;
|
max@0
|
277 typedef typename ProxyCube<T1>::ea_type ea_type1;
|
max@0
|
278 typedef typename ProxyCube<T2>::ea_type ea_type2;
|
max@0
|
279
|
max@0
|
280 arma_type_check(( is_complex<eT>::value == false )); //!< compile-time abort if eT isn't std::complex
|
max@0
|
281 arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex
|
max@0
|
282
|
max@0
|
283 arma_type_check(( is_same_type< std::complex<T>, eT >::value == false )); //!< compile-time abort if types are not compatible
|
max@0
|
284
|
max@0
|
285 const ProxyCube<T1> X(A.get_ref());
|
max@0
|
286 const ProxyCube<T2> Y(B.get_ref());
|
max@0
|
287
|
max@0
|
288 arma_assert_same_size(X, Y, "Cube()");
|
max@0
|
289
|
max@0
|
290 init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices());
|
max@0
|
291
|
max@0
|
292 const uword N = n_elem;
|
max@0
|
293 eT* out_mem = memptr();
|
max@0
|
294 ea_type1 PX = X.get_ea();
|
max@0
|
295 ea_type2 PY = Y.get_ea();
|
max@0
|
296
|
max@0
|
297 for(uword i=0; i<N; ++i)
|
max@0
|
298 {
|
max@0
|
299 out_mem[i] = std::complex<T>(PX[i], PY[i]);
|
max@0
|
300 }
|
max@0
|
301 }
|
max@0
|
302
|
max@0
|
303
|
max@0
|
304
|
max@0
|
305 //! try to steal the memory from a given cube;
|
max@0
|
306 //! if memory can't be stolen, copy the given cube
|
max@0
|
307 template<typename eT>
|
max@0
|
308 inline
|
max@0
|
309 void
|
max@0
|
310 Cube<eT>::steal_mem(Cube<eT>& x)
|
max@0
|
311 {
|
max@0
|
312 arma_extra_debug_sigprint();
|
max@0
|
313
|
max@0
|
314 if(this != &x)
|
max@0
|
315 {
|
max@0
|
316 if( (x.mem_state == 0) && (x.n_elem > Cube_prealloc::mem_n_elem) )
|
max@0
|
317 {
|
max@0
|
318 reset();
|
max@0
|
319
|
max@0
|
320 const uword x_n_slices = x.n_slices;
|
max@0
|
321
|
max@0
|
322 access::rw(n_rows) = x.n_rows;
|
max@0
|
323 access::rw(n_cols) = x.n_cols;
|
max@0
|
324 access::rw(n_elem_slice) = x.n_elem_slice;
|
max@0
|
325 access::rw(n_slices) = x_n_slices;
|
max@0
|
326 access::rw(n_elem) = x.n_elem;
|
max@0
|
327 access::rw(mem) = x.mem;
|
max@0
|
328
|
max@0
|
329 if(x_n_slices > Cube_prealloc::mat_ptrs_size)
|
max@0
|
330 {
|
max@0
|
331 access::rw( mat_ptrs) = x.mat_ptrs;
|
max@0
|
332 access::rw(x.mat_ptrs) = 0;
|
max@0
|
333 }
|
max@0
|
334 else
|
max@0
|
335 {
|
max@0
|
336 access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local);
|
max@0
|
337
|
max@0
|
338 for(uword i=0; i < x_n_slices; ++i)
|
max@0
|
339 {
|
max@0
|
340 mat_ptrs[i] = x.mat_ptrs[i];
|
max@0
|
341 x.mat_ptrs[i] = 0;
|
max@0
|
342 }
|
max@0
|
343 }
|
max@0
|
344
|
max@0
|
345 access::rw(x.n_rows) = 0;
|
max@0
|
346 access::rw(x.n_cols) = 0;
|
max@0
|
347 access::rw(x.n_elem_slice) = 0;
|
max@0
|
348 access::rw(x.n_slices) = 0;
|
max@0
|
349 access::rw(x.n_elem) = 0;
|
max@0
|
350 access::rw(x.mem) = 0;
|
max@0
|
351 }
|
max@0
|
352 else
|
max@0
|
353 {
|
max@0
|
354 (*this).operator=(x);
|
max@0
|
355 }
|
max@0
|
356 }
|
max@0
|
357 }
|
max@0
|
358
|
max@0
|
359
|
max@0
|
360
|
max@0
|
361 template<typename eT>
|
max@0
|
362 inline
|
max@0
|
363 void
|
max@0
|
364 Cube<eT>::delete_mat()
|
max@0
|
365 {
|
max@0
|
366 arma_extra_debug_sigprint();
|
max@0
|
367
|
max@0
|
368 for(uword slice = 0; slice < n_slices; ++slice)
|
max@0
|
369 {
|
max@0
|
370 delete access::rw(mat_ptrs[slice]);
|
max@0
|
371 }
|
max@0
|
372
|
max@0
|
373 if(mem_state <= 2)
|
max@0
|
374 {
|
max@0
|
375 if(n_slices > Cube_prealloc::mat_ptrs_size)
|
max@0
|
376 {
|
max@0
|
377 delete [] mat_ptrs;
|
max@0
|
378 }
|
max@0
|
379 }
|
max@0
|
380 }
|
max@0
|
381
|
max@0
|
382
|
max@0
|
383
|
max@0
|
384 template<typename eT>
|
max@0
|
385 inline
|
max@0
|
386 void
|
max@0
|
387 Cube<eT>::create_mat()
|
max@0
|
388 {
|
max@0
|
389 arma_extra_debug_sigprint();
|
max@0
|
390
|
max@0
|
391 if(mem_state <= 2)
|
max@0
|
392 {
|
max@0
|
393 if(n_slices <= Cube_prealloc::mat_ptrs_size)
|
max@0
|
394 {
|
max@0
|
395 access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local);
|
max@0
|
396 }
|
max@0
|
397 else
|
max@0
|
398 {
|
max@0
|
399 access::rw(mat_ptrs) = new(std::nothrow) const Mat<eT>*[n_slices];
|
max@0
|
400
|
max@0
|
401 arma_check_bad_alloc( (mat_ptrs == 0), "Cube::create_mat(): out of memory" );
|
max@0
|
402 }
|
max@0
|
403 }
|
max@0
|
404
|
max@0
|
405 for(uword slice = 0; slice < n_slices; ++slice)
|
max@0
|
406 {
|
max@0
|
407 mat_ptrs[slice] = new Mat<eT>('j', slice_memptr(slice), n_rows, n_cols);
|
max@0
|
408 }
|
max@0
|
409 }
|
max@0
|
410
|
max@0
|
411
|
max@0
|
412
|
max@0
|
413 //! Set the cube to be equal to the specified scalar.
|
max@0
|
414 //! NOTE: the size of the cube will be 1x1x1
|
max@0
|
415 template<typename eT>
|
max@0
|
416 arma_inline
|
max@0
|
417 const Cube<eT>&
|
max@0
|
418 Cube<eT>::operator=(const eT val)
|
max@0
|
419 {
|
max@0
|
420 arma_extra_debug_sigprint();
|
max@0
|
421
|
max@0
|
422 init_warm(1,1,1);
|
max@0
|
423 access::rw(mem[0]) = val;
|
max@0
|
424 return *this;
|
max@0
|
425 }
|
max@0
|
426
|
max@0
|
427
|
max@0
|
428
|
max@0
|
429 //! In-place addition of a scalar to all elements of the cube
|
max@0
|
430 template<typename eT>
|
max@0
|
431 arma_inline
|
max@0
|
432 const Cube<eT>&
|
max@0
|
433 Cube<eT>::operator+=(const eT val)
|
max@0
|
434 {
|
max@0
|
435 arma_extra_debug_sigprint();
|
max@0
|
436
|
max@0
|
437 arrayops::inplace_plus( memptr(), val, n_elem );
|
max@0
|
438
|
max@0
|
439 return *this;
|
max@0
|
440 }
|
max@0
|
441
|
max@0
|
442
|
max@0
|
443
|
max@0
|
444 //! In-place subtraction of a scalar from all elements of the cube
|
max@0
|
445 template<typename eT>
|
max@0
|
446 arma_inline
|
max@0
|
447 const Cube<eT>&
|
max@0
|
448 Cube<eT>::operator-=(const eT val)
|
max@0
|
449 {
|
max@0
|
450 arma_extra_debug_sigprint();
|
max@0
|
451
|
max@0
|
452 arrayops::inplace_minus( memptr(), val, n_elem );
|
max@0
|
453
|
max@0
|
454 return *this;
|
max@0
|
455 }
|
max@0
|
456
|
max@0
|
457
|
max@0
|
458
|
max@0
|
459 //! In-place multiplication of all elements of the cube with a scalar
|
max@0
|
460 template<typename eT>
|
max@0
|
461 arma_inline
|
max@0
|
462 const Cube<eT>&
|
max@0
|
463 Cube<eT>::operator*=(const eT val)
|
max@0
|
464 {
|
max@0
|
465 arma_extra_debug_sigprint();
|
max@0
|
466
|
max@0
|
467 arrayops::inplace_mul( memptr(), val, n_elem );
|
max@0
|
468
|
max@0
|
469 return *this;
|
max@0
|
470 }
|
max@0
|
471
|
max@0
|
472
|
max@0
|
473
|
max@0
|
474 //! In-place division of all elements of the cube with a scalar
|
max@0
|
475 template<typename eT>
|
max@0
|
476 arma_inline
|
max@0
|
477 const Cube<eT>&
|
max@0
|
478 Cube<eT>::operator/=(const eT val)
|
max@0
|
479 {
|
max@0
|
480 arma_extra_debug_sigprint();
|
max@0
|
481
|
max@0
|
482 arrayops::inplace_div( memptr(), val, n_elem );
|
max@0
|
483
|
max@0
|
484 return *this;
|
max@0
|
485 }
|
max@0
|
486
|
max@0
|
487
|
max@0
|
488
|
max@0
|
489 //! construct a cube from a given cube
|
max@0
|
490 template<typename eT>
|
max@0
|
491 inline
|
max@0
|
492 Cube<eT>::Cube(const Cube<eT>& x)
|
max@0
|
493 : n_rows(x.n_rows)
|
max@0
|
494 , n_cols(x.n_cols)
|
max@0
|
495 , n_elem_slice(x.n_elem_slice)
|
max@0
|
496 , n_slices(x.n_slices)
|
max@0
|
497 , n_elem(x.n_elem)
|
max@0
|
498 , mem_state(0)
|
max@0
|
499 , mat_ptrs()
|
max@0
|
500 , mem()
|
max@0
|
501 {
|
max@0
|
502 arma_extra_debug_sigprint_this(this);
|
max@0
|
503 arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x") % this % &x);
|
max@0
|
504
|
max@0
|
505 init_cold();
|
max@0
|
506
|
max@0
|
507 arrayops::copy( memptr(), x.mem, n_elem );
|
max@0
|
508 }
|
max@0
|
509
|
max@0
|
510
|
max@0
|
511
|
max@0
|
512 //! construct a cube from a given cube
|
max@0
|
513 template<typename eT>
|
max@0
|
514 inline
|
max@0
|
515 const Cube<eT>&
|
max@0
|
516 Cube<eT>::operator=(const Cube<eT>& x)
|
max@0
|
517 {
|
max@0
|
518 arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x") % this % &x);
|
max@0
|
519
|
max@0
|
520 if(this != &x)
|
max@0
|
521 {
|
max@0
|
522 init_warm(x.n_rows, x.n_cols, x.n_slices);
|
max@0
|
523
|
max@0
|
524 arrayops::copy( memptr(), x.mem, n_elem );
|
max@0
|
525 }
|
max@0
|
526
|
max@0
|
527 return *this;
|
max@0
|
528 }
|
max@0
|
529
|
max@0
|
530
|
max@0
|
531
|
max@0
|
532 //! construct a cube from a given auxiliary array of eTs.
|
max@0
|
533 //! if copy_aux_mem is true, new memory is allocated and the array is copied.
|
max@0
|
534 //! if copy_aux_mem is false, the auxiliary array is used directly (without allocating memory and copying).
|
max@0
|
535 //! note that in the latter case
|
max@0
|
536 //! the default is to copy the array.
|
max@0
|
537
|
max@0
|
538 template<typename eT>
|
max@0
|
539 inline
|
max@0
|
540 Cube<eT>::Cube(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices, const bool copy_aux_mem, const bool strict)
|
max@0
|
541 : n_rows ( aux_n_rows )
|
max@0
|
542 , n_cols ( aux_n_cols )
|
max@0
|
543 , n_elem_slice( aux_n_rows*aux_n_cols )
|
max@0
|
544 , n_slices ( aux_n_slices )
|
max@0
|
545 , n_elem ( aux_n_rows*aux_n_cols*aux_n_slices )
|
max@0
|
546 , mem_state ( copy_aux_mem ? 0 : (strict ? 2 : 1) )
|
max@0
|
547 , mat_ptrs ( 0 )
|
max@0
|
548 , mem ( copy_aux_mem ? 0 : aux_mem )
|
max@0
|
549 {
|
max@0
|
550 arma_extra_debug_sigprint_this(this);
|
max@0
|
551
|
max@0
|
552 if(copy_aux_mem == true)
|
max@0
|
553 {
|
max@0
|
554 init_cold();
|
max@0
|
555
|
max@0
|
556 arrayops::copy( memptr(), aux_mem, n_elem );
|
max@0
|
557 }
|
max@0
|
558 else
|
max@0
|
559 {
|
max@0
|
560 create_mat();
|
max@0
|
561 }
|
max@0
|
562 }
|
max@0
|
563
|
max@0
|
564
|
max@0
|
565
|
max@0
|
566 //! construct a cube from a given auxiliary read-only array of eTs.
|
max@0
|
567 //! the array is copied.
|
max@0
|
568 template<typename eT>
|
max@0
|
569 inline
|
max@0
|
570 Cube<eT>::Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices)
|
max@0
|
571 : n_rows(aux_n_rows)
|
max@0
|
572 , n_cols(aux_n_cols)
|
max@0
|
573 , n_elem_slice(aux_n_rows*aux_n_cols)
|
max@0
|
574 , n_slices(aux_n_slices)
|
max@0
|
575 , n_elem(aux_n_rows*aux_n_cols*aux_n_slices)
|
max@0
|
576 , mem_state(0)
|
max@0
|
577 , mat_ptrs()
|
max@0
|
578 , mem()
|
max@0
|
579 {
|
max@0
|
580 arma_extra_debug_sigprint_this(this);
|
max@0
|
581
|
max@0
|
582 init_cold();
|
max@0
|
583
|
max@0
|
584 arrayops::copy( memptr(), aux_mem, n_elem );
|
max@0
|
585 }
|
max@0
|
586
|
max@0
|
587
|
max@0
|
588
|
max@0
|
589 //! in-place cube addition
|
max@0
|
590 template<typename eT>
|
max@0
|
591 inline
|
max@0
|
592 const Cube<eT>&
|
max@0
|
593 Cube<eT>::operator+=(const Cube<eT>& m)
|
max@0
|
594 {
|
max@0
|
595 arma_extra_debug_sigprint();
|
max@0
|
596
|
max@0
|
597 arma_debug_assert_same_size(*this, m, "cube addition");
|
max@0
|
598
|
max@0
|
599 arrayops::inplace_plus( memptr(), m.memptr(), n_elem );
|
max@0
|
600
|
max@0
|
601 return *this;
|
max@0
|
602 }
|
max@0
|
603
|
max@0
|
604
|
max@0
|
605
|
max@0
|
606 //! in-place cube subtraction
|
max@0
|
607 template<typename eT>
|
max@0
|
608 inline
|
max@0
|
609 const Cube<eT>&
|
max@0
|
610 Cube<eT>::operator-=(const Cube<eT>& m)
|
max@0
|
611 {
|
max@0
|
612 arma_extra_debug_sigprint();
|
max@0
|
613
|
max@0
|
614 arma_debug_assert_same_size(*this, m, "cube subtraction");
|
max@0
|
615
|
max@0
|
616 arrayops::inplace_minus( memptr(), m.memptr(), n_elem );
|
max@0
|
617
|
max@0
|
618 return *this;
|
max@0
|
619 }
|
max@0
|
620
|
max@0
|
621
|
max@0
|
622
|
max@0
|
623 //! in-place element-wise cube multiplication
|
max@0
|
624 template<typename eT>
|
max@0
|
625 inline
|
max@0
|
626 const Cube<eT>&
|
max@0
|
627 Cube<eT>::operator%=(const Cube<eT>& m)
|
max@0
|
628 {
|
max@0
|
629 arma_extra_debug_sigprint();
|
max@0
|
630
|
max@0
|
631 arma_debug_assert_same_size(*this, m, "element-wise cube multiplication");
|
max@0
|
632
|
max@0
|
633 arrayops::inplace_mul( memptr(), m.memptr(), n_elem );
|
max@0
|
634
|
max@0
|
635 return *this;
|
max@0
|
636 }
|
max@0
|
637
|
max@0
|
638
|
max@0
|
639
|
max@0
|
640 //! in-place element-wise cube division
|
max@0
|
641 template<typename eT>
|
max@0
|
642 inline
|
max@0
|
643 const Cube<eT>&
|
max@0
|
644 Cube<eT>::operator/=(const Cube<eT>& m)
|
max@0
|
645 {
|
max@0
|
646 arma_extra_debug_sigprint();
|
max@0
|
647
|
max@0
|
648 arma_debug_assert_same_size(*this, m, "element-wise cube division");
|
max@0
|
649
|
max@0
|
650 arrayops::inplace_div( memptr(), m.memptr(), n_elem );
|
max@0
|
651
|
max@0
|
652 return *this;
|
max@0
|
653 }
|
max@0
|
654
|
max@0
|
655
|
max@0
|
656
|
max@0
|
657 //! for constructing a complex cube out of two non-complex cubes
|
max@0
|
658 template<typename eT>
|
max@0
|
659 template<typename T1, typename T2>
|
max@0
|
660 inline
|
max@0
|
661 Cube<eT>::Cube
|
max@0
|
662 (
|
max@0
|
663 const BaseCube<typename Cube<eT>::pod_type,T1>& A,
|
max@0
|
664 const BaseCube<typename Cube<eT>::pod_type,T2>& B
|
max@0
|
665 )
|
max@0
|
666 : n_rows(0)
|
max@0
|
667 , n_cols(0)
|
max@0
|
668 , n_elem_slice(0)
|
max@0
|
669 , n_slices(0)
|
max@0
|
670 , n_elem(0)
|
max@0
|
671 , mem_state(0)
|
max@0
|
672 , mat_ptrs()
|
max@0
|
673 , mem()
|
max@0
|
674 {
|
max@0
|
675 arma_extra_debug_sigprint_this(this);
|
max@0
|
676
|
max@0
|
677 init(A,B);
|
max@0
|
678 }
|
max@0
|
679
|
max@0
|
680
|
max@0
|
681
|
max@0
|
682 //! construct a cube from a subview_cube instance (e.g. construct a cube from a delayed subcube operation)
|
max@0
|
683 template<typename eT>
|
max@0
|
684 inline
|
max@0
|
685 Cube<eT>::Cube(const subview_cube<eT>& X)
|
max@0
|
686 : n_rows(X.n_rows)
|
max@0
|
687 , n_cols(X.n_cols)
|
max@0
|
688 , n_elem_slice(X.n_elem_slice)
|
max@0
|
689 , n_slices(X.n_slices)
|
max@0
|
690 , n_elem(X.n_elem)
|
max@0
|
691 , mem_state(0)
|
max@0
|
692 , mat_ptrs()
|
max@0
|
693 , mem()
|
max@0
|
694 {
|
max@0
|
695 arma_extra_debug_sigprint_this(this);
|
max@0
|
696
|
max@0
|
697 init_cold();
|
max@0
|
698
|
max@0
|
699 subview_cube<eT>::extract(*this, X);
|
max@0
|
700 }
|
max@0
|
701
|
max@0
|
702
|
max@0
|
703
|
max@0
|
704 //! construct a cube from a subview_cube instance (e.g. construct a cube from a delayed subcube operation)
|
max@0
|
705 template<typename eT>
|
max@0
|
706 inline
|
max@0
|
707 const Cube<eT>&
|
max@0
|
708 Cube<eT>::operator=(const subview_cube<eT>& X)
|
max@0
|
709 {
|
max@0
|
710 arma_extra_debug_sigprint();
|
max@0
|
711
|
max@0
|
712 const bool alias = (this == &(X.m));
|
max@0
|
713
|
max@0
|
714 if(alias == false)
|
max@0
|
715 {
|
max@0
|
716 init_warm(X.n_rows, X.n_cols, X.n_slices);
|
max@0
|
717
|
max@0
|
718 subview_cube<eT>::extract(*this, X);
|
max@0
|
719 }
|
max@0
|
720 else
|
max@0
|
721 {
|
max@0
|
722 Cube<eT> tmp(X);
|
max@0
|
723
|
max@0
|
724 steal_mem(tmp);
|
max@0
|
725 }
|
max@0
|
726
|
max@0
|
727 return *this;
|
max@0
|
728 }
|
max@0
|
729
|
max@0
|
730
|
max@0
|
731
|
max@0
|
732 //! in-place cube addition (using a subcube on the right-hand-side)
|
max@0
|
733 template<typename eT>
|
max@0
|
734 inline
|
max@0
|
735 const Cube<eT>&
|
max@0
|
736 Cube<eT>::operator+=(const subview_cube<eT>& X)
|
max@0
|
737 {
|
max@0
|
738 arma_extra_debug_sigprint();
|
max@0
|
739
|
max@0
|
740 subview_cube<eT>::plus_inplace(*this, X);
|
max@0
|
741
|
max@0
|
742 return *this;
|
max@0
|
743 }
|
max@0
|
744
|
max@0
|
745
|
max@0
|
746
|
max@0
|
747 //! in-place cube subtraction (using a subcube on the right-hand-side)
|
max@0
|
748 template<typename eT>
|
max@0
|
749 inline
|
max@0
|
750 const Cube<eT>&
|
max@0
|
751 Cube<eT>::operator-=(const subview_cube<eT>& X)
|
max@0
|
752 {
|
max@0
|
753 arma_extra_debug_sigprint();
|
max@0
|
754
|
max@0
|
755 subview_cube<eT>::minus_inplace(*this, X);
|
max@0
|
756
|
max@0
|
757 return *this;
|
max@0
|
758 }
|
max@0
|
759
|
max@0
|
760
|
max@0
|
761
|
max@0
|
762 //! in-place element-wise cube mutiplication (using a subcube on the right-hand-side)
|
max@0
|
763 template<typename eT>
|
max@0
|
764 inline
|
max@0
|
765 const Cube<eT>&
|
max@0
|
766 Cube<eT>::operator%=(const subview_cube<eT>& X)
|
max@0
|
767 {
|
max@0
|
768 arma_extra_debug_sigprint();
|
max@0
|
769
|
max@0
|
770 subview_cube<eT>::schur_inplace(*this, X);
|
max@0
|
771
|
max@0
|
772 return *this;
|
max@0
|
773 }
|
max@0
|
774
|
max@0
|
775
|
max@0
|
776
|
max@0
|
777 //! in-place element-wise cube division (using a subcube on the right-hand-side)
|
max@0
|
778 template<typename eT>
|
max@0
|
779 inline
|
max@0
|
780 const Cube<eT>&
|
max@0
|
781 Cube<eT>::operator/=(const subview_cube<eT>& X)
|
max@0
|
782 {
|
max@0
|
783 arma_extra_debug_sigprint();
|
max@0
|
784
|
max@0
|
785 subview_cube<eT>::div_inplace(*this, X);
|
max@0
|
786
|
max@0
|
787 return *this;
|
max@0
|
788 }
|
max@0
|
789
|
max@0
|
790
|
max@0
|
791
|
max@0
|
792 //! provide the reference to the matrix representing a single slice
|
max@0
|
793 template<typename eT>
|
max@0
|
794 arma_inline
|
max@0
|
795 Mat<eT>&
|
max@0
|
796 Cube<eT>::slice(const uword in_slice)
|
max@0
|
797 {
|
max@0
|
798 arma_extra_debug_sigprint();
|
max@0
|
799
|
max@0
|
800 arma_debug_check
|
max@0
|
801 (
|
max@0
|
802 (in_slice >= n_slices),
|
max@0
|
803 "Cube::slice(): index out of bounds"
|
max@0
|
804 );
|
max@0
|
805
|
max@0
|
806 return const_cast< Mat<eT>& >( *(mat_ptrs[in_slice]) );
|
max@0
|
807 }
|
max@0
|
808
|
max@0
|
809
|
max@0
|
810
|
max@0
|
811 //! provide the reference to the matrix representing a single slice
|
max@0
|
812 template<typename eT>
|
max@0
|
813 arma_inline
|
max@0
|
814 const Mat<eT>&
|
max@0
|
815 Cube<eT>::slice(const uword in_slice) const
|
max@0
|
816 {
|
max@0
|
817 arma_extra_debug_sigprint();
|
max@0
|
818
|
max@0
|
819 arma_debug_check
|
max@0
|
820 (
|
max@0
|
821 (in_slice >= n_slices),
|
max@0
|
822 "Cube::slice(): index out of bounds"
|
max@0
|
823 );
|
max@0
|
824
|
max@0
|
825 return *(mat_ptrs[in_slice]);
|
max@0
|
826 }
|
max@0
|
827
|
max@0
|
828
|
max@0
|
829
|
max@0
|
830 //! creation of subview_cube (subcube comprised of specified slices)
|
max@0
|
831 template<typename eT>
|
max@0
|
832 arma_inline
|
max@0
|
833 subview_cube<eT>
|
max@0
|
834 Cube<eT>::slices(const uword in_slice1, const uword in_slice2)
|
max@0
|
835 {
|
max@0
|
836 arma_extra_debug_sigprint();
|
max@0
|
837
|
max@0
|
838 arma_debug_check
|
max@0
|
839 (
|
max@0
|
840 (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
|
max@0
|
841 "Cube::slices(): indices out of bounds or incorrectly used"
|
max@0
|
842 );
|
max@0
|
843
|
max@0
|
844 const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
|
max@0
|
845
|
max@0
|
846 return subview_cube<eT>(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices);
|
max@0
|
847 }
|
max@0
|
848
|
max@0
|
849
|
max@0
|
850
|
max@0
|
851 //! creation of subview_cube (subcube comprised of specified slices)
|
max@0
|
852 template<typename eT>
|
max@0
|
853 arma_inline
|
max@0
|
854 const subview_cube<eT>
|
max@0
|
855 Cube<eT>::slices(const uword in_slice1, const uword in_slice2) const
|
max@0
|
856 {
|
max@0
|
857 arma_extra_debug_sigprint();
|
max@0
|
858
|
max@0
|
859 arma_debug_check
|
max@0
|
860 (
|
max@0
|
861 (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
|
max@0
|
862 "Cube::rows(): indices out of bounds or incorrectly used"
|
max@0
|
863 );
|
max@0
|
864
|
max@0
|
865 const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
|
max@0
|
866
|
max@0
|
867 return subview_cube<eT>(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices);
|
max@0
|
868 }
|
max@0
|
869
|
max@0
|
870
|
max@0
|
871
|
max@0
|
872 //! creation of subview_cube (generic subcube)
|
max@0
|
873 template<typename eT>
|
max@0
|
874 arma_inline
|
max@0
|
875 subview_cube<eT>
|
max@0
|
876 Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2)
|
max@0
|
877 {
|
max@0
|
878 arma_extra_debug_sigprint();
|
max@0
|
879
|
max@0
|
880 arma_debug_check
|
max@0
|
881 (
|
max@0
|
882 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) ||
|
max@0
|
883 (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices),
|
max@0
|
884 "Cube::subcube(): indices out of bounds or incorrectly used"
|
max@0
|
885 );
|
max@0
|
886
|
max@0
|
887 const uword subcube_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
888 const uword subcube_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
889 const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
|
max@0
|
890
|
max@0
|
891 return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
|
max@0
|
892 }
|
max@0
|
893
|
max@0
|
894
|
max@0
|
895
|
max@0
|
896 //! creation of subview_cube (generic subcube)
|
max@0
|
897 template<typename eT>
|
max@0
|
898 arma_inline
|
max@0
|
899 const subview_cube<eT>
|
max@0
|
900 Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const
|
max@0
|
901 {
|
max@0
|
902 arma_extra_debug_sigprint();
|
max@0
|
903
|
max@0
|
904 arma_debug_check
|
max@0
|
905 (
|
max@0
|
906 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) ||
|
max@0
|
907 (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices),
|
max@0
|
908 "Cube::subcube(): indices out of bounds or incorrectly used"
|
max@0
|
909 );
|
max@0
|
910
|
max@0
|
911 const uword subcube_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
912 const uword subcube_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
913 const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
|
max@0
|
914
|
max@0
|
915 return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
|
max@0
|
916 }
|
max@0
|
917
|
max@0
|
918
|
max@0
|
919
|
max@0
|
920 //! creation of subview_cube (generic subcube)
|
max@0
|
921 template<typename eT>
|
max@0
|
922 inline
|
max@0
|
923 subview_cube<eT>
|
max@0
|
924 Cube<eT>::subcube(const span& row_span, const span& col_span, const span& slice_span)
|
max@0
|
925 {
|
max@0
|
926 arma_extra_debug_sigprint();
|
max@0
|
927
|
max@0
|
928 const bool row_all = row_span.whole;
|
max@0
|
929 const bool col_all = col_span.whole;
|
max@0
|
930 const bool slice_all = slice_span.whole;
|
max@0
|
931
|
max@0
|
932 const uword local_n_rows = n_rows;
|
max@0
|
933 const uword local_n_cols = n_cols;
|
max@0
|
934 const uword local_n_slices = n_slices;
|
max@0
|
935
|
max@0
|
936 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
937 const uword in_row2 = row_span.b;
|
max@0
|
938 const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
939
|
max@0
|
940 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
941 const uword in_col2 = col_span.b;
|
max@0
|
942 const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
943
|
max@0
|
944 const uword in_slice1 = slice_all ? 0 : slice_span.a;
|
max@0
|
945 const uword in_slice2 = slice_span.b;
|
max@0
|
946 const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1;
|
max@0
|
947
|
max@0
|
948 arma_debug_check
|
max@0
|
949 (
|
max@0
|
950 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
951 ||
|
max@0
|
952 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
953 ||
|
max@0
|
954 ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) )
|
max@0
|
955 ,
|
max@0
|
956 "Cube::subcube(): indices out of bounds or incorrectly used"
|
max@0
|
957 );
|
max@0
|
958
|
max@0
|
959 return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
|
max@0
|
960 }
|
max@0
|
961
|
max@0
|
962
|
max@0
|
963
|
max@0
|
964 //! creation of subview_cube (generic subcube)
|
max@0
|
965 template<typename eT>
|
max@0
|
966 inline
|
max@0
|
967 const subview_cube<eT>
|
max@0
|
968 Cube<eT>::subcube(const span& row_span, const span& col_span, const span& slice_span) const
|
max@0
|
969 {
|
max@0
|
970 arma_extra_debug_sigprint();
|
max@0
|
971
|
max@0
|
972 const bool row_all = row_span.whole;
|
max@0
|
973 const bool col_all = col_span.whole;
|
max@0
|
974 const bool slice_all = slice_span.whole;
|
max@0
|
975
|
max@0
|
976 const uword local_n_rows = n_rows;
|
max@0
|
977 const uword local_n_cols = n_cols;
|
max@0
|
978 const uword local_n_slices = n_slices;
|
max@0
|
979
|
max@0
|
980 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
981 const uword in_row2 = row_span.b;
|
max@0
|
982 const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
983
|
max@0
|
984 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
985 const uword in_col2 = col_span.b;
|
max@0
|
986 const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
987
|
max@0
|
988 const uword in_slice1 = slice_all ? 0 : slice_span.a;
|
max@0
|
989 const uword in_slice2 = slice_span.b;
|
max@0
|
990 const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1;
|
max@0
|
991
|
max@0
|
992 arma_debug_check
|
max@0
|
993 (
|
max@0
|
994 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
995 ||
|
max@0
|
996 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
997 ||
|
max@0
|
998 ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) )
|
max@0
|
999 ,
|
max@0
|
1000 "Cube::subcube(): indices out of bounds or incorrectly used"
|
max@0
|
1001 );
|
max@0
|
1002
|
max@0
|
1003 return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
|
max@0
|
1004 }
|
max@0
|
1005
|
max@0
|
1006
|
max@0
|
1007
|
max@0
|
1008 template<typename eT>
|
max@0
|
1009 inline
|
max@0
|
1010 subview_cube<eT>
|
max@0
|
1011 Cube<eT>::operator()(const span& row_span, const span& col_span, const span& slice_span)
|
max@0
|
1012 {
|
max@0
|
1013 arma_extra_debug_sigprint();
|
max@0
|
1014
|
max@0
|
1015 return (*this).subcube(row_span, col_span, slice_span);
|
max@0
|
1016 }
|
max@0
|
1017
|
max@0
|
1018
|
max@0
|
1019
|
max@0
|
1020 template<typename eT>
|
max@0
|
1021 inline
|
max@0
|
1022 const subview_cube<eT>
|
max@0
|
1023 Cube<eT>::operator()(const span& row_span, const span& col_span, const span& slice_span) const
|
max@0
|
1024 {
|
max@0
|
1025 arma_extra_debug_sigprint();
|
max@0
|
1026
|
max@0
|
1027 return (*this).subcube(row_span, col_span, slice_span);
|
max@0
|
1028 }
|
max@0
|
1029
|
max@0
|
1030
|
max@0
|
1031
|
max@0
|
1032 //! remove specified slice
|
max@0
|
1033 template<typename eT>
|
max@0
|
1034 inline
|
max@0
|
1035 void
|
max@0
|
1036 Cube<eT>::shed_slice(const uword slice_num)
|
max@0
|
1037 {
|
max@0
|
1038 arma_extra_debug_sigprint();
|
max@0
|
1039
|
max@0
|
1040 arma_debug_check( slice_num >= n_slices, "Cube::shed_slice(): out of bounds");
|
max@0
|
1041
|
max@0
|
1042 shed_slices(slice_num, slice_num);
|
max@0
|
1043 }
|
max@0
|
1044
|
max@0
|
1045
|
max@0
|
1046
|
max@0
|
1047 //! remove specified slices
|
max@0
|
1048 template<typename eT>
|
max@0
|
1049 inline
|
max@0
|
1050 void
|
max@0
|
1051 Cube<eT>::shed_slices(const uword in_slice1, const uword in_slice2)
|
max@0
|
1052 {
|
max@0
|
1053 arma_extra_debug_sigprint();
|
max@0
|
1054
|
max@0
|
1055 arma_debug_check
|
max@0
|
1056 (
|
max@0
|
1057 (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
|
max@0
|
1058 "Cube::shed_slices(): indices out of bounds or incorrectly used"
|
max@0
|
1059 );
|
max@0
|
1060
|
max@0
|
1061 const uword n_keep_front = in_slice1;
|
max@0
|
1062 const uword n_keep_back = n_slices - (in_slice2 + 1);
|
max@0
|
1063
|
max@0
|
1064 Cube<eT> X(n_rows, n_cols, n_keep_front + n_keep_back);
|
max@0
|
1065
|
max@0
|
1066 if(n_keep_front > 0)
|
max@0
|
1067 {
|
max@0
|
1068 X.slices( 0, (n_keep_front-1) ) = slices( 0, (in_slice1-1) );
|
max@0
|
1069 }
|
max@0
|
1070
|
max@0
|
1071 if(n_keep_back > 0)
|
max@0
|
1072 {
|
max@0
|
1073 X.slices( n_keep_front, (n_keep_front+n_keep_back-1) ) = slices( (in_slice2+1), (n_slices-1) );
|
max@0
|
1074 }
|
max@0
|
1075
|
max@0
|
1076 steal_mem(X);
|
max@0
|
1077 }
|
max@0
|
1078
|
max@0
|
1079
|
max@0
|
1080
|
max@0
|
1081 //! insert N slices at the specified slice position,
|
max@0
|
1082 //! optionally setting the elements of the inserted slices to zero
|
max@0
|
1083 template<typename eT>
|
max@0
|
1084 inline
|
max@0
|
1085 void
|
max@0
|
1086 Cube<eT>::insert_slices(const uword slice_num, const uword N, const bool set_to_zero)
|
max@0
|
1087 {
|
max@0
|
1088 arma_extra_debug_sigprint();
|
max@0
|
1089
|
max@0
|
1090 const uword t_n_slices = n_slices;
|
max@0
|
1091
|
max@0
|
1092 const uword A_n_slices = slice_num;
|
max@0
|
1093 const uword B_n_slices = t_n_slices - slice_num;
|
max@0
|
1094
|
max@0
|
1095 // insertion at slice_num == n_slices is in effect an append operation
|
max@0
|
1096 arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): out of bounds");
|
max@0
|
1097
|
max@0
|
1098 if(N > 0)
|
max@0
|
1099 {
|
max@0
|
1100 Cube<eT> out(n_rows, n_cols, t_n_slices + N);
|
max@0
|
1101
|
max@0
|
1102 if(A_n_slices > 0)
|
max@0
|
1103 {
|
max@0
|
1104 out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1);
|
max@0
|
1105 }
|
max@0
|
1106
|
max@0
|
1107 if(B_n_slices > 0)
|
max@0
|
1108 {
|
max@0
|
1109 out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices-1);
|
max@0
|
1110 }
|
max@0
|
1111
|
max@0
|
1112 if(set_to_zero == true)
|
max@0
|
1113 {
|
max@0
|
1114 //out.slices(slice_num, slice_num + N - 1).zeros();
|
max@0
|
1115
|
max@0
|
1116 for(uword i=slice_num; i < (slice_num + N); ++i)
|
max@0
|
1117 {
|
max@0
|
1118 out.slice(i).zeros();
|
max@0
|
1119 }
|
max@0
|
1120 }
|
max@0
|
1121
|
max@0
|
1122 steal_mem(out);
|
max@0
|
1123 }
|
max@0
|
1124 }
|
max@0
|
1125
|
max@0
|
1126
|
max@0
|
1127
|
max@0
|
1128 //! insert the given object at the specified slice position;
|
max@0
|
1129 //! the given object must have the same number of rows and columns as the cube
|
max@0
|
1130 template<typename eT>
|
max@0
|
1131 template<typename T1>
|
max@0
|
1132 inline
|
max@0
|
1133 void
|
max@0
|
1134 Cube<eT>::insert_slices(const uword slice_num, const BaseCube<eT,T1>& X)
|
max@0
|
1135 {
|
max@0
|
1136 arma_extra_debug_sigprint();
|
max@0
|
1137
|
max@0
|
1138 const unwrap_cube<T1> tmp(X.get_ref());
|
max@0
|
1139 const Cube<eT>& C = tmp.M;
|
max@0
|
1140
|
max@0
|
1141 const uword N = C.n_slices;
|
max@0
|
1142
|
max@0
|
1143 const uword t_n_slices = n_slices;
|
max@0
|
1144
|
max@0
|
1145 const uword A_n_slices = slice_num;
|
max@0
|
1146 const uword B_n_slices = t_n_slices - slice_num;
|
max@0
|
1147
|
max@0
|
1148 // insertion at slice_num == n_slices is in effect an append operation
|
max@0
|
1149 arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): out of bounds");
|
max@0
|
1150
|
max@0
|
1151 arma_debug_check
|
max@0
|
1152 (
|
max@0
|
1153 ( (C.n_rows != n_rows) || (C.n_cols != n_cols) ),
|
max@0
|
1154 "Cube::insert_slices(): given object has an incompatible dimensions"
|
max@0
|
1155 );
|
max@0
|
1156
|
max@0
|
1157 if(N > 0)
|
max@0
|
1158 {
|
max@0
|
1159 Cube<eT> out(n_rows, n_cols, t_n_slices + N);
|
max@0
|
1160
|
max@0
|
1161 if(A_n_slices > 0)
|
max@0
|
1162 {
|
max@0
|
1163 out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1);
|
max@0
|
1164 }
|
max@0
|
1165
|
max@0
|
1166 if(B_n_slices > 0)
|
max@0
|
1167 {
|
max@0
|
1168 out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices - 1);
|
max@0
|
1169 }
|
max@0
|
1170
|
max@0
|
1171 out.slices(slice_num, slice_num + N - 1) = C;
|
max@0
|
1172
|
max@0
|
1173 steal_mem(out);
|
max@0
|
1174 }
|
max@0
|
1175 }
|
max@0
|
1176
|
max@0
|
1177
|
max@0
|
1178
|
max@0
|
1179 //! create a cube from OpCube, i.e. run the previously delayed unary operations
|
max@0
|
1180 template<typename eT>
|
max@0
|
1181 template<typename gen_type>
|
max@0
|
1182 inline
|
max@0
|
1183 Cube<eT>::Cube(const GenCube<eT, gen_type>& X)
|
max@0
|
1184 : n_rows(X.n_rows)
|
max@0
|
1185 , n_cols(X.n_cols)
|
max@0
|
1186 , n_elem_slice(X.n_rows*X.n_cols)
|
max@0
|
1187 , n_slices(X.n_slices)
|
max@0
|
1188 , n_elem(X.n_rows*X.n_cols*X.n_slices)
|
max@0
|
1189 , mem_state(0)
|
max@0
|
1190 , mat_ptrs()
|
max@0
|
1191 , mem()
|
max@0
|
1192 {
|
max@0
|
1193 arma_extra_debug_sigprint_this(this);
|
max@0
|
1194
|
max@0
|
1195 init_cold();
|
max@0
|
1196
|
max@0
|
1197 X.apply(*this);
|
max@0
|
1198 }
|
max@0
|
1199
|
max@0
|
1200
|
max@0
|
1201
|
max@0
|
1202 template<typename eT>
|
max@0
|
1203 template<typename gen_type>
|
max@0
|
1204 inline
|
max@0
|
1205 const Cube<eT>&
|
max@0
|
1206 Cube<eT>::operator=(const GenCube<eT, gen_type>& X)
|
max@0
|
1207 {
|
max@0
|
1208 arma_extra_debug_sigprint();
|
max@0
|
1209
|
max@0
|
1210 init_warm(X.n_rows, X.n_cols, X.n_slices);
|
max@0
|
1211
|
max@0
|
1212 X.apply(*this);
|
max@0
|
1213
|
max@0
|
1214 return *this;
|
max@0
|
1215 }
|
max@0
|
1216
|
max@0
|
1217
|
max@0
|
1218
|
max@0
|
1219 template<typename eT>
|
max@0
|
1220 template<typename gen_type>
|
max@0
|
1221 inline
|
max@0
|
1222 const Cube<eT>&
|
max@0
|
1223 Cube<eT>::operator+=(const GenCube<eT, gen_type>& X)
|
max@0
|
1224 {
|
max@0
|
1225 arma_extra_debug_sigprint();
|
max@0
|
1226
|
max@0
|
1227 X.apply_inplace_plus(*this);
|
max@0
|
1228
|
max@0
|
1229 return *this;
|
max@0
|
1230 }
|
max@0
|
1231
|
max@0
|
1232
|
max@0
|
1233
|
max@0
|
1234 template<typename eT>
|
max@0
|
1235 template<typename gen_type>
|
max@0
|
1236 inline
|
max@0
|
1237 const Cube<eT>&
|
max@0
|
1238 Cube<eT>::operator-=(const GenCube<eT, gen_type>& X)
|
max@0
|
1239 {
|
max@0
|
1240 arma_extra_debug_sigprint();
|
max@0
|
1241
|
max@0
|
1242 X.apply_inplace_minus(*this);
|
max@0
|
1243
|
max@0
|
1244 return *this;
|
max@0
|
1245 }
|
max@0
|
1246
|
max@0
|
1247
|
max@0
|
1248
|
max@0
|
1249 template<typename eT>
|
max@0
|
1250 template<typename gen_type>
|
max@0
|
1251 inline
|
max@0
|
1252 const Cube<eT>&
|
max@0
|
1253 Cube<eT>::operator%=(const GenCube<eT, gen_type>& X)
|
max@0
|
1254 {
|
max@0
|
1255 arma_extra_debug_sigprint();
|
max@0
|
1256
|
max@0
|
1257 X.apply_inplace_schur(*this);
|
max@0
|
1258
|
max@0
|
1259 return *this;
|
max@0
|
1260 }
|
max@0
|
1261
|
max@0
|
1262
|
max@0
|
1263
|
max@0
|
1264 template<typename eT>
|
max@0
|
1265 template<typename gen_type>
|
max@0
|
1266 inline
|
max@0
|
1267 const Cube<eT>&
|
max@0
|
1268 Cube<eT>::operator/=(const GenCube<eT, gen_type>& X)
|
max@0
|
1269 {
|
max@0
|
1270 arma_extra_debug_sigprint();
|
max@0
|
1271
|
max@0
|
1272 X.apply_inplace_div(*this);
|
max@0
|
1273
|
max@0
|
1274 return *this;
|
max@0
|
1275 }
|
max@0
|
1276
|
max@0
|
1277
|
max@0
|
1278
|
max@0
|
1279 //! create a cube from OpCube, i.e. run the previously delayed unary operations
|
max@0
|
1280 template<typename eT>
|
max@0
|
1281 template<typename T1, typename op_type>
|
max@0
|
1282 inline
|
max@0
|
1283 Cube<eT>::Cube(const OpCube<T1, op_type>& X)
|
max@0
|
1284 : n_rows(0)
|
max@0
|
1285 , n_cols(0)
|
max@0
|
1286 , n_elem_slice(0)
|
max@0
|
1287 , n_slices(0)
|
max@0
|
1288 , n_elem(0)
|
max@0
|
1289 , mem_state(0)
|
max@0
|
1290 , mat_ptrs()
|
max@0
|
1291 , mem()
|
max@0
|
1292 {
|
max@0
|
1293 arma_extra_debug_sigprint_this(this);
|
max@0
|
1294
|
max@0
|
1295 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1296
|
max@0
|
1297 op_type::apply(*this, X);
|
max@0
|
1298 }
|
max@0
|
1299
|
max@0
|
1300
|
max@0
|
1301
|
max@0
|
1302 //! create a cube from OpCube, i.e. run the previously delayed unary operations
|
max@0
|
1303 template<typename eT>
|
max@0
|
1304 template<typename T1, typename op_type>
|
max@0
|
1305 inline
|
max@0
|
1306 const Cube<eT>&
|
max@0
|
1307 Cube<eT>::operator=(const OpCube<T1, op_type>& X)
|
max@0
|
1308 {
|
max@0
|
1309 arma_extra_debug_sigprint();
|
max@0
|
1310
|
max@0
|
1311 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1312
|
max@0
|
1313 op_type::apply(*this, X);
|
max@0
|
1314
|
max@0
|
1315 return *this;
|
max@0
|
1316 }
|
max@0
|
1317
|
max@0
|
1318
|
max@0
|
1319
|
max@0
|
1320 //! in-place cube addition, with the right-hand-side operand having delayed operations
|
max@0
|
1321 template<typename eT>
|
max@0
|
1322 template<typename T1, typename op_type>
|
max@0
|
1323 inline
|
max@0
|
1324 const Cube<eT>&
|
max@0
|
1325 Cube<eT>::operator+=(const OpCube<T1, op_type>& X)
|
max@0
|
1326 {
|
max@0
|
1327 arma_extra_debug_sigprint();
|
max@0
|
1328
|
max@0
|
1329 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1330
|
max@0
|
1331 const Cube<eT> m(X);
|
max@0
|
1332
|
max@0
|
1333 return (*this).operator+=(m);
|
max@0
|
1334 }
|
max@0
|
1335
|
max@0
|
1336
|
max@0
|
1337
|
max@0
|
1338 //! in-place cube subtraction, with the right-hand-side operand having delayed operations
|
max@0
|
1339 template<typename eT>
|
max@0
|
1340 template<typename T1, typename op_type>
|
max@0
|
1341 inline
|
max@0
|
1342 const Cube<eT>&
|
max@0
|
1343 Cube<eT>::operator-=(const OpCube<T1, op_type>& X)
|
max@0
|
1344 {
|
max@0
|
1345 arma_extra_debug_sigprint();
|
max@0
|
1346
|
max@0
|
1347 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1348
|
max@0
|
1349 const Cube<eT> m(X);
|
max@0
|
1350
|
max@0
|
1351 return (*this).operator-=(m);
|
max@0
|
1352 }
|
max@0
|
1353
|
max@0
|
1354
|
max@0
|
1355
|
max@0
|
1356 //! in-place cube element-wise multiplication, with the right-hand-side operand having delayed operations
|
max@0
|
1357 template<typename eT>
|
max@0
|
1358 template<typename T1, typename op_type>
|
max@0
|
1359 inline
|
max@0
|
1360 const Cube<eT>&
|
max@0
|
1361 Cube<eT>::operator%=(const OpCube<T1, op_type>& X)
|
max@0
|
1362 {
|
max@0
|
1363 arma_extra_debug_sigprint();
|
max@0
|
1364
|
max@0
|
1365 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1366
|
max@0
|
1367 const Cube<eT> m(X);
|
max@0
|
1368
|
max@0
|
1369 return (*this).operator%=(m);
|
max@0
|
1370 }
|
max@0
|
1371
|
max@0
|
1372
|
max@0
|
1373
|
max@0
|
1374 //! in-place cube element-wise division, with the right-hand-side operand having delayed operations
|
max@0
|
1375 template<typename eT>
|
max@0
|
1376 template<typename T1, typename op_type>
|
max@0
|
1377 inline
|
max@0
|
1378 const Cube<eT>&
|
max@0
|
1379 Cube<eT>::operator/=(const OpCube<T1, op_type>& X)
|
max@0
|
1380 {
|
max@0
|
1381 arma_extra_debug_sigprint();
|
max@0
|
1382
|
max@0
|
1383 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1384
|
max@0
|
1385 const Cube<eT> m(X);
|
max@0
|
1386
|
max@0
|
1387 return (*this).operator/=(m);
|
max@0
|
1388 }
|
max@0
|
1389
|
max@0
|
1390
|
max@0
|
1391
|
max@0
|
1392 //! create a cube from eOpCube, i.e. run the previously delayed unary operations
|
max@0
|
1393 template<typename eT>
|
max@0
|
1394 template<typename T1, typename eop_type>
|
max@0
|
1395 inline
|
max@0
|
1396 Cube<eT>::Cube(const eOpCube<T1, eop_type>& X)
|
max@0
|
1397 : n_rows(X.get_n_rows())
|
max@0
|
1398 , n_cols(X.get_n_cols())
|
max@0
|
1399 , n_elem_slice(X.get_n_elem_slice())
|
max@0
|
1400 , n_slices(X.get_n_slices())
|
max@0
|
1401 , n_elem(X.get_n_elem())
|
max@0
|
1402 , mem_state(0)
|
max@0
|
1403 , mat_ptrs()
|
max@0
|
1404 , mem()
|
max@0
|
1405 {
|
max@0
|
1406 arma_extra_debug_sigprint_this(this);
|
max@0
|
1407
|
max@0
|
1408 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1409
|
max@0
|
1410 init_cold();
|
max@0
|
1411
|
max@0
|
1412 eop_type::apply(*this, X);
|
max@0
|
1413 }
|
max@0
|
1414
|
max@0
|
1415
|
max@0
|
1416
|
max@0
|
1417 //! create a cube from eOpCube, i.e. run the previously delayed unary operations
|
max@0
|
1418 template<typename eT>
|
max@0
|
1419 template<typename T1, typename eop_type>
|
max@0
|
1420 inline
|
max@0
|
1421 const Cube<eT>&
|
max@0
|
1422 Cube<eT>::operator=(const eOpCube<T1, eop_type>& X)
|
max@0
|
1423 {
|
max@0
|
1424 arma_extra_debug_sigprint();
|
max@0
|
1425
|
max@0
|
1426 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1427
|
max@0
|
1428 const bool bad_alias = ( X.P.has_subview && X.P.is_alias(*this) );
|
max@0
|
1429
|
max@0
|
1430 if(bad_alias == false)
|
max@0
|
1431 {
|
max@0
|
1432 init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices());
|
max@0
|
1433
|
max@0
|
1434 eop_type::apply(*this, X);
|
max@0
|
1435 }
|
max@0
|
1436 else
|
max@0
|
1437 {
|
max@0
|
1438 Cube<eT> tmp(X);
|
max@0
|
1439
|
max@0
|
1440 steal_mem(tmp);
|
max@0
|
1441 }
|
max@0
|
1442
|
max@0
|
1443 return *this;
|
max@0
|
1444 }
|
max@0
|
1445
|
max@0
|
1446
|
max@0
|
1447
|
max@0
|
1448 //! in-place cube addition, with the right-hand-side operand having delayed operations
|
max@0
|
1449 template<typename eT>
|
max@0
|
1450 template<typename T1, typename eop_type>
|
max@0
|
1451 inline
|
max@0
|
1452 const Cube<eT>&
|
max@0
|
1453 Cube<eT>::operator+=(const eOpCube<T1, eop_type>& X)
|
max@0
|
1454 {
|
max@0
|
1455 arma_extra_debug_sigprint();
|
max@0
|
1456
|
max@0
|
1457 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1458
|
max@0
|
1459 eop_type::apply_inplace_plus(*this, X);
|
max@0
|
1460
|
max@0
|
1461 return *this;
|
max@0
|
1462 }
|
max@0
|
1463
|
max@0
|
1464
|
max@0
|
1465
|
max@0
|
1466 //! in-place cube subtraction, with the right-hand-side operand having delayed operations
|
max@0
|
1467 template<typename eT>
|
max@0
|
1468 template<typename T1, typename eop_type>
|
max@0
|
1469 inline
|
max@0
|
1470 const Cube<eT>&
|
max@0
|
1471 Cube<eT>::operator-=(const eOpCube<T1, eop_type>& X)
|
max@0
|
1472 {
|
max@0
|
1473 arma_extra_debug_sigprint();
|
max@0
|
1474
|
max@0
|
1475 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1476
|
max@0
|
1477 eop_type::apply_inplace_minus(*this, X);
|
max@0
|
1478
|
max@0
|
1479 return *this;
|
max@0
|
1480 }
|
max@0
|
1481
|
max@0
|
1482
|
max@0
|
1483
|
max@0
|
1484 //! in-place cube element-wise multiplication, with the right-hand-side operand having delayed operations
|
max@0
|
1485 template<typename eT>
|
max@0
|
1486 template<typename T1, typename eop_type>
|
max@0
|
1487 inline
|
max@0
|
1488 const Cube<eT>&
|
max@0
|
1489 Cube<eT>::operator%=(const eOpCube<T1, eop_type>& X)
|
max@0
|
1490 {
|
max@0
|
1491 arma_extra_debug_sigprint();
|
max@0
|
1492
|
max@0
|
1493 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1494
|
max@0
|
1495 eop_type::apply_inplace_schur(*this, X);
|
max@0
|
1496
|
max@0
|
1497 return *this;
|
max@0
|
1498 }
|
max@0
|
1499
|
max@0
|
1500
|
max@0
|
1501
|
max@0
|
1502 //! in-place cube element-wise division, with the right-hand-side operand having delayed operations
|
max@0
|
1503 template<typename eT>
|
max@0
|
1504 template<typename T1, typename eop_type>
|
max@0
|
1505 inline
|
max@0
|
1506 const Cube<eT>&
|
max@0
|
1507 Cube<eT>::operator/=(const eOpCube<T1, eop_type>& X)
|
max@0
|
1508 {
|
max@0
|
1509 arma_extra_debug_sigprint();
|
max@0
|
1510
|
max@0
|
1511 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1512
|
max@0
|
1513 eop_type::apply_inplace_div(*this, X);
|
max@0
|
1514
|
max@0
|
1515 return *this;
|
max@0
|
1516 }
|
max@0
|
1517
|
max@0
|
1518
|
max@0
|
1519
|
max@0
|
1520 //! EXPERIMENTAL
|
max@0
|
1521 template<typename eT>
|
max@0
|
1522 template<typename T1, typename op_type>
|
max@0
|
1523 inline
|
max@0
|
1524 Cube<eT>::Cube(const mtOpCube<eT, T1, op_type>& X)
|
max@0
|
1525 : n_rows(0)
|
max@0
|
1526 , n_cols(0)
|
max@0
|
1527 , n_elem_slice(0)
|
max@0
|
1528 , n_slices(0)
|
max@0
|
1529 , n_elem(0)
|
max@0
|
1530 , mem_state(0)
|
max@0
|
1531 , mat_ptrs()
|
max@0
|
1532 , mem()
|
max@0
|
1533 {
|
max@0
|
1534 arma_extra_debug_sigprint_this(this);
|
max@0
|
1535
|
max@0
|
1536 op_type::apply(*this, X);
|
max@0
|
1537 }
|
max@0
|
1538
|
max@0
|
1539
|
max@0
|
1540
|
max@0
|
1541 //! EXPERIMENTAL
|
max@0
|
1542 template<typename eT>
|
max@0
|
1543 template<typename T1, typename op_type>
|
max@0
|
1544 inline
|
max@0
|
1545 const Cube<eT>&
|
max@0
|
1546 Cube<eT>::operator=(const mtOpCube<eT, T1, op_type>& X)
|
max@0
|
1547 {
|
max@0
|
1548 arma_extra_debug_sigprint();
|
max@0
|
1549
|
max@0
|
1550 op_type::apply(*this, X);
|
max@0
|
1551
|
max@0
|
1552 return *this;
|
max@0
|
1553 }
|
max@0
|
1554
|
max@0
|
1555
|
max@0
|
1556
|
max@0
|
1557 //! EXPERIMENTAL
|
max@0
|
1558 template<typename eT>
|
max@0
|
1559 template<typename T1, typename op_type>
|
max@0
|
1560 inline
|
max@0
|
1561 const Cube<eT>&
|
max@0
|
1562 Cube<eT>::operator+=(const mtOpCube<eT, T1, op_type>& X)
|
max@0
|
1563 {
|
max@0
|
1564 arma_extra_debug_sigprint();
|
max@0
|
1565
|
max@0
|
1566 const Cube<eT> m(X);
|
max@0
|
1567
|
max@0
|
1568 return (*this).operator+=(m);
|
max@0
|
1569 }
|
max@0
|
1570
|
max@0
|
1571
|
max@0
|
1572
|
max@0
|
1573 //! EXPERIMENTAL
|
max@0
|
1574 template<typename eT>
|
max@0
|
1575 template<typename T1, typename op_type>
|
max@0
|
1576 inline
|
max@0
|
1577 const Cube<eT>&
|
max@0
|
1578 Cube<eT>::operator-=(const mtOpCube<eT, T1, op_type>& X)
|
max@0
|
1579 {
|
max@0
|
1580 arma_extra_debug_sigprint();
|
max@0
|
1581
|
max@0
|
1582 const Cube<eT> m(X);
|
max@0
|
1583
|
max@0
|
1584 return (*this).operator-=(m);
|
max@0
|
1585 }
|
max@0
|
1586
|
max@0
|
1587
|
max@0
|
1588
|
max@0
|
1589 //! EXPERIMENTAL
|
max@0
|
1590 template<typename eT>
|
max@0
|
1591 template<typename T1, typename op_type>
|
max@0
|
1592 inline
|
max@0
|
1593 const Cube<eT>&
|
max@0
|
1594 Cube<eT>::operator%=(const mtOpCube<eT, T1, op_type>& X)
|
max@0
|
1595 {
|
max@0
|
1596 arma_extra_debug_sigprint();
|
max@0
|
1597
|
max@0
|
1598 const Cube<eT> m(X);
|
max@0
|
1599
|
max@0
|
1600 return (*this).operator%=(m);
|
max@0
|
1601 }
|
max@0
|
1602
|
max@0
|
1603
|
max@0
|
1604
|
max@0
|
1605 //! EXPERIMENTAL
|
max@0
|
1606 template<typename eT>
|
max@0
|
1607 template<typename T1, typename op_type>
|
max@0
|
1608 inline
|
max@0
|
1609 const Cube<eT>&
|
max@0
|
1610 Cube<eT>::operator/=(const mtOpCube<eT, T1, op_type>& X)
|
max@0
|
1611 {
|
max@0
|
1612 arma_extra_debug_sigprint();
|
max@0
|
1613
|
max@0
|
1614 const Cube<eT> m(X);
|
max@0
|
1615
|
max@0
|
1616 return (*this).operator/=(m);
|
max@0
|
1617 }
|
max@0
|
1618
|
max@0
|
1619
|
max@0
|
1620
|
max@0
|
1621 //! create a cube from Glue, i.e. run the previously delayed binary operations
|
max@0
|
1622 template<typename eT>
|
max@0
|
1623 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1624 inline
|
max@0
|
1625 Cube<eT>::Cube(const GlueCube<T1, T2, glue_type>& X)
|
max@0
|
1626 : n_rows(0)
|
max@0
|
1627 , n_cols(0)
|
max@0
|
1628 , n_elem_slice(0)
|
max@0
|
1629 , n_slices(0)
|
max@0
|
1630 , n_elem(0)
|
max@0
|
1631 , mem_state(0)
|
max@0
|
1632 , mat_ptrs()
|
max@0
|
1633 , mem()
|
max@0
|
1634 {
|
max@0
|
1635 arma_extra_debug_sigprint_this(this);
|
max@0
|
1636 this->operator=(X);
|
max@0
|
1637 }
|
max@0
|
1638
|
max@0
|
1639
|
max@0
|
1640
|
max@0
|
1641 //! create a cube from Glue, i.e. run the previously delayed binary operations
|
max@0
|
1642 template<typename eT>
|
max@0
|
1643 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1644 inline
|
max@0
|
1645 const Cube<eT>&
|
max@0
|
1646 Cube<eT>::operator=(const GlueCube<T1, T2, glue_type>& X)
|
max@0
|
1647 {
|
max@0
|
1648 arma_extra_debug_sigprint();
|
max@0
|
1649
|
max@0
|
1650 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1651 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1652
|
max@0
|
1653 glue_type::apply(*this, X);
|
max@0
|
1654
|
max@0
|
1655 return *this;
|
max@0
|
1656 }
|
max@0
|
1657
|
max@0
|
1658
|
max@0
|
1659 //! in-place cube addition, with the right-hand-side operands having delayed operations
|
max@0
|
1660 template<typename eT>
|
max@0
|
1661 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1662 inline
|
max@0
|
1663 const Cube<eT>&
|
max@0
|
1664 Cube<eT>::operator+=(const GlueCube<T1, T2, glue_type>& X)
|
max@0
|
1665 {
|
max@0
|
1666 arma_extra_debug_sigprint();
|
max@0
|
1667
|
max@0
|
1668 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1669 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1670
|
max@0
|
1671 const Cube<eT> m(X);
|
max@0
|
1672
|
max@0
|
1673 return (*this).operator+=(m);
|
max@0
|
1674 }
|
max@0
|
1675
|
max@0
|
1676
|
max@0
|
1677
|
max@0
|
1678 //! in-place cube subtraction, with the right-hand-side operands having delayed operations
|
max@0
|
1679 template<typename eT>
|
max@0
|
1680 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1681 inline
|
max@0
|
1682 const Cube<eT>&
|
max@0
|
1683 Cube<eT>::operator-=(const GlueCube<T1, T2, glue_type>& X)
|
max@0
|
1684 {
|
max@0
|
1685 arma_extra_debug_sigprint();
|
max@0
|
1686
|
max@0
|
1687 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1688 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1689
|
max@0
|
1690 const Cube<eT> m(X);
|
max@0
|
1691
|
max@0
|
1692 return (*this).operator-=(m);
|
max@0
|
1693 }
|
max@0
|
1694
|
max@0
|
1695
|
max@0
|
1696
|
max@0
|
1697 //! in-place cube element-wise multiplication, with the right-hand-side operands having delayed operations
|
max@0
|
1698 template<typename eT>
|
max@0
|
1699 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1700 inline
|
max@0
|
1701 const Cube<eT>&
|
max@0
|
1702 Cube<eT>::operator%=(const GlueCube<T1, T2, glue_type>& X)
|
max@0
|
1703 {
|
max@0
|
1704 arma_extra_debug_sigprint();
|
max@0
|
1705
|
max@0
|
1706 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1707 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1708
|
max@0
|
1709 const Cube<eT> m(X);
|
max@0
|
1710
|
max@0
|
1711 return (*this).operator%=(m);
|
max@0
|
1712 }
|
max@0
|
1713
|
max@0
|
1714
|
max@0
|
1715
|
max@0
|
1716 //! in-place cube element-wise division, with the right-hand-side operands having delayed operations
|
max@0
|
1717 template<typename eT>
|
max@0
|
1718 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1719 inline
|
max@0
|
1720 const Cube<eT>&
|
max@0
|
1721 Cube<eT>::operator/=(const GlueCube<T1, T2, glue_type>& X)
|
max@0
|
1722 {
|
max@0
|
1723 arma_extra_debug_sigprint();
|
max@0
|
1724
|
max@0
|
1725 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1726 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1727
|
max@0
|
1728 const Cube<eT> m(X);
|
max@0
|
1729
|
max@0
|
1730 return (*this).operator/=(m);
|
max@0
|
1731 }
|
max@0
|
1732
|
max@0
|
1733
|
max@0
|
1734
|
max@0
|
1735 //! create a cube from eGlue, i.e. run the previously delayed binary operations
|
max@0
|
1736 template<typename eT>
|
max@0
|
1737 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
1738 inline
|
max@0
|
1739 Cube<eT>::Cube(const eGlueCube<T1, T2, eglue_type>& X)
|
max@0
|
1740 : n_rows(X.get_n_rows())
|
max@0
|
1741 , n_cols(X.get_n_cols())
|
max@0
|
1742 , n_elem_slice(X.get_n_elem_slice())
|
max@0
|
1743 , n_slices(X.get_n_slices())
|
max@0
|
1744 , n_elem(X.get_n_elem())
|
max@0
|
1745 , mem_state(0)
|
max@0
|
1746 , mat_ptrs()
|
max@0
|
1747 , mem()
|
max@0
|
1748 {
|
max@0
|
1749 arma_extra_debug_sigprint_this(this);
|
max@0
|
1750
|
max@0
|
1751 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1752 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1753
|
max@0
|
1754 init_cold();
|
max@0
|
1755
|
max@0
|
1756 eglue_type::apply(*this, X);
|
max@0
|
1757 }
|
max@0
|
1758
|
max@0
|
1759
|
max@0
|
1760
|
max@0
|
1761 //! create a cube from Glue, i.e. run the previously delayed binary operations
|
max@0
|
1762 template<typename eT>
|
max@0
|
1763 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
1764 inline
|
max@0
|
1765 const Cube<eT>&
|
max@0
|
1766 Cube<eT>::operator=(const eGlueCube<T1, T2, eglue_type>& X)
|
max@0
|
1767 {
|
max@0
|
1768 arma_extra_debug_sigprint();
|
max@0
|
1769
|
max@0
|
1770 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1771 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1772
|
max@0
|
1773 const bool bad_alias = ( (X.P1.has_subview && X.P1.is_alias(*this)) || (X.P2.has_subview && X.P2.is_alias(*this)) );
|
max@0
|
1774
|
max@0
|
1775 if(bad_alias == false)
|
max@0
|
1776 {
|
max@0
|
1777 init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices());
|
max@0
|
1778
|
max@0
|
1779 eglue_type::apply(*this, X);
|
max@0
|
1780 }
|
max@0
|
1781 else
|
max@0
|
1782 {
|
max@0
|
1783 Cube<eT> tmp(X);
|
max@0
|
1784
|
max@0
|
1785 steal_mem(tmp);
|
max@0
|
1786 }
|
max@0
|
1787
|
max@0
|
1788 return *this;
|
max@0
|
1789 }
|
max@0
|
1790
|
max@0
|
1791
|
max@0
|
1792
|
max@0
|
1793 //! in-place cube addition, with the right-hand-side operands having delayed operations
|
max@0
|
1794 template<typename eT>
|
max@0
|
1795 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
1796 inline
|
max@0
|
1797 const Cube<eT>&
|
max@0
|
1798 Cube<eT>::operator+=(const eGlueCube<T1, T2, eglue_type>& X)
|
max@0
|
1799 {
|
max@0
|
1800 arma_extra_debug_sigprint();
|
max@0
|
1801
|
max@0
|
1802 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1803 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1804
|
max@0
|
1805 eglue_type::apply_inplace_plus(*this, X);
|
max@0
|
1806
|
max@0
|
1807 return *this;
|
max@0
|
1808 }
|
max@0
|
1809
|
max@0
|
1810
|
max@0
|
1811
|
max@0
|
1812 //! in-place cube subtraction, with the right-hand-side operands having delayed operations
|
max@0
|
1813 template<typename eT>
|
max@0
|
1814 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
1815 inline
|
max@0
|
1816 const Cube<eT>&
|
max@0
|
1817 Cube<eT>::operator-=(const eGlueCube<T1, T2, eglue_type>& X)
|
max@0
|
1818 {
|
max@0
|
1819 arma_extra_debug_sigprint();
|
max@0
|
1820
|
max@0
|
1821 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1822 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1823
|
max@0
|
1824 eglue_type::apply_inplace_minus(*this, X);
|
max@0
|
1825
|
max@0
|
1826 return *this;
|
max@0
|
1827 }
|
max@0
|
1828
|
max@0
|
1829
|
max@0
|
1830
|
max@0
|
1831 //! in-place cube element-wise multiplication, with the right-hand-side operands having delayed operations
|
max@0
|
1832 template<typename eT>
|
max@0
|
1833 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
1834 inline
|
max@0
|
1835 const Cube<eT>&
|
max@0
|
1836 Cube<eT>::operator%=(const eGlueCube<T1, T2, eglue_type>& X)
|
max@0
|
1837 {
|
max@0
|
1838 arma_extra_debug_sigprint();
|
max@0
|
1839
|
max@0
|
1840 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1841 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1842
|
max@0
|
1843 eglue_type::apply_inplace_schur(*this, X);
|
max@0
|
1844
|
max@0
|
1845 return *this;
|
max@0
|
1846 }
|
max@0
|
1847
|
max@0
|
1848
|
max@0
|
1849
|
max@0
|
1850 //! in-place cube element-wise division, with the right-hand-side operands having delayed operations
|
max@0
|
1851 template<typename eT>
|
max@0
|
1852 template<typename T1, typename T2, typename eglue_type>
|
max@0
|
1853 inline
|
max@0
|
1854 const Cube<eT>&
|
max@0
|
1855 Cube<eT>::operator/=(const eGlueCube<T1, T2, eglue_type>& X)
|
max@0
|
1856 {
|
max@0
|
1857 arma_extra_debug_sigprint();
|
max@0
|
1858
|
max@0
|
1859 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
|
max@0
|
1860 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false ));
|
max@0
|
1861
|
max@0
|
1862 eglue_type::apply_inplace_div(*this, X);
|
max@0
|
1863
|
max@0
|
1864 return *this;
|
max@0
|
1865 }
|
max@0
|
1866
|
max@0
|
1867
|
max@0
|
1868
|
max@0
|
1869 //! EXPERIMENTAL
|
max@0
|
1870 template<typename eT>
|
max@0
|
1871 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1872 inline
|
max@0
|
1873 Cube<eT>::Cube(const mtGlueCube<eT, T1, T2, glue_type>& X)
|
max@0
|
1874 : n_rows(0)
|
max@0
|
1875 , n_cols(0)
|
max@0
|
1876 , n_elem_slice(0)
|
max@0
|
1877 , n_slices(0)
|
max@0
|
1878 , n_elem(0)
|
max@0
|
1879 , mem_state(0)
|
max@0
|
1880 , mat_ptrs()
|
max@0
|
1881 , mem()
|
max@0
|
1882 {
|
max@0
|
1883 arma_extra_debug_sigprint_this(this);
|
max@0
|
1884
|
max@0
|
1885 glue_type::apply(*this, X);
|
max@0
|
1886 }
|
max@0
|
1887
|
max@0
|
1888
|
max@0
|
1889
|
max@0
|
1890 //! EXPERIMENTAL
|
max@0
|
1891 template<typename eT>
|
max@0
|
1892 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1893 inline
|
max@0
|
1894 const Cube<eT>&
|
max@0
|
1895 Cube<eT>::operator=(const mtGlueCube<eT, T1, T2, glue_type>& X)
|
max@0
|
1896 {
|
max@0
|
1897 arma_extra_debug_sigprint();
|
max@0
|
1898
|
max@0
|
1899 glue_type::apply(*this, X);
|
max@0
|
1900
|
max@0
|
1901 return *this;
|
max@0
|
1902 }
|
max@0
|
1903
|
max@0
|
1904
|
max@0
|
1905
|
max@0
|
1906 //! EXPERIMENTAL
|
max@0
|
1907 template<typename eT>
|
max@0
|
1908 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1909 inline
|
max@0
|
1910 const Cube<eT>&
|
max@0
|
1911 Cube<eT>::operator+=(const mtGlueCube<eT, T1, T2, glue_type>& X)
|
max@0
|
1912 {
|
max@0
|
1913 arma_extra_debug_sigprint();
|
max@0
|
1914
|
max@0
|
1915 const Cube<eT> m(X);
|
max@0
|
1916
|
max@0
|
1917 return (*this).operator+=(m);
|
max@0
|
1918 }
|
max@0
|
1919
|
max@0
|
1920
|
max@0
|
1921
|
max@0
|
1922 //! EXPERIMENTAL
|
max@0
|
1923 template<typename eT>
|
max@0
|
1924 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1925 inline
|
max@0
|
1926 const Cube<eT>&
|
max@0
|
1927 Cube<eT>::operator-=(const mtGlueCube<eT, T1, T2, glue_type>& X)
|
max@0
|
1928 {
|
max@0
|
1929 arma_extra_debug_sigprint();
|
max@0
|
1930
|
max@0
|
1931 const Cube<eT> m(X);
|
max@0
|
1932
|
max@0
|
1933 return (*this).operator-=(m);
|
max@0
|
1934 }
|
max@0
|
1935
|
max@0
|
1936
|
max@0
|
1937
|
max@0
|
1938 //! EXPERIMENTAL
|
max@0
|
1939 template<typename eT>
|
max@0
|
1940 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1941 inline
|
max@0
|
1942 const Cube<eT>&
|
max@0
|
1943 Cube<eT>::operator%=(const mtGlueCube<eT, T1, T2, glue_type>& X)
|
max@0
|
1944 {
|
max@0
|
1945 arma_extra_debug_sigprint();
|
max@0
|
1946
|
max@0
|
1947 const Cube<eT> m(X);
|
max@0
|
1948
|
max@0
|
1949 return (*this).operator%=(m);
|
max@0
|
1950 }
|
max@0
|
1951
|
max@0
|
1952
|
max@0
|
1953
|
max@0
|
1954 //! EXPERIMENTAL
|
max@0
|
1955 template<typename eT>
|
max@0
|
1956 template<typename T1, typename T2, typename glue_type>
|
max@0
|
1957 inline
|
max@0
|
1958 const Cube<eT>&
|
max@0
|
1959 Cube<eT>::operator/=(const mtGlueCube<eT, T1, T2, glue_type>& X)
|
max@0
|
1960 {
|
max@0
|
1961 arma_extra_debug_sigprint();
|
max@0
|
1962
|
max@0
|
1963 const Cube<eT> m(X);
|
max@0
|
1964
|
max@0
|
1965 return (*this).operator/=(m);
|
max@0
|
1966 }
|
max@0
|
1967
|
max@0
|
1968
|
max@0
|
1969
|
max@0
|
1970 //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
|
max@0
|
1971 template<typename eT>
|
max@0
|
1972 arma_inline
|
max@0
|
1973 arma_warn_unused
|
max@0
|
1974 eT&
|
max@0
|
1975 Cube<eT>::operator() (const uword i)
|
max@0
|
1976 {
|
max@0
|
1977 arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds");
|
max@0
|
1978 return access::rw(mem[i]);
|
max@0
|
1979 }
|
max@0
|
1980
|
max@0
|
1981
|
max@0
|
1982
|
max@0
|
1983 //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
|
max@0
|
1984 template<typename eT>
|
max@0
|
1985 arma_inline
|
max@0
|
1986 arma_warn_unused
|
max@0
|
1987 eT
|
max@0
|
1988 Cube<eT>::operator() (const uword i) const
|
max@0
|
1989 {
|
max@0
|
1990 arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds");
|
max@0
|
1991 return mem[i];
|
max@0
|
1992 }
|
max@0
|
1993
|
max@0
|
1994
|
max@0
|
1995 //! linear element accessor (treats the cube as a vector); no bounds check.
|
max@0
|
1996 template<typename eT>
|
max@0
|
1997 arma_inline
|
max@0
|
1998 arma_warn_unused
|
max@0
|
1999 eT&
|
max@0
|
2000 Cube<eT>::operator[] (const uword i)
|
max@0
|
2001 {
|
max@0
|
2002 return access::rw(mem[i]);
|
max@0
|
2003 }
|
max@0
|
2004
|
max@0
|
2005
|
max@0
|
2006
|
max@0
|
2007 //! linear element accessor (treats the cube as a vector); no bounds check
|
max@0
|
2008 template<typename eT>
|
max@0
|
2009 arma_inline
|
max@0
|
2010 arma_warn_unused
|
max@0
|
2011 eT
|
max@0
|
2012 Cube<eT>::operator[] (const uword i) const
|
max@0
|
2013 {
|
max@0
|
2014 return mem[i];
|
max@0
|
2015 }
|
max@0
|
2016
|
max@0
|
2017
|
max@0
|
2018
|
max@0
|
2019 //! linear element accessor (treats the cube as a vector); no bounds check.
|
max@0
|
2020 template<typename eT>
|
max@0
|
2021 arma_inline
|
max@0
|
2022 arma_warn_unused
|
max@0
|
2023 eT&
|
max@0
|
2024 Cube<eT>::at(const uword i)
|
max@0
|
2025 {
|
max@0
|
2026 return access::rw(mem[i]);
|
max@0
|
2027 }
|
max@0
|
2028
|
max@0
|
2029
|
max@0
|
2030
|
max@0
|
2031 //! linear element accessor (treats the cube as a vector); no bounds check
|
max@0
|
2032 template<typename eT>
|
max@0
|
2033 arma_inline
|
max@0
|
2034 arma_warn_unused
|
max@0
|
2035 eT
|
max@0
|
2036 Cube<eT>::at(const uword i) const
|
max@0
|
2037 {
|
max@0
|
2038 return mem[i];
|
max@0
|
2039 }
|
max@0
|
2040
|
max@0
|
2041
|
max@0
|
2042
|
max@0
|
2043 //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
|
max@0
|
2044 template<typename eT>
|
max@0
|
2045 arma_inline
|
max@0
|
2046 arma_warn_unused
|
max@0
|
2047 eT&
|
max@0
|
2048 Cube<eT>::operator() (const uword in_row, const uword in_col, const uword in_slice)
|
max@0
|
2049 {
|
max@0
|
2050 arma_debug_check
|
max@0
|
2051 (
|
max@0
|
2052 (in_row >= n_rows) ||
|
max@0
|
2053 (in_col >= n_cols) ||
|
max@0
|
2054 (in_slice >= n_slices)
|
max@0
|
2055 ,
|
max@0
|
2056 "Cube::operator(): index out of bounds"
|
max@0
|
2057 );
|
max@0
|
2058
|
max@0
|
2059 return access::rw(mem[in_slice*n_elem_slice + in_col*n_rows + in_row]);
|
max@0
|
2060 }
|
max@0
|
2061
|
max@0
|
2062
|
max@0
|
2063
|
max@0
|
2064 //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
|
max@0
|
2065 template<typename eT>
|
max@0
|
2066 arma_inline
|
max@0
|
2067 arma_warn_unused
|
max@0
|
2068 eT
|
max@0
|
2069 Cube<eT>::operator() (const uword in_row, const uword in_col, const uword in_slice) const
|
max@0
|
2070 {
|
max@0
|
2071 arma_debug_check
|
max@0
|
2072 (
|
max@0
|
2073 (in_row >= n_rows) ||
|
max@0
|
2074 (in_col >= n_cols) ||
|
max@0
|
2075 (in_slice >= n_slices)
|
max@0
|
2076 ,
|
max@0
|
2077 "Cube::operator(): index out of bounds"
|
max@0
|
2078 );
|
max@0
|
2079
|
max@0
|
2080 return mem[in_slice*n_elem_slice + in_col*n_rows + in_row];
|
max@0
|
2081 }
|
max@0
|
2082
|
max@0
|
2083
|
max@0
|
2084
|
max@0
|
2085 //! element accessor; no bounds check
|
max@0
|
2086 template<typename eT>
|
max@0
|
2087 arma_inline
|
max@0
|
2088 arma_warn_unused
|
max@0
|
2089 eT&
|
max@0
|
2090 Cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice)
|
max@0
|
2091 {
|
max@0
|
2092 return access::rw( mem[in_slice*n_elem_slice + in_col*n_rows + in_row] );
|
max@0
|
2093 }
|
max@0
|
2094
|
max@0
|
2095
|
max@0
|
2096
|
max@0
|
2097 //! element accessor; no bounds check
|
max@0
|
2098 template<typename eT>
|
max@0
|
2099 arma_inline
|
max@0
|
2100 arma_warn_unused
|
max@0
|
2101 eT
|
max@0
|
2102 Cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice) const
|
max@0
|
2103 {
|
max@0
|
2104 return mem[in_slice*n_elem_slice + in_col*n_rows + in_row];
|
max@0
|
2105 }
|
max@0
|
2106
|
max@0
|
2107
|
max@0
|
2108
|
max@0
|
2109 //! prefix ++
|
max@0
|
2110 template<typename eT>
|
max@0
|
2111 arma_inline
|
max@0
|
2112 const Cube<eT>&
|
max@0
|
2113 Cube<eT>::operator++()
|
max@0
|
2114 {
|
max@0
|
2115 Cube_aux::prefix_pp(*this);
|
max@0
|
2116 return *this;
|
max@0
|
2117 }
|
max@0
|
2118
|
max@0
|
2119
|
max@0
|
2120
|
max@0
|
2121 //! postfix ++ (must not return the object by reference)
|
max@0
|
2122 template<typename eT>
|
max@0
|
2123 arma_inline
|
max@0
|
2124 void
|
max@0
|
2125 Cube<eT>::operator++(int)
|
max@0
|
2126 {
|
max@0
|
2127 Cube_aux::postfix_pp(*this);
|
max@0
|
2128 }
|
max@0
|
2129
|
max@0
|
2130
|
max@0
|
2131
|
max@0
|
2132 //! prefix --
|
max@0
|
2133 template<typename eT>
|
max@0
|
2134 arma_inline
|
max@0
|
2135 const Cube<eT>&
|
max@0
|
2136 Cube<eT>::operator--()
|
max@0
|
2137 {
|
max@0
|
2138 Cube_aux::prefix_mm(*this);
|
max@0
|
2139 return *this;
|
max@0
|
2140 }
|
max@0
|
2141
|
max@0
|
2142
|
max@0
|
2143
|
max@0
|
2144 //! postfix -- (must not return the object by reference)
|
max@0
|
2145 template<typename eT>
|
max@0
|
2146 arma_inline
|
max@0
|
2147 void
|
max@0
|
2148 Cube<eT>::operator--(int)
|
max@0
|
2149 {
|
max@0
|
2150 Cube_aux::postfix_mm(*this);
|
max@0
|
2151 }
|
max@0
|
2152
|
max@0
|
2153
|
max@0
|
2154
|
max@0
|
2155 //! returns true if all of the elements are finite
|
max@0
|
2156 template<typename eT>
|
max@0
|
2157 arma_inline
|
max@0
|
2158 arma_warn_unused
|
max@0
|
2159 bool
|
max@0
|
2160 Cube<eT>::is_finite() const
|
max@0
|
2161 {
|
max@0
|
2162 return arrayops::is_finite( memptr(), n_elem );
|
max@0
|
2163 }
|
max@0
|
2164
|
max@0
|
2165
|
max@0
|
2166
|
max@0
|
2167 //! returns true if the cube has no elements
|
max@0
|
2168 template<typename eT>
|
max@0
|
2169 arma_inline
|
max@0
|
2170 arma_warn_unused
|
max@0
|
2171 bool
|
max@0
|
2172 Cube<eT>::is_empty() const
|
max@0
|
2173 {
|
max@0
|
2174 return (n_elem == 0);
|
max@0
|
2175 }
|
max@0
|
2176
|
max@0
|
2177
|
max@0
|
2178
|
max@0
|
2179 //! returns true if the given index is currently in range
|
max@0
|
2180 template<typename eT>
|
max@0
|
2181 arma_inline
|
max@0
|
2182 arma_warn_unused
|
max@0
|
2183 bool
|
max@0
|
2184 Cube<eT>::in_range(const uword i) const
|
max@0
|
2185 {
|
max@0
|
2186 return (i < n_elem);
|
max@0
|
2187 }
|
max@0
|
2188
|
max@0
|
2189
|
max@0
|
2190
|
max@0
|
2191 //! returns true if the given start and end indices are currently in range
|
max@0
|
2192 template<typename eT>
|
max@0
|
2193 arma_inline
|
max@0
|
2194 arma_warn_unused
|
max@0
|
2195 bool
|
max@0
|
2196 Cube<eT>::in_range(const span& x) const
|
max@0
|
2197 {
|
max@0
|
2198 arma_extra_debug_sigprint();
|
max@0
|
2199
|
max@0
|
2200 if(x.whole == true)
|
max@0
|
2201 {
|
max@0
|
2202 return true;
|
max@0
|
2203 }
|
max@0
|
2204 else
|
max@0
|
2205 {
|
max@0
|
2206 const uword a = x.a;
|
max@0
|
2207 const uword b = x.b;
|
max@0
|
2208
|
max@0
|
2209 return ( (a <= b) && (b < n_elem) );
|
max@0
|
2210 }
|
max@0
|
2211 }
|
max@0
|
2212
|
max@0
|
2213
|
max@0
|
2214
|
max@0
|
2215 //! returns true if the given location is currently in range
|
max@0
|
2216 template<typename eT>
|
max@0
|
2217 arma_inline
|
max@0
|
2218 arma_warn_unused
|
max@0
|
2219 bool
|
max@0
|
2220 Cube<eT>::in_range(const uword in_row, const uword in_col, const uword in_slice) const
|
max@0
|
2221 {
|
max@0
|
2222 return ( (in_row < n_rows) && (in_col < n_cols) && (in_slice < n_slices) );
|
max@0
|
2223 }
|
max@0
|
2224
|
max@0
|
2225
|
max@0
|
2226
|
max@0
|
2227 template<typename eT>
|
max@0
|
2228 inline
|
max@0
|
2229 arma_warn_unused
|
max@0
|
2230 bool
|
max@0
|
2231 Cube<eT>::in_range(const span& row_span, const span& col_span, const span& slice_span) const
|
max@0
|
2232 {
|
max@0
|
2233 arma_extra_debug_sigprint();
|
max@0
|
2234
|
max@0
|
2235 const uword in_row1 = row_span.a;
|
max@0
|
2236 const uword in_row2 = row_span.b;
|
max@0
|
2237
|
max@0
|
2238 const uword in_col1 = col_span.a;
|
max@0
|
2239 const uword in_col2 = col_span.b;
|
max@0
|
2240
|
max@0
|
2241 const uword in_slice1 = slice_span.a;
|
max@0
|
2242 const uword in_slice2 = slice_span.b;
|
max@0
|
2243
|
max@0
|
2244
|
max@0
|
2245 const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) );
|
max@0
|
2246 const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) );
|
max@0
|
2247 const bool slices_ok = slice_span.whole ? true : ( (in_slice1 <= in_slice2) && (in_slice2 < n_slices) );
|
max@0
|
2248
|
max@0
|
2249
|
max@0
|
2250 return ( (rows_ok == true) && (cols_ok == true) && (slices_ok == true) );
|
max@0
|
2251 }
|
max@0
|
2252
|
max@0
|
2253
|
max@0
|
2254
|
max@0
|
2255 //! returns a pointer to array of eTs used by the cube
|
max@0
|
2256 template<typename eT>
|
max@0
|
2257 arma_inline
|
max@0
|
2258 arma_warn_unused
|
max@0
|
2259 eT*
|
max@0
|
2260 Cube<eT>::memptr()
|
max@0
|
2261 {
|
max@0
|
2262 return const_cast<eT*>(mem);
|
max@0
|
2263 }
|
max@0
|
2264
|
max@0
|
2265
|
max@0
|
2266
|
max@0
|
2267 //! returns a pointer to array of eTs used by the cube
|
max@0
|
2268 template<typename eT>
|
max@0
|
2269 arma_inline
|
max@0
|
2270 arma_warn_unused
|
max@0
|
2271 const eT*
|
max@0
|
2272 Cube<eT>::memptr() const
|
max@0
|
2273 {
|
max@0
|
2274 return mem;
|
max@0
|
2275 }
|
max@0
|
2276
|
max@0
|
2277
|
max@0
|
2278
|
max@0
|
2279 //! returns a pointer to array of eTs used by the specified slice in the cube
|
max@0
|
2280 template<typename eT>
|
max@0
|
2281 arma_inline
|
max@0
|
2282 arma_warn_unused
|
max@0
|
2283 eT*
|
max@0
|
2284 Cube<eT>::slice_memptr(const uword slice)
|
max@0
|
2285 {
|
max@0
|
2286 return const_cast<eT*>( &mem[ slice*n_elem_slice ] );
|
max@0
|
2287 }
|
max@0
|
2288
|
max@0
|
2289
|
max@0
|
2290
|
max@0
|
2291 //! returns a pointer to array of eTs used by the specified slice in the cube
|
max@0
|
2292 template<typename eT>
|
max@0
|
2293 arma_inline
|
max@0
|
2294 arma_warn_unused
|
max@0
|
2295 const eT*
|
max@0
|
2296 Cube<eT>::slice_memptr(const uword slice) const
|
max@0
|
2297 {
|
max@0
|
2298 return &mem[ slice*n_elem_slice ];
|
max@0
|
2299 }
|
max@0
|
2300
|
max@0
|
2301
|
max@0
|
2302
|
max@0
|
2303 //! returns a pointer to array of eTs used by the specified slice in the cube
|
max@0
|
2304 template<typename eT>
|
max@0
|
2305 arma_inline
|
max@0
|
2306 arma_warn_unused
|
max@0
|
2307 eT*
|
max@0
|
2308 Cube<eT>::slice_colptr(const uword slice, const uword col)
|
max@0
|
2309 {
|
max@0
|
2310 return const_cast<eT*>( &mem[ slice*n_elem_slice + col*n_rows] );
|
max@0
|
2311 }
|
max@0
|
2312
|
max@0
|
2313
|
max@0
|
2314
|
max@0
|
2315 //! returns a pointer to array of eTs used by the specified slice in the cube
|
max@0
|
2316 template<typename eT>
|
max@0
|
2317 arma_inline
|
max@0
|
2318 arma_warn_unused
|
max@0
|
2319 const eT*
|
max@0
|
2320 Cube<eT>::slice_colptr(const uword slice, const uword col) const
|
max@0
|
2321 {
|
max@0
|
2322 return &mem[ slice*n_elem_slice + col*n_rows ];
|
max@0
|
2323 }
|
max@0
|
2324
|
max@0
|
2325
|
max@0
|
2326
|
max@0
|
2327 //! print contents of the cube (to the cout stream),
|
max@0
|
2328 //! optionally preceding with a user specified line of text.
|
max@0
|
2329 //! the precision and cell width are modified.
|
max@0
|
2330 //! on return, the stream's state are restored to their original values.
|
max@0
|
2331 template<typename eT>
|
max@0
|
2332 inline
|
max@0
|
2333 void
|
max@0
|
2334 Cube<eT>::impl_print(const std::string& extra_text) const
|
max@0
|
2335 {
|
max@0
|
2336 arma_extra_debug_sigprint();
|
max@0
|
2337
|
max@0
|
2338 if(extra_text.length() != 0)
|
max@0
|
2339 {
|
max@0
|
2340 ARMA_DEFAULT_OSTREAM << extra_text << '\n';
|
max@0
|
2341 }
|
max@0
|
2342
|
max@0
|
2343 arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true);
|
max@0
|
2344 }
|
max@0
|
2345
|
max@0
|
2346
|
max@0
|
2347 //! print contents of the cube to a user specified stream,
|
max@0
|
2348 //! optionally preceding with a user specified line of text.
|
max@0
|
2349 //! the precision and cell width are modified.
|
max@0
|
2350 //! on return, the stream's state are restored to their original values.
|
max@0
|
2351 template<typename eT>
|
max@0
|
2352 inline
|
max@0
|
2353 void
|
max@0
|
2354 Cube<eT>::impl_print(std::ostream& user_stream, const std::string& extra_text) const
|
max@0
|
2355 {
|
max@0
|
2356 arma_extra_debug_sigprint();
|
max@0
|
2357
|
max@0
|
2358 if(extra_text.length() != 0)
|
max@0
|
2359 {
|
max@0
|
2360 user_stream << extra_text << '\n';
|
max@0
|
2361 }
|
max@0
|
2362
|
max@0
|
2363 arma_ostream::print(user_stream, *this, true);
|
max@0
|
2364 }
|
max@0
|
2365
|
max@0
|
2366
|
max@0
|
2367
|
max@0
|
2368 //! print contents of the cube (to the cout stream),
|
max@0
|
2369 //! optionally preceding with a user specified line of text.
|
max@0
|
2370 //! the stream's state are used as is and are not modified
|
max@0
|
2371 //! (i.e. the precision and cell width are not modified).
|
max@0
|
2372 template<typename eT>
|
max@0
|
2373 inline
|
max@0
|
2374 void
|
max@0
|
2375 Cube<eT>::impl_raw_print(const std::string& extra_text) const
|
max@0
|
2376 {
|
max@0
|
2377 arma_extra_debug_sigprint();
|
max@0
|
2378
|
max@0
|
2379 if(extra_text.length() != 0)
|
max@0
|
2380 {
|
max@0
|
2381 ARMA_DEFAULT_OSTREAM << extra_text << '\n';
|
max@0
|
2382 }
|
max@0
|
2383
|
max@0
|
2384 arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false);
|
max@0
|
2385 }
|
max@0
|
2386
|
max@0
|
2387
|
max@0
|
2388
|
max@0
|
2389 //! print contents of the cube to a user specified stream,
|
max@0
|
2390 //! optionally preceding with a user specified line of text.
|
max@0
|
2391 //! the stream's state are used as is and are not modified.
|
max@0
|
2392 //! (i.e. the precision and cell width are not modified).
|
max@0
|
2393 template<typename eT>
|
max@0
|
2394 inline
|
max@0
|
2395 void
|
max@0
|
2396 Cube<eT>::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const
|
max@0
|
2397 {
|
max@0
|
2398 arma_extra_debug_sigprint();
|
max@0
|
2399
|
max@0
|
2400 if(extra_text.length() != 0)
|
max@0
|
2401 {
|
max@0
|
2402 user_stream << extra_text << '\n';
|
max@0
|
2403 }
|
max@0
|
2404
|
max@0
|
2405 arma_ostream::print(user_stream, *this, false);
|
max@0
|
2406 }
|
max@0
|
2407
|
max@0
|
2408
|
max@0
|
2409
|
max@0
|
2410 //! change the cube to have user specified dimensions (data is not preserved)
|
max@0
|
2411 template<typename eT>
|
max@0
|
2412 inline
|
max@0
|
2413 void
|
max@0
|
2414 Cube<eT>::set_size(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
|
max@0
|
2415 {
|
max@0
|
2416 arma_extra_debug_sigprint();
|
max@0
|
2417
|
max@0
|
2418 init_warm(in_n_rows, in_n_cols, in_n_slices);
|
max@0
|
2419 }
|
max@0
|
2420
|
max@0
|
2421
|
max@0
|
2422
|
max@0
|
2423 //! change the cube to have user specified dimensions (data is preserved)
|
max@0
|
2424 template<typename eT>
|
max@0
|
2425 inline
|
max@0
|
2426 void
|
max@0
|
2427 Cube<eT>::reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim)
|
max@0
|
2428 {
|
max@0
|
2429 arma_extra_debug_sigprint();
|
max@0
|
2430
|
max@0
|
2431 *this = arma::reshape(*this, in_rows, in_cols, in_slices, dim);
|
max@0
|
2432 }
|
max@0
|
2433
|
max@0
|
2434
|
max@0
|
2435
|
max@0
|
2436 //! change the cube to have user specified dimensions (data is preserved)
|
max@0
|
2437 template<typename eT>
|
max@0
|
2438 inline
|
max@0
|
2439 void
|
max@0
|
2440 Cube<eT>::resize(const uword in_rows, const uword in_cols, const uword in_slices)
|
max@0
|
2441 {
|
max@0
|
2442 arma_extra_debug_sigprint();
|
max@0
|
2443
|
max@0
|
2444 *this = arma::resize(*this, in_rows, in_cols, in_slices);
|
max@0
|
2445 }
|
max@0
|
2446
|
max@0
|
2447
|
max@0
|
2448
|
max@0
|
2449 //! change the cube (without preserving data) to have the same dimensions as the given cube
|
max@0
|
2450 template<typename eT>
|
max@0
|
2451 template<typename eT2>
|
max@0
|
2452 inline
|
max@0
|
2453 void
|
max@0
|
2454 Cube<eT>::copy_size(const Cube<eT2>& m)
|
max@0
|
2455 {
|
max@0
|
2456 arma_extra_debug_sigprint();
|
max@0
|
2457
|
max@0
|
2458 init_warm(m.n_rows, m.n_cols, m.n_slices);
|
max@0
|
2459 }
|
max@0
|
2460
|
max@0
|
2461
|
max@0
|
2462
|
max@0
|
2463 //! fill the cube with the specified value
|
max@0
|
2464 template<typename eT>
|
max@0
|
2465 inline
|
max@0
|
2466 const Cube<eT>&
|
max@0
|
2467 Cube<eT>::fill(const eT val)
|
max@0
|
2468 {
|
max@0
|
2469 arma_extra_debug_sigprint();
|
max@0
|
2470
|
max@0
|
2471 arrayops::inplace_set( memptr(), val, n_elem );
|
max@0
|
2472
|
max@0
|
2473 return *this;
|
max@0
|
2474 }
|
max@0
|
2475
|
max@0
|
2476
|
max@0
|
2477
|
max@0
|
2478 template<typename eT>
|
max@0
|
2479 inline
|
max@0
|
2480 const Cube<eT>&
|
max@0
|
2481 Cube<eT>::zeros()
|
max@0
|
2482 {
|
max@0
|
2483 arma_extra_debug_sigprint();
|
max@0
|
2484
|
max@0
|
2485 return (*this).fill(eT(0));
|
max@0
|
2486 }
|
max@0
|
2487
|
max@0
|
2488
|
max@0
|
2489
|
max@0
|
2490 template<typename eT>
|
max@0
|
2491 inline
|
max@0
|
2492 const Cube<eT>&
|
max@0
|
2493 Cube<eT>::zeros(const uword in_rows, const uword in_cols, const uword in_slices)
|
max@0
|
2494 {
|
max@0
|
2495 arma_extra_debug_sigprint();
|
max@0
|
2496
|
max@0
|
2497 set_size(in_rows, in_cols, in_slices);
|
max@0
|
2498
|
max@0
|
2499 return (*this).fill(eT(0));
|
max@0
|
2500 }
|
max@0
|
2501
|
max@0
|
2502
|
max@0
|
2503
|
max@0
|
2504 template<typename eT>
|
max@0
|
2505 inline
|
max@0
|
2506 const Cube<eT>&
|
max@0
|
2507 Cube<eT>::ones()
|
max@0
|
2508 {
|
max@0
|
2509 arma_extra_debug_sigprint();
|
max@0
|
2510
|
max@0
|
2511 return (*this).fill(eT(1));
|
max@0
|
2512 }
|
max@0
|
2513
|
max@0
|
2514
|
max@0
|
2515
|
max@0
|
2516 template<typename eT>
|
max@0
|
2517 inline
|
max@0
|
2518 const Cube<eT>&
|
max@0
|
2519 Cube<eT>::ones(const uword in_rows, const uword in_cols, const uword in_slices)
|
max@0
|
2520 {
|
max@0
|
2521 arma_extra_debug_sigprint();
|
max@0
|
2522
|
max@0
|
2523 set_size(in_rows, in_cols, in_slices);
|
max@0
|
2524
|
max@0
|
2525 return (*this).fill(eT(1));
|
max@0
|
2526 }
|
max@0
|
2527
|
max@0
|
2528
|
max@0
|
2529
|
max@0
|
2530 template<typename eT>
|
max@0
|
2531 inline
|
max@0
|
2532 const Cube<eT>&
|
max@0
|
2533 Cube<eT>::randu()
|
max@0
|
2534 {
|
max@0
|
2535 arma_extra_debug_sigprint();
|
max@0
|
2536
|
max@0
|
2537 const uword N = n_elem;
|
max@0
|
2538 eT* ptr = memptr();
|
max@0
|
2539
|
max@0
|
2540 uword i,j;
|
max@0
|
2541
|
max@0
|
2542 for(i=0, j=1; j<N; i+=2, j+=2)
|
max@0
|
2543 {
|
max@0
|
2544 ptr[i] = eT(eop_aux_randu<eT>());
|
max@0
|
2545 ptr[j] = eT(eop_aux_randu<eT>());
|
max@0
|
2546 }
|
max@0
|
2547
|
max@0
|
2548 if(i < N)
|
max@0
|
2549 {
|
max@0
|
2550 ptr[i] = eT(eop_aux_randu<eT>());
|
max@0
|
2551 }
|
max@0
|
2552
|
max@0
|
2553 return *this;
|
max@0
|
2554 }
|
max@0
|
2555
|
max@0
|
2556
|
max@0
|
2557
|
max@0
|
2558 template<typename eT>
|
max@0
|
2559 inline
|
max@0
|
2560 const Cube<eT>&
|
max@0
|
2561 Cube<eT>::randu(const uword in_rows, const uword in_cols, const uword in_slices)
|
max@0
|
2562 {
|
max@0
|
2563 arma_extra_debug_sigprint();
|
max@0
|
2564
|
max@0
|
2565 set_size(in_rows, in_cols, in_slices);
|
max@0
|
2566
|
max@0
|
2567 return (*this).randu();
|
max@0
|
2568 }
|
max@0
|
2569
|
max@0
|
2570
|
max@0
|
2571
|
max@0
|
2572 template<typename eT>
|
max@0
|
2573 inline
|
max@0
|
2574 const Cube<eT>&
|
max@0
|
2575 Cube<eT>::randn()
|
max@0
|
2576 {
|
max@0
|
2577 arma_extra_debug_sigprint();
|
max@0
|
2578
|
max@0
|
2579 const uword N = n_elem;
|
max@0
|
2580 eT* ptr = memptr();
|
max@0
|
2581
|
max@0
|
2582 for(uword i=0; i<N; ++i)
|
max@0
|
2583 {
|
max@0
|
2584 ptr[i] = eT(eop_aux_randn<eT>());
|
max@0
|
2585 }
|
max@0
|
2586
|
max@0
|
2587 return *this;
|
max@0
|
2588 }
|
max@0
|
2589
|
max@0
|
2590
|
max@0
|
2591
|
max@0
|
2592 template<typename eT>
|
max@0
|
2593 inline
|
max@0
|
2594 const Cube<eT>&
|
max@0
|
2595 Cube<eT>::randn(const uword in_rows, const uword in_cols, const uword in_slices)
|
max@0
|
2596 {
|
max@0
|
2597 arma_extra_debug_sigprint();
|
max@0
|
2598
|
max@0
|
2599 set_size(in_rows, in_cols, in_slices);
|
max@0
|
2600
|
max@0
|
2601 return (*this).randn();
|
max@0
|
2602 }
|
max@0
|
2603
|
max@0
|
2604
|
max@0
|
2605
|
max@0
|
2606 template<typename eT>
|
max@0
|
2607 inline
|
max@0
|
2608 void
|
max@0
|
2609 Cube<eT>::reset()
|
max@0
|
2610 {
|
max@0
|
2611 arma_extra_debug_sigprint();
|
max@0
|
2612
|
max@0
|
2613 init_warm(0,0,0);
|
max@0
|
2614 }
|
max@0
|
2615
|
max@0
|
2616
|
max@0
|
2617
|
max@0
|
2618 template<typename eT>
|
max@0
|
2619 template<typename T1>
|
max@0
|
2620 inline
|
max@0
|
2621 void
|
max@0
|
2622 Cube<eT>::set_real(const BaseCube<typename Cube<eT>::pod_type,T1>& X)
|
max@0
|
2623 {
|
max@0
|
2624 arma_extra_debug_sigprint();
|
max@0
|
2625
|
max@0
|
2626 Cube_aux::set_real(*this, X);
|
max@0
|
2627 }
|
max@0
|
2628
|
max@0
|
2629
|
max@0
|
2630
|
max@0
|
2631 template<typename eT>
|
max@0
|
2632 template<typename T1>
|
max@0
|
2633 inline
|
max@0
|
2634 void
|
max@0
|
2635 Cube<eT>::set_imag(const BaseCube<typename Cube<eT>::pod_type,T1>& X)
|
max@0
|
2636 {
|
max@0
|
2637 arma_extra_debug_sigprint();
|
max@0
|
2638
|
max@0
|
2639 Cube_aux::set_imag(*this, X);
|
max@0
|
2640 }
|
max@0
|
2641
|
max@0
|
2642
|
max@0
|
2643
|
max@0
|
2644 template<typename eT>
|
max@0
|
2645 inline
|
max@0
|
2646 arma_warn_unused
|
max@0
|
2647 eT
|
max@0
|
2648 Cube<eT>::min() const
|
max@0
|
2649 {
|
max@0
|
2650 arma_extra_debug_sigprint();
|
max@0
|
2651
|
max@0
|
2652 arma_debug_check( (n_elem == 0), "min(): object has no elements" );
|
max@0
|
2653
|
max@0
|
2654 return op_min::direct_min(memptr(), n_elem);
|
max@0
|
2655 }
|
max@0
|
2656
|
max@0
|
2657
|
max@0
|
2658
|
max@0
|
2659 template<typename eT>
|
max@0
|
2660 inline
|
max@0
|
2661 arma_warn_unused
|
max@0
|
2662 eT
|
max@0
|
2663 Cube<eT>::max() const
|
max@0
|
2664 {
|
max@0
|
2665 arma_extra_debug_sigprint();
|
max@0
|
2666
|
max@0
|
2667 arma_debug_check( (n_elem == 0), "max(): object has no elements" );
|
max@0
|
2668
|
max@0
|
2669 return op_max::direct_max(memptr(), n_elem);
|
max@0
|
2670 }
|
max@0
|
2671
|
max@0
|
2672
|
max@0
|
2673
|
max@0
|
2674 template<typename eT>
|
max@0
|
2675 inline
|
max@0
|
2676 eT
|
max@0
|
2677 Cube<eT>::min(uword& index_of_min_val) const
|
max@0
|
2678 {
|
max@0
|
2679 arma_extra_debug_sigprint();
|
max@0
|
2680
|
max@0
|
2681 arma_debug_check( (n_elem == 0), "min(): object has no elements" );
|
max@0
|
2682
|
max@0
|
2683 return op_min::direct_min(memptr(), n_elem, index_of_min_val);
|
max@0
|
2684 }
|
max@0
|
2685
|
max@0
|
2686
|
max@0
|
2687
|
max@0
|
2688 template<typename eT>
|
max@0
|
2689 inline
|
max@0
|
2690 eT
|
max@0
|
2691 Cube<eT>::max(uword& index_of_max_val) const
|
max@0
|
2692 {
|
max@0
|
2693 arma_extra_debug_sigprint();
|
max@0
|
2694
|
max@0
|
2695 arma_debug_check( (n_elem == 0), "max(): object has no elements" );
|
max@0
|
2696
|
max@0
|
2697 return op_max::direct_max(memptr(), n_elem, index_of_max_val);
|
max@0
|
2698 }
|
max@0
|
2699
|
max@0
|
2700
|
max@0
|
2701
|
max@0
|
2702 template<typename eT>
|
max@0
|
2703 inline
|
max@0
|
2704 eT
|
max@0
|
2705 Cube<eT>::min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const
|
max@0
|
2706 {
|
max@0
|
2707 arma_extra_debug_sigprint();
|
max@0
|
2708
|
max@0
|
2709 arma_debug_check( (n_elem == 0), "min(): object has no elements" );
|
max@0
|
2710
|
max@0
|
2711 uword i;
|
max@0
|
2712
|
max@0
|
2713 eT val = op_min::direct_min(memptr(), n_elem, i);
|
max@0
|
2714
|
max@0
|
2715 const uword in_slice = i / n_elem_slice;
|
max@0
|
2716 const uword offset = in_slice * n_elem_slice;
|
max@0
|
2717 const uword j = i - offset;
|
max@0
|
2718
|
max@0
|
2719 row_of_min_val = j % n_rows;
|
max@0
|
2720 col_of_min_val = j / n_rows;
|
max@0
|
2721 slice_of_min_val = in_slice;
|
max@0
|
2722
|
max@0
|
2723 return val;
|
max@0
|
2724 }
|
max@0
|
2725
|
max@0
|
2726
|
max@0
|
2727
|
max@0
|
2728 template<typename eT>
|
max@0
|
2729 inline
|
max@0
|
2730 eT
|
max@0
|
2731 Cube<eT>::max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const
|
max@0
|
2732 {
|
max@0
|
2733 arma_extra_debug_sigprint();
|
max@0
|
2734
|
max@0
|
2735 arma_debug_check( (n_elem == 0), "max(): object has no elements" );
|
max@0
|
2736
|
max@0
|
2737 uword i;
|
max@0
|
2738
|
max@0
|
2739 eT val = op_max::direct_max(memptr(), n_elem, i);
|
max@0
|
2740
|
max@0
|
2741 const uword in_slice = i / n_elem_slice;
|
max@0
|
2742 const uword offset = in_slice * n_elem_slice;
|
max@0
|
2743 const uword j = i - offset;
|
max@0
|
2744
|
max@0
|
2745 row_of_max_val = j % n_rows;
|
max@0
|
2746 col_of_max_val = j / n_rows;
|
max@0
|
2747 slice_of_max_val = in_slice;
|
max@0
|
2748
|
max@0
|
2749 return val;
|
max@0
|
2750 }
|
max@0
|
2751
|
max@0
|
2752
|
max@0
|
2753
|
max@0
|
2754 //! save the cube to a file
|
max@0
|
2755 template<typename eT>
|
max@0
|
2756 inline
|
max@0
|
2757 bool
|
max@0
|
2758 Cube<eT>::save(const std::string name, const file_type type, const bool print_status) const
|
max@0
|
2759 {
|
max@0
|
2760 arma_extra_debug_sigprint();
|
max@0
|
2761
|
max@0
|
2762 bool save_okay;
|
max@0
|
2763
|
max@0
|
2764 switch(type)
|
max@0
|
2765 {
|
max@0
|
2766 case raw_ascii:
|
max@0
|
2767 save_okay = diskio::save_raw_ascii(*this, name);
|
max@0
|
2768 break;
|
max@0
|
2769
|
max@0
|
2770 case arma_ascii:
|
max@0
|
2771 save_okay = diskio::save_arma_ascii(*this, name);
|
max@0
|
2772 break;
|
max@0
|
2773
|
max@0
|
2774 case raw_binary:
|
max@0
|
2775 save_okay = diskio::save_raw_binary(*this, name);
|
max@0
|
2776 break;
|
max@0
|
2777
|
max@0
|
2778 case arma_binary:
|
max@0
|
2779 save_okay = diskio::save_arma_binary(*this, name);
|
max@0
|
2780 break;
|
max@0
|
2781
|
max@0
|
2782 case ppm_binary:
|
max@0
|
2783 save_okay = diskio::save_ppm_binary(*this, name);
|
max@0
|
2784 break;
|
max@0
|
2785
|
max@0
|
2786 default:
|
max@0
|
2787 arma_warn(print_status, "Cube::save(): unsupported file type");
|
max@0
|
2788 save_okay = false;
|
max@0
|
2789 }
|
max@0
|
2790
|
max@0
|
2791 arma_warn( (print_status && (save_okay == false)), "Cube::save(): couldn't write to ", name);
|
max@0
|
2792
|
max@0
|
2793 return save_okay;
|
max@0
|
2794 }
|
max@0
|
2795
|
max@0
|
2796
|
max@0
|
2797
|
max@0
|
2798 //! save the cube to a stream
|
max@0
|
2799 template<typename eT>
|
max@0
|
2800 inline
|
max@0
|
2801 bool
|
max@0
|
2802 Cube<eT>::save(std::ostream& os, const file_type type, const bool print_status) const
|
max@0
|
2803 {
|
max@0
|
2804 arma_extra_debug_sigprint();
|
max@0
|
2805
|
max@0
|
2806 bool save_okay;
|
max@0
|
2807
|
max@0
|
2808 switch(type)
|
max@0
|
2809 {
|
max@0
|
2810 case raw_ascii:
|
max@0
|
2811 save_okay = diskio::save_raw_ascii(*this, os);
|
max@0
|
2812 break;
|
max@0
|
2813
|
max@0
|
2814 case arma_ascii:
|
max@0
|
2815 save_okay = diskio::save_arma_ascii(*this, os);
|
max@0
|
2816 break;
|
max@0
|
2817
|
max@0
|
2818 case raw_binary:
|
max@0
|
2819 save_okay = diskio::save_raw_binary(*this, os);
|
max@0
|
2820 break;
|
max@0
|
2821
|
max@0
|
2822 case arma_binary:
|
max@0
|
2823 save_okay = diskio::save_arma_binary(*this, os);
|
max@0
|
2824 break;
|
max@0
|
2825
|
max@0
|
2826 case ppm_binary:
|
max@0
|
2827 save_okay = diskio::save_ppm_binary(*this, os);
|
max@0
|
2828 break;
|
max@0
|
2829
|
max@0
|
2830 default:
|
max@0
|
2831 arma_warn(print_status, "Cube::save(): unsupported file type");
|
max@0
|
2832 save_okay = false;
|
max@0
|
2833 }
|
max@0
|
2834
|
max@0
|
2835 arma_warn( (print_status && (save_okay == false)), "Cube::save(): couldn't write to given stream");
|
max@0
|
2836
|
max@0
|
2837 return save_okay;
|
max@0
|
2838 }
|
max@0
|
2839
|
max@0
|
2840
|
max@0
|
2841
|
max@0
|
2842 //! load a cube from a file
|
max@0
|
2843 template<typename eT>
|
max@0
|
2844 inline
|
max@0
|
2845 bool
|
max@0
|
2846 Cube<eT>::load(const std::string name, const file_type type, const bool print_status)
|
max@0
|
2847 {
|
max@0
|
2848 arma_extra_debug_sigprint();
|
max@0
|
2849
|
max@0
|
2850 bool load_okay;
|
max@0
|
2851 std::string err_msg;
|
max@0
|
2852
|
max@0
|
2853 switch(type)
|
max@0
|
2854 {
|
max@0
|
2855 case auto_detect:
|
max@0
|
2856 load_okay = diskio::load_auto_detect(*this, name, err_msg);
|
max@0
|
2857 break;
|
max@0
|
2858
|
max@0
|
2859 case raw_ascii:
|
max@0
|
2860 load_okay = diskio::load_raw_ascii(*this, name, err_msg);
|
max@0
|
2861 break;
|
max@0
|
2862
|
max@0
|
2863 case arma_ascii:
|
max@0
|
2864 load_okay = diskio::load_arma_ascii(*this, name, err_msg);
|
max@0
|
2865 break;
|
max@0
|
2866
|
max@0
|
2867 case raw_binary:
|
max@0
|
2868 load_okay = diskio::load_raw_binary(*this, name, err_msg);
|
max@0
|
2869 break;
|
max@0
|
2870
|
max@0
|
2871 case arma_binary:
|
max@0
|
2872 load_okay = diskio::load_arma_binary(*this, name, err_msg);
|
max@0
|
2873 break;
|
max@0
|
2874
|
max@0
|
2875 case ppm_binary:
|
max@0
|
2876 load_okay = diskio::load_ppm_binary(*this, name, err_msg);
|
max@0
|
2877 break;
|
max@0
|
2878
|
max@0
|
2879 default:
|
max@0
|
2880 arma_warn(print_status, "Cube::load(): unsupported file type");
|
max@0
|
2881 load_okay = false;
|
max@0
|
2882 }
|
max@0
|
2883
|
max@0
|
2884 if( (print_status == true) && (load_okay == false) )
|
max@0
|
2885 {
|
max@0
|
2886 if(err_msg.length() > 0)
|
max@0
|
2887 {
|
max@0
|
2888 arma_warn(true, "Cube::load(): ", err_msg, name);
|
max@0
|
2889 }
|
max@0
|
2890 else
|
max@0
|
2891 {
|
max@0
|
2892 arma_warn(true, "Cube::load(): couldn't read ", name);
|
max@0
|
2893 }
|
max@0
|
2894 }
|
max@0
|
2895
|
max@0
|
2896 if(load_okay == false)
|
max@0
|
2897 {
|
max@0
|
2898 (*this).reset();
|
max@0
|
2899 }
|
max@0
|
2900
|
max@0
|
2901 return load_okay;
|
max@0
|
2902 }
|
max@0
|
2903
|
max@0
|
2904
|
max@0
|
2905
|
max@0
|
2906 //! load a cube from a stream
|
max@0
|
2907 template<typename eT>
|
max@0
|
2908 inline
|
max@0
|
2909 bool
|
max@0
|
2910 Cube<eT>::load(std::istream& is, const file_type type, const bool print_status)
|
max@0
|
2911 {
|
max@0
|
2912 arma_extra_debug_sigprint();
|
max@0
|
2913
|
max@0
|
2914 bool load_okay;
|
max@0
|
2915 std::string err_msg;
|
max@0
|
2916
|
max@0
|
2917 switch(type)
|
max@0
|
2918 {
|
max@0
|
2919 case auto_detect:
|
max@0
|
2920 load_okay = diskio::load_auto_detect(*this, is, err_msg);
|
max@0
|
2921 break;
|
max@0
|
2922
|
max@0
|
2923 case raw_ascii:
|
max@0
|
2924 load_okay = diskio::load_raw_ascii(*this, is, err_msg);
|
max@0
|
2925 break;
|
max@0
|
2926
|
max@0
|
2927 case arma_ascii:
|
max@0
|
2928 load_okay = diskio::load_arma_ascii(*this, is, err_msg);
|
max@0
|
2929 break;
|
max@0
|
2930
|
max@0
|
2931 case raw_binary:
|
max@0
|
2932 load_okay = diskio::load_raw_binary(*this, is, err_msg);
|
max@0
|
2933 break;
|
max@0
|
2934
|
max@0
|
2935 case arma_binary:
|
max@0
|
2936 load_okay = diskio::load_arma_binary(*this, is, err_msg);
|
max@0
|
2937 break;
|
max@0
|
2938
|
max@0
|
2939 case ppm_binary:
|
max@0
|
2940 load_okay = diskio::load_ppm_binary(*this, is, err_msg);
|
max@0
|
2941 break;
|
max@0
|
2942
|
max@0
|
2943 default:
|
max@0
|
2944 arma_warn(print_status, "Cube::load(): unsupported file type");
|
max@0
|
2945 load_okay = false;
|
max@0
|
2946 }
|
max@0
|
2947
|
max@0
|
2948
|
max@0
|
2949 if( (print_status == true) && (load_okay == false) )
|
max@0
|
2950 {
|
max@0
|
2951 if(err_msg.length() > 0)
|
max@0
|
2952 {
|
max@0
|
2953 arma_warn(true, "Cube::load(): ", err_msg, "the given stream");
|
max@0
|
2954 }
|
max@0
|
2955 else
|
max@0
|
2956 {
|
max@0
|
2957 arma_warn(true, "Cube::load(): couldn't load from the given stream");
|
max@0
|
2958 }
|
max@0
|
2959 }
|
max@0
|
2960
|
max@0
|
2961 if(load_okay == false)
|
max@0
|
2962 {
|
max@0
|
2963 (*this).reset();
|
max@0
|
2964 }
|
max@0
|
2965
|
max@0
|
2966 return load_okay;
|
max@0
|
2967 }
|
max@0
|
2968
|
max@0
|
2969
|
max@0
|
2970
|
max@0
|
2971 //! save the cube to a file, without printing any error messages
|
max@0
|
2972 template<typename eT>
|
max@0
|
2973 inline
|
max@0
|
2974 bool
|
max@0
|
2975 Cube<eT>::quiet_save(const std::string name, const file_type type) const
|
max@0
|
2976 {
|
max@0
|
2977 arma_extra_debug_sigprint();
|
max@0
|
2978
|
max@0
|
2979 return (*this).save(name, type, false);
|
max@0
|
2980 }
|
max@0
|
2981
|
max@0
|
2982
|
max@0
|
2983
|
max@0
|
2984 //! save the cube to a stream, without printing any error messages
|
max@0
|
2985 template<typename eT>
|
max@0
|
2986 inline
|
max@0
|
2987 bool
|
max@0
|
2988 Cube<eT>::quiet_save(std::ostream& os, const file_type type) const
|
max@0
|
2989 {
|
max@0
|
2990 arma_extra_debug_sigprint();
|
max@0
|
2991
|
max@0
|
2992 return (*this).save(os, type, false);
|
max@0
|
2993 }
|
max@0
|
2994
|
max@0
|
2995
|
max@0
|
2996
|
max@0
|
2997 //! load a cube from a file, without printing any error messages
|
max@0
|
2998 template<typename eT>
|
max@0
|
2999 inline
|
max@0
|
3000 bool
|
max@0
|
3001 Cube<eT>::quiet_load(const std::string name, const file_type type)
|
max@0
|
3002 {
|
max@0
|
3003 arma_extra_debug_sigprint();
|
max@0
|
3004
|
max@0
|
3005 return (*this).load(name, type, false);
|
max@0
|
3006 }
|
max@0
|
3007
|
max@0
|
3008
|
max@0
|
3009
|
max@0
|
3010 //! load a cube from a stream, without printing any error messages
|
max@0
|
3011 template<typename eT>
|
max@0
|
3012 inline
|
max@0
|
3013 bool
|
max@0
|
3014 Cube<eT>::quiet_load(std::istream& is, const file_type type)
|
max@0
|
3015 {
|
max@0
|
3016 arma_extra_debug_sigprint();
|
max@0
|
3017
|
max@0
|
3018 return (*this).load(is, type, false);
|
max@0
|
3019 }
|
max@0
|
3020
|
max@0
|
3021
|
max@0
|
3022
|
max@0
|
3023 template<typename eT>
|
max@0
|
3024 inline
|
max@0
|
3025 typename Cube<eT>::iterator
|
max@0
|
3026 Cube<eT>::begin()
|
max@0
|
3027 {
|
max@0
|
3028 arma_extra_debug_sigprint();
|
max@0
|
3029
|
max@0
|
3030 return memptr();
|
max@0
|
3031 }
|
max@0
|
3032
|
max@0
|
3033
|
max@0
|
3034
|
max@0
|
3035 template<typename eT>
|
max@0
|
3036 inline
|
max@0
|
3037 typename Cube<eT>::const_iterator
|
max@0
|
3038 Cube<eT>::begin() const
|
max@0
|
3039 {
|
max@0
|
3040 arma_extra_debug_sigprint();
|
max@0
|
3041
|
max@0
|
3042 return memptr();
|
max@0
|
3043 }
|
max@0
|
3044
|
max@0
|
3045
|
max@0
|
3046
|
max@0
|
3047 template<typename eT>
|
max@0
|
3048 inline
|
max@0
|
3049 typename Cube<eT>::iterator
|
max@0
|
3050 Cube<eT>::end()
|
max@0
|
3051 {
|
max@0
|
3052 arma_extra_debug_sigprint();
|
max@0
|
3053
|
max@0
|
3054 return memptr() + n_elem;
|
max@0
|
3055 }
|
max@0
|
3056
|
max@0
|
3057
|
max@0
|
3058
|
max@0
|
3059 template<typename eT>
|
max@0
|
3060 inline
|
max@0
|
3061 typename Cube<eT>::const_iterator
|
max@0
|
3062 Cube<eT>::end() const
|
max@0
|
3063 {
|
max@0
|
3064 arma_extra_debug_sigprint();
|
max@0
|
3065
|
max@0
|
3066 return memptr() + n_elem;
|
max@0
|
3067 }
|
max@0
|
3068
|
max@0
|
3069
|
max@0
|
3070
|
max@0
|
3071 template<typename eT>
|
max@0
|
3072 inline
|
max@0
|
3073 typename Cube<eT>::slice_iterator
|
max@0
|
3074 Cube<eT>::begin_slice(const uword slice_num)
|
max@0
|
3075 {
|
max@0
|
3076 arma_extra_debug_sigprint();
|
max@0
|
3077
|
max@0
|
3078 arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds");
|
max@0
|
3079
|
max@0
|
3080 return slice_memptr(slice_num);
|
max@0
|
3081 }
|
max@0
|
3082
|
max@0
|
3083
|
max@0
|
3084
|
max@0
|
3085 template<typename eT>
|
max@0
|
3086 inline
|
max@0
|
3087 typename Cube<eT>::const_slice_iterator
|
max@0
|
3088 Cube<eT>::begin_slice(const uword slice_num) const
|
max@0
|
3089 {
|
max@0
|
3090 arma_extra_debug_sigprint();
|
max@0
|
3091
|
max@0
|
3092 arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds");
|
max@0
|
3093
|
max@0
|
3094 return slice_memptr(slice_num);
|
max@0
|
3095 }
|
max@0
|
3096
|
max@0
|
3097
|
max@0
|
3098
|
max@0
|
3099 template<typename eT>
|
max@0
|
3100 inline
|
max@0
|
3101 typename Cube<eT>::slice_iterator
|
max@0
|
3102 Cube<eT>::end_slice(const uword slice_num)
|
max@0
|
3103 {
|
max@0
|
3104 arma_extra_debug_sigprint();
|
max@0
|
3105
|
max@0
|
3106 arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds");
|
max@0
|
3107
|
max@0
|
3108 return slice_memptr(slice_num) + n_elem_slice;
|
max@0
|
3109 }
|
max@0
|
3110
|
max@0
|
3111
|
max@0
|
3112
|
max@0
|
3113 template<typename eT>
|
max@0
|
3114 inline
|
max@0
|
3115 typename Cube<eT>::const_slice_iterator
|
max@0
|
3116 Cube<eT>::end_slice(const uword slice_num) const
|
max@0
|
3117 {
|
max@0
|
3118 arma_extra_debug_sigprint();
|
max@0
|
3119
|
max@0
|
3120 arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds");
|
max@0
|
3121
|
max@0
|
3122 return slice_memptr(slice_num) + n_elem_slice;
|
max@0
|
3123 }
|
max@0
|
3124
|
max@0
|
3125
|
max@0
|
3126
|
max@0
|
3127 template<typename eT>
|
max@0
|
3128 template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
|
max@0
|
3129 arma_inline
|
max@0
|
3130 void
|
max@0
|
3131 Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::mem_setup()
|
max@0
|
3132 {
|
max@0
|
3133 arma_extra_debug_sigprint_this(this);
|
max@0
|
3134
|
max@0
|
3135 if(fixed_n_elem > 0)
|
max@0
|
3136 {
|
max@0
|
3137 access::rw(Cube<eT>::n_rows) = fixed_n_rows;
|
max@0
|
3138 access::rw(Cube<eT>::n_cols) = fixed_n_cols;
|
max@0
|
3139 access::rw(Cube<eT>::n_elem_slice) = fixed_n_rows * fixed_n_cols;
|
max@0
|
3140 access::rw(Cube<eT>::n_slices) = fixed_n_slices;
|
max@0
|
3141 access::rw(Cube<eT>::n_elem) = fixed_n_elem;
|
max@0
|
3142 access::rw(Cube<eT>::mem_state) = 3;
|
max@0
|
3143 access::rw(Cube<eT>::mat_ptrs) = const_cast< const Mat<eT>** >( \
|
max@0
|
3144 (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? mat_ptrs_local_extra : mat_ptrs_local );
|
max@0
|
3145 access::rw(Cube<eT>::mem) = (fixed_n_elem > Cube_prealloc::mem_n_elem) ? mem_local_extra : mem_local;
|
max@0
|
3146
|
max@0
|
3147 create_mat();
|
max@0
|
3148 }
|
max@0
|
3149 else
|
max@0
|
3150 {
|
max@0
|
3151 access::rw(Cube<eT>::n_rows) = 0;
|
max@0
|
3152 access::rw(Cube<eT>::n_cols) = 0;
|
max@0
|
3153 access::rw(Cube<eT>::n_elem_slice) = 0;
|
max@0
|
3154 access::rw(Cube<eT>::n_slices) = 0;
|
max@0
|
3155 access::rw(Cube<eT>::n_elem) = 0;
|
max@0
|
3156 access::rw(Cube<eT>::mem_state) = 3;
|
max@0
|
3157 access::rw(Cube<eT>::mat_ptrs) = 0;
|
max@0
|
3158 access::rw(Cube<eT>::mem) = 0;
|
max@0
|
3159 }
|
max@0
|
3160 }
|
max@0
|
3161
|
max@0
|
3162
|
max@0
|
3163
|
max@0
|
3164 //! prefix ++
|
max@0
|
3165 template<typename eT>
|
max@0
|
3166 arma_inline
|
max@0
|
3167 void
|
max@0
|
3168 Cube_aux::prefix_pp(Cube<eT>& x)
|
max@0
|
3169 {
|
max@0
|
3170 eT* memptr = x.memptr();
|
max@0
|
3171 const uword n_elem = x.n_elem;
|
max@0
|
3172
|
max@0
|
3173 uword i,j;
|
max@0
|
3174
|
max@0
|
3175 for(i=0, j=1; j<n_elem; i+=2, j+=2)
|
max@0
|
3176 {
|
max@0
|
3177 ++(memptr[i]);
|
max@0
|
3178 ++(memptr[j]);
|
max@0
|
3179 }
|
max@0
|
3180
|
max@0
|
3181 if(i < n_elem)
|
max@0
|
3182 {
|
max@0
|
3183 ++(memptr[i]);
|
max@0
|
3184 }
|
max@0
|
3185 }
|
max@0
|
3186
|
max@0
|
3187
|
max@0
|
3188
|
max@0
|
3189 //! prefix ++ for complex numbers (work around for limitations of the std::complex class)
|
max@0
|
3190 template<typename T>
|
max@0
|
3191 arma_inline
|
max@0
|
3192 void
|
max@0
|
3193 Cube_aux::prefix_pp(Cube< std::complex<T> >& x)
|
max@0
|
3194 {
|
max@0
|
3195 x += T(1);
|
max@0
|
3196 }
|
max@0
|
3197
|
max@0
|
3198
|
max@0
|
3199
|
max@0
|
3200 //! postfix ++
|
max@0
|
3201 template<typename eT>
|
max@0
|
3202 arma_inline
|
max@0
|
3203 void
|
max@0
|
3204 Cube_aux::postfix_pp(Cube<eT>& x)
|
max@0
|
3205 {
|
max@0
|
3206 eT* memptr = x.memptr();
|
max@0
|
3207 const uword n_elem = x.n_elem;
|
max@0
|
3208
|
max@0
|
3209 uword i,j;
|
max@0
|
3210
|
max@0
|
3211 for(i=0, j=1; j<n_elem; i+=2, j+=2)
|
max@0
|
3212 {
|
max@0
|
3213 (memptr[i])++;
|
max@0
|
3214 (memptr[j])++;
|
max@0
|
3215 }
|
max@0
|
3216
|
max@0
|
3217 if(i < n_elem)
|
max@0
|
3218 {
|
max@0
|
3219 (memptr[i])++;
|
max@0
|
3220 }
|
max@0
|
3221 }
|
max@0
|
3222
|
max@0
|
3223
|
max@0
|
3224
|
max@0
|
3225 //! postfix ++ for complex numbers (work around for limitations of the std::complex class)
|
max@0
|
3226 template<typename T>
|
max@0
|
3227 arma_inline
|
max@0
|
3228 void
|
max@0
|
3229 Cube_aux::postfix_pp(Cube< std::complex<T> >& x)
|
max@0
|
3230 {
|
max@0
|
3231 x += T(1);
|
max@0
|
3232 }
|
max@0
|
3233
|
max@0
|
3234
|
max@0
|
3235
|
max@0
|
3236 //! prefix --
|
max@0
|
3237 template<typename eT>
|
max@0
|
3238 arma_inline
|
max@0
|
3239 void
|
max@0
|
3240 Cube_aux::prefix_mm(Cube<eT>& x)
|
max@0
|
3241 {
|
max@0
|
3242 eT* memptr = x.memptr();
|
max@0
|
3243 const uword n_elem = x.n_elem;
|
max@0
|
3244
|
max@0
|
3245 uword i,j;
|
max@0
|
3246
|
max@0
|
3247 for(i=0, j=1; j<n_elem; i+=2, j+=2)
|
max@0
|
3248 {
|
max@0
|
3249 --(memptr[i]);
|
max@0
|
3250 --(memptr[j]);
|
max@0
|
3251 }
|
max@0
|
3252
|
max@0
|
3253 if(i < n_elem)
|
max@0
|
3254 {
|
max@0
|
3255 --(memptr[i]);
|
max@0
|
3256 }
|
max@0
|
3257 }
|
max@0
|
3258
|
max@0
|
3259
|
max@0
|
3260
|
max@0
|
3261 //! prefix -- for complex numbers (work around for limitations of the std::complex class)
|
max@0
|
3262 template<typename T>
|
max@0
|
3263 arma_inline
|
max@0
|
3264 void
|
max@0
|
3265 Cube_aux::prefix_mm(Cube< std::complex<T> >& x)
|
max@0
|
3266 {
|
max@0
|
3267 x -= T(1);
|
max@0
|
3268 }
|
max@0
|
3269
|
max@0
|
3270
|
max@0
|
3271
|
max@0
|
3272 //! postfix --
|
max@0
|
3273 template<typename eT>
|
max@0
|
3274 arma_inline
|
max@0
|
3275 void
|
max@0
|
3276 Cube_aux::postfix_mm(Cube<eT>& x)
|
max@0
|
3277 {
|
max@0
|
3278 eT* memptr = x.memptr();
|
max@0
|
3279 const uword n_elem = x.n_elem;
|
max@0
|
3280
|
max@0
|
3281 uword i,j;
|
max@0
|
3282
|
max@0
|
3283 for(i=0, j=1; j<n_elem; i+=2, j+=2)
|
max@0
|
3284 {
|
max@0
|
3285 (memptr[i])--;
|
max@0
|
3286 (memptr[j])--;
|
max@0
|
3287 }
|
max@0
|
3288
|
max@0
|
3289 if(i < n_elem)
|
max@0
|
3290 {
|
max@0
|
3291 (memptr[i])--;
|
max@0
|
3292 }
|
max@0
|
3293 }
|
max@0
|
3294
|
max@0
|
3295
|
max@0
|
3296
|
max@0
|
3297 //! postfix ++ for complex numbers (work around for limitations of the std::complex class)
|
max@0
|
3298 template<typename T>
|
max@0
|
3299 arma_inline
|
max@0
|
3300 void
|
max@0
|
3301 Cube_aux::postfix_mm(Cube< std::complex<T> >& x)
|
max@0
|
3302 {
|
max@0
|
3303 x -= T(1);
|
max@0
|
3304 }
|
max@0
|
3305
|
max@0
|
3306
|
max@0
|
3307
|
max@0
|
3308 template<typename eT, typename T1>
|
max@0
|
3309 inline
|
max@0
|
3310 void
|
max@0
|
3311 Cube_aux::set_real(Cube<eT>& out, const BaseCube<eT,T1>& X)
|
max@0
|
3312 {
|
max@0
|
3313 arma_extra_debug_sigprint();
|
max@0
|
3314
|
max@0
|
3315 const unwrap_cube<T1> tmp(X.get_ref());
|
max@0
|
3316 const Cube<eT>& A = tmp.M;
|
max@0
|
3317
|
max@0
|
3318 arma_debug_assert_same_size( out, A, "Cube::set_real()" );
|
max@0
|
3319
|
max@0
|
3320 out = A;
|
max@0
|
3321 }
|
max@0
|
3322
|
max@0
|
3323
|
max@0
|
3324
|
max@0
|
3325 template<typename eT, typename T1>
|
max@0
|
3326 inline
|
max@0
|
3327 void
|
max@0
|
3328 Cube_aux::set_imag(Cube<eT>& out, const BaseCube<eT,T1>& X)
|
max@0
|
3329 {
|
max@0
|
3330 arma_extra_debug_sigprint();
|
max@0
|
3331 }
|
max@0
|
3332
|
max@0
|
3333
|
max@0
|
3334
|
max@0
|
3335 template<typename T, typename T1>
|
max@0
|
3336 inline
|
max@0
|
3337 void
|
max@0
|
3338 Cube_aux::set_real(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X)
|
max@0
|
3339 {
|
max@0
|
3340 arma_extra_debug_sigprint();
|
max@0
|
3341
|
max@0
|
3342 typedef typename std::complex<T> eT;
|
max@0
|
3343 typedef typename ProxyCube<T1>::ea_type ea_type;
|
max@0
|
3344
|
max@0
|
3345 const ProxyCube<T1> A(X.get_ref());
|
max@0
|
3346
|
max@0
|
3347 arma_debug_assert_same_size
|
max@0
|
3348 (
|
max@0
|
3349 out.n_rows, out.n_cols, out.n_slices,
|
max@0
|
3350 A.get_n_rows(), A.get_n_cols(), A.get_n_slices(),
|
max@0
|
3351 "Cube::set_real()"
|
max@0
|
3352 );
|
max@0
|
3353
|
max@0
|
3354 const uword n_elem = out.n_elem;
|
max@0
|
3355 eT* out_mem = out.memptr();
|
max@0
|
3356 ea_type PA = A.get_ea();
|
max@0
|
3357
|
max@0
|
3358 for(uword i=0; i<n_elem; ++i)
|
max@0
|
3359 {
|
max@0
|
3360 //out_mem[i].real() = PA[i];
|
max@0
|
3361 out_mem[i] = std::complex<T>( PA[i], out_mem[i].imag() );
|
max@0
|
3362 }
|
max@0
|
3363 }
|
max@0
|
3364
|
max@0
|
3365
|
max@0
|
3366
|
max@0
|
3367 template<typename T, typename T1>
|
max@0
|
3368 inline
|
max@0
|
3369 void
|
max@0
|
3370 Cube_aux::set_imag(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X)
|
max@0
|
3371 {
|
max@0
|
3372 arma_extra_debug_sigprint();
|
max@0
|
3373
|
max@0
|
3374 typedef typename std::complex<T> eT;
|
max@0
|
3375 typedef typename ProxyCube<T1>::ea_type ea_type;
|
max@0
|
3376
|
max@0
|
3377 const ProxyCube<T1> A(X.get_ref());
|
max@0
|
3378
|
max@0
|
3379 arma_debug_assert_same_size
|
max@0
|
3380 (
|
max@0
|
3381 out.n_rows, out.n_cols, out.n_slices,
|
max@0
|
3382 A.get_n_rows(), A.get_n_cols(), A.get_n_slices(),
|
max@0
|
3383 "Cube::set_imag()"
|
max@0
|
3384 );
|
max@0
|
3385
|
max@0
|
3386 const uword n_elem = out.n_elem;
|
max@0
|
3387 eT* out_mem = out.memptr();
|
max@0
|
3388 ea_type PA = A.get_ea();
|
max@0
|
3389
|
max@0
|
3390 for(uword i=0; i<n_elem; ++i)
|
max@0
|
3391 {
|
max@0
|
3392 //out_mem[i].imag() = PA[i];
|
max@0
|
3393 out_mem[i] = std::complex<T>( out_mem[i].real(), PA[i] );
|
max@0
|
3394 }
|
max@0
|
3395 }
|
max@0
|
3396
|
max@0
|
3397
|
max@0
|
3398
|
max@0
|
3399 #ifdef ARMA_EXTRA_CUBE_MEAT
|
max@0
|
3400 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_MEAT)
|
max@0
|
3401 #endif
|
max@0
|
3402
|
max@0
|
3403
|
max@0
|
3404
|
max@0
|
3405 //! @}
|