Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-2.4.4/include/armadillo_bits/podarray_meat.hpp @ 0:8b6102e2a9b0
Armadillo Library
author | maxzanoni76 <max.zanoni@eecs.qmul.ac.uk> |
---|---|
date | Wed, 11 Apr 2012 09:27:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8b6102e2a9b0 |
---|---|
1 // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | |
2 // Copyright (C) 2008-2010 Conrad Sanderson | |
3 // | |
4 // This file is part of the Armadillo C++ library. | |
5 // It is provided without any warranty of fitness | |
6 // for any purpose. You can redistribute this file | |
7 // and/or modify it under the terms of the GNU | |
8 // Lesser General Public License (LGPL) as published | |
9 // by the Free Software Foundation, either version 3 | |
10 // of the License or (at your option) any later version. | |
11 // (see http://www.opensource.org/licenses for more info) | |
12 | |
13 | |
14 //! \addtogroup podarray | |
15 //! @{ | |
16 | |
17 | |
18 template<typename eT> | |
19 inline | |
20 podarray<eT>::~podarray() | |
21 { | |
22 arma_extra_debug_sigprint_this(this); | |
23 | |
24 if(n_elem > sizeof(mem_local)/sizeof(eT) ) | |
25 { | |
26 delete [] mem; | |
27 } | |
28 | |
29 if(arma_config::debug == true) | |
30 { | |
31 access::rw(n_elem) = 0; | |
32 access::rw(mem) = 0; | |
33 } | |
34 } | |
35 | |
36 | |
37 | |
38 template<typename eT> | |
39 inline | |
40 podarray<eT>::podarray() | |
41 : n_elem(0) | |
42 , mem (0) | |
43 { | |
44 arma_extra_debug_sigprint_this(this); | |
45 } | |
46 | |
47 | |
48 | |
49 template<typename eT> | |
50 inline | |
51 podarray<eT>::podarray(const podarray& x) | |
52 : n_elem(0) | |
53 , mem (0) | |
54 { | |
55 arma_extra_debug_sigprint(); | |
56 | |
57 this->operator=(x); | |
58 } | |
59 | |
60 | |
61 | |
62 template<typename eT> | |
63 inline | |
64 const podarray<eT>& | |
65 podarray<eT>::operator=(const podarray& x) | |
66 { | |
67 arma_extra_debug_sigprint(); | |
68 | |
69 if(this != &x) | |
70 { | |
71 init(x.n_elem); | |
72 | |
73 arrayops::copy( memptr(), x.memptr(), n_elem ); | |
74 } | |
75 | |
76 return *this; | |
77 } | |
78 | |
79 | |
80 | |
81 template<typename eT> | |
82 arma_inline | |
83 podarray<eT>::podarray(const uword new_n_elem) | |
84 : n_elem(0) | |
85 , mem (0) | |
86 { | |
87 arma_extra_debug_sigprint_this(this); | |
88 | |
89 init(new_n_elem); | |
90 } | |
91 | |
92 | |
93 | |
94 template<typename eT> | |
95 arma_inline | |
96 podarray<eT>::podarray(const eT* X, const uword new_n_elem) | |
97 : n_elem(0) | |
98 , mem (0) | |
99 { | |
100 arma_extra_debug_sigprint_this(this); | |
101 | |
102 init(new_n_elem); | |
103 | |
104 arrayops::copy( memptr(), X, new_n_elem ); | |
105 } | |
106 | |
107 | |
108 | |
109 template<typename eT> | |
110 arma_inline | |
111 eT | |
112 podarray<eT>::operator[] (const uword i) const | |
113 { | |
114 return mem[i]; | |
115 } | |
116 | |
117 | |
118 | |
119 template<typename eT> | |
120 arma_inline | |
121 eT& | |
122 podarray<eT>::operator[] (const uword i) | |
123 { | |
124 return access::rw(mem[i]); | |
125 } | |
126 | |
127 | |
128 | |
129 template<typename eT> | |
130 arma_inline | |
131 eT | |
132 podarray<eT>::operator() (const uword i) const | |
133 { | |
134 arma_debug_check( (i >= n_elem), "podarray::operator(): index out of bounds"); | |
135 return mem[i]; | |
136 } | |
137 | |
138 | |
139 | |
140 template<typename eT> | |
141 arma_inline | |
142 eT& | |
143 podarray<eT>::operator() (const uword i) | |
144 { | |
145 arma_debug_check( (i >= n_elem), "podarray::operator(): index out of bounds"); | |
146 return access::rw(mem[i]); | |
147 } | |
148 | |
149 | |
150 | |
151 template<typename eT> | |
152 inline | |
153 void | |
154 podarray<eT>::set_size(const uword new_n_elem) | |
155 { | |
156 arma_extra_debug_sigprint(); | |
157 | |
158 init(new_n_elem); | |
159 } | |
160 | |
161 | |
162 | |
163 template<typename eT> | |
164 inline | |
165 void | |
166 podarray<eT>::reset() | |
167 { | |
168 arma_extra_debug_sigprint(); | |
169 | |
170 init(0); | |
171 } | |
172 | |
173 | |
174 | |
175 template<typename eT> | |
176 inline | |
177 void | |
178 podarray<eT>::fill(const eT val) | |
179 { | |
180 arma_extra_debug_sigprint(); | |
181 | |
182 arrayops::inplace_set(memptr(), val, n_elem); | |
183 } | |
184 | |
185 | |
186 | |
187 template<typename eT> | |
188 inline | |
189 void | |
190 podarray<eT>::zeros() | |
191 { | |
192 arma_extra_debug_sigprint(); | |
193 | |
194 fill(eT(0)); | |
195 } | |
196 | |
197 | |
198 | |
199 template<typename eT> | |
200 inline | |
201 void | |
202 podarray<eT>::zeros(const uword new_n_elem) | |
203 { | |
204 arma_extra_debug_sigprint(); | |
205 | |
206 init(new_n_elem); | |
207 fill(eT(0)); | |
208 } | |
209 | |
210 | |
211 | |
212 template<typename eT> | |
213 arma_inline | |
214 eT* | |
215 podarray<eT>::memptr() | |
216 { | |
217 return const_cast<eT*>(mem); | |
218 } | |
219 | |
220 | |
221 | |
222 template<typename eT> | |
223 arma_inline | |
224 const eT* | |
225 podarray<eT>::memptr() const | |
226 { | |
227 return mem; | |
228 } | |
229 | |
230 | |
231 | |
232 template<typename eT> | |
233 arma_hot | |
234 inline | |
235 void | |
236 podarray<eT>::copy_row(const Mat<eT>& A, const uword row) | |
237 { | |
238 const uword cols = A.n_cols; | |
239 | |
240 // note: this function assumes that the podarray has been set to the correct size beforehand | |
241 eT* out = memptr(); | |
242 | |
243 switch(cols) | |
244 { | |
245 default: | |
246 { | |
247 uword i,j; | |
248 for(i=0, j=1; j < cols; i+=2, j+=2) | |
249 { | |
250 const eT tmp_i = A.at(row, i); | |
251 const eT tmp_j = A.at(row, j); | |
252 | |
253 out[i] = tmp_i; | |
254 out[j] = tmp_j; | |
255 } | |
256 | |
257 if(i < cols) | |
258 { | |
259 out[i] = A.at(row, i); | |
260 } | |
261 } | |
262 break; | |
263 | |
264 case 8: | |
265 out[7] = A.at(row, 7); | |
266 | |
267 case 7: | |
268 out[6] = A.at(row, 6); | |
269 | |
270 case 6: | |
271 out[5] = A.at(row, 5); | |
272 | |
273 case 5: | |
274 out[4] = A.at(row, 4); | |
275 | |
276 case 4: | |
277 out[3] = A.at(row, 3); | |
278 | |
279 case 3: | |
280 out[2] = A.at(row, 2); | |
281 | |
282 case 2: | |
283 out[1] = A.at(row, 1); | |
284 | |
285 case 1: | |
286 out[0] = A.at(row, 0); | |
287 } | |
288 } | |
289 | |
290 | |
291 | |
292 template<typename eT> | |
293 inline | |
294 void | |
295 podarray<eT>::init(const uword new_n_elem) | |
296 { | |
297 arma_extra_debug_sigprint(); | |
298 | |
299 if(n_elem == new_n_elem) | |
300 { | |
301 return; | |
302 } | |
303 | |
304 if(n_elem > sizeof(mem_local)/sizeof(eT) ) | |
305 { | |
306 delete [] mem; | |
307 } | |
308 | |
309 if(new_n_elem <= sizeof(mem_local)/sizeof(eT) ) | |
310 { | |
311 access::rw(mem) = mem_local; | |
312 } | |
313 else | |
314 { | |
315 access::rw(mem) = new eT[new_n_elem]; | |
316 } | |
317 | |
318 access::rw(n_elem) = new_n_elem; | |
319 } | |
320 | |
321 | |
322 | |
323 //! @} |