podarray_meat.hpp
Go to the documentation of this file.
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 
16 
17 
18 template<typename eT>
19 inline
21  {
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
41  : n_elem(0)
42  , mem (0)
43  {
45  }
46 
47 
48 
49 template<typename eT>
50 inline
52  : n_elem(0)
53  , mem (0)
54  {
56 
57  this->operator=(x);
58  }
59 
60 
61 
62 template<typename eT>
63 inline
64 const podarray<eT>&
66  {
68 
69  if(this != &x)
70  {
71  init(x.n_elem);
72 
74  }
75 
76  return *this;
77  }
78 
79 
80 
81 template<typename eT>
83 podarray<eT>::podarray(const uword new_n_elem)
84  : n_elem(0)
85  , mem (0)
86  {
88 
89  init(new_n_elem);
90  }
91 
92 
93 
94 template<typename eT>
96 podarray<eT>::podarray(const eT* X, const uword new_n_elem)
97  : n_elem(0)
98  , mem (0)
99  {
101 
102  init(new_n_elem);
103 
104  arrayops::copy( memptr(), X, new_n_elem );
105  }
106 
107 
108 
109 template<typename eT>
111 eT
113  {
114  return mem[i];
115  }
116 
117 
118 
119 template<typename eT>
121 eT&
123  {
124  return access::rw(mem[i]);
125  }
126 
127 
128 
129 template<typename eT>
131 eT
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>
142 eT&
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  {
157 
158  init(new_n_elem);
159  }
160 
161 
162 
163 template<typename eT>
164 inline
165 void
167  {
169 
170  init(0);
171  }
172 
173 
174 
175 template<typename eT>
176 inline
177 void
178 podarray<eT>::fill(const eT val)
179  {
181 
183  }
184 
185 
186 
187 template<typename eT>
188 inline
189 void
191  {
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  {
205 
206  init(new_n_elem);
207  fill(eT(0));
208  }
209 
210 
211 
212 template<typename eT>
214 eT*
216  {
217  return const_cast<eT*>(mem);
218  }
219 
220 
221 
222 template<typename eT>
224 const eT*
226  {
227  return mem;
228  }
229 
230 
231 
232 template<typename eT>
233 arma_hot
234 inline
235 void
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  {
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  {
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 
arma_aligned const uword n_elem
number of elements held
arma_hot void copy_row(const Mat< eT > &A, const uword row)
A lightweight array for POD types. If the amount of memory requested is small, the stack is used...
arma_inline eT & operator()(const uword i)
arma_hot static arma_inline void copy(eT *dest, const eT *src, const uword n_elem)
void init(const uword new_n_elem)
void zeros()
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
const podarray & operator=(const podarray &x)
void reset()
u32 uword
Definition: typedef.hpp:85
static arma_inline T1 & rw(const T1 &x)
internal function to allow modification of data declared as read-only
Definition: access.hpp:23
#define arma_debug_check
Definition: debug.hpp:1084
static arma_hot void inplace_set(eT *dest, const eT val, const uword n_elem)
arma_inline arma_warn_unused eT & at(const uword i)
linear element accessor (treats the matrix as a vector); no bounds check.
Definition: Mat_meat.hpp:3692
#define arma_extra_debug_sigprint_this
Definition: debug.hpp:1117
void fill(const eT val)
arma_aligned eT mem_local[podarray_prealloc_n_elem::val]
Internal memory, to avoid calling the &#39;new&#39; operator for small amounts of memory. ...
arma_inline eT & operator[](const uword i)
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
arma_inline eT * memptr()
Dense matrix class.
#define arma_inline
void set_size(const uword new_n_elem)
static const bool debug
Definition: arma_config.hpp:63
arma_aligned const eT *const mem
pointer to memory used by the object
#define arma_hot


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:58