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