ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
i3arr.cpp
Go to the documentation of this file.
1 
5 #include "fvar.hpp"
6 
9 {
10  allocate();
11 }
14 {
15  deallocate();
16 }
28  int sl, int sh,
29  int nrl, int nrh,
30  int ncl, int nch)
31 {
32  allocate(sl, sh);
33  for (int i = sl; i <= sh; ++i)
34  {
35  t[i].allocate(nrl, nrh, ncl, nch);
36  }
37 }
44 void i3_array::allocate(int sl, int sh)
45 {
46  if (sl > sh)
47  {
48  return allocate();
49  }
50  if ((shape = new three_array_shape(sl, sh)) == 0)
51  {
52  cerr << " Error: Unable to allocate memory in "
53  << " i3_array::allocate(int, int).\n";
54  ad_exit(1);
55  }
56  if ((t = new imatrix[slicesize()]) == 0)
57  {
58  cerr << " Error: Unable to allocate memory in "
59  << " i3_array::allocate(int, int).\n";
60  ad_exit(1);
61  }
62  t -= slicemin();
63  for (int i = sl; i <= sh; ++i)
64  {
65  t[i].allocate();
66  }
67 }
79  int sl, int sh,
80  int nrl, int nrh,
81  const ivector& ncl, const ivector& nch)
82 {
83  allocate(sl, sh, nrl, nrh, ncl, nch);
84 }
91 i3_array::i3_array(int sl, int sh)
92 {
93  allocate(sl, sh);
94 }
106  int sl, int sh,
107  int nrl, const ivector& nrh,
108  int ncl, int nch)
109 {
110  allocate(sl, sh, nrl, nrh, ncl, nch);
111 }
123  int sl, int sh,
124  int nrl, int nrh,
125  const ivector& ncl, const ivector& nch)
126 {
127  allocate(sl, sh);
128  for (int i = sl; i <= sh; ++i)
129  {
130  elem(i).allocate(nrl, nrh, ncl(i), nch(i));
131  }
132 }
144  int sl,int sh,
145  int nrl,const ivector& nrh,
146  int ncl, int nch)
147 {
148  allocate(sl, sh);
149  for (int i = sl; i <= sh; ++i)
150  {
151  elem(i).allocate(nrl, nrh(i), ncl, nch);
152  }
153 }
165  int sl, int sh,
166  int nrl, int nrh,
167  int ncl, int nch)
168 {
169  allocate(sl, sh, nrl, nrh, ncl, nch);
170 }
182  int sl, int sh,
183  int nrl, const ivector& nrh,
184  int ncl, const imatrix& nch)
185 {
186  allocate(sl, sh, nrl, nrh, ncl, nch);
187 }
199  int sl, int sh,
200  int nrl, const ivector& nrh,
201  int ncl, const imatrix& nch)
202 {
203  allocate(sl, sh);
204  for (int i = slicemin(); i <= slicemax(); ++i)
205  {
206  t[i].allocate(nrl, nrh(i), ncl, nch(i));
207  }
208 }
215 i3_array::i3_array(int sl, int sh, const imatrix& m1)
216 {
217  allocate(sl, sh);
218  for (int i = slicemin(); i <= slicemax(); ++i)
219  {
220  t[i].shallow_copy(m1);
221  }
222 }
228 void i3_array::allocate(const i3_array& other)
229 {
230  allocate(other.slicemin(), other.slicemax());
231  for (int i = slicemin(); i <= slicemax(); ++i)
232  {
233  elem(i).allocate(other.elem(i));
234  }
235 }
238 {
239  shape = nullptr;
240  t = nullptr;
241 }
244 {
245  for (int i = slicemin(); i <= slicemax(); ++i)
246  {
247  elem(i).initialize();
248  }
249 }
252 {
253  shallow_copy(other);
254 }
261 {
262  if (other.shape)
263  {
264  shape = other.shape;
265  ++(shape->ncopies);
266  t = other.t;
267  }
268  else
269  {
270 #ifdef DEBUG
271  cerr << "Warning -- Unable to shallow copy an unallocated i3_array.\n";
272 #endif
273  allocate();
274  }
275 }
278 {
279  if (shape)
280  {
281  if (shape->ncopies > 0)
282  {
283  --(shape->ncopies);
284  }
285  else
286  {
287  t += indexmin();
288  delete [] t;
289  delete shape;
290  }
291  allocate();
292  }
293 #if defined(DIAG)
294  else
295  {
296  cerr << "Warning -- Unable to deallocate an unallocated i3_array.\n";
297  }
298 #endif
299 }
void allocate(void)
Does not allocate, but initializes imatrix members.
Definition: imat.cpp:138
unsigned int ncopies
Definition: fvar.hpp:3701
Description not yet available.
Definition: imatrix.h:69
imatrix * t
Definition: fvar.hpp:3946
Description not yet available.
Definition: fvar.hpp:3698
void deallocate(void)
Deallocate i3_array memory.
Definition: i3arr.cpp:277
exitptr ad_exit
Definition: gradstrc.cpp:53
int slicemin() const
Definition: fvar.hpp:4029
void shallow_copy(const i3_array &)
Shallow copy other data structure pointers.
Definition: i3arr.cpp:260
int indexmin() const
Definition: fvar.hpp:4021
i3_array(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: i3arr.cpp:8
void shallow_copy(const imatrix &)
Shallow copy other data structure pointers.
Definition: imat.cpp:200
~i3_array()
Destructor.
Definition: i3arr.cpp:13
void allocate(void)
Does NOT allocate, but set empty i3_array.
Definition: i3arr.cpp:237
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
void initialize(void)
Description not yet available.
Definition: imat3.cpp:20
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void initialize()
Initialize all elements of i3_array to zero.
Definition: i3arr.cpp:243
three_array_shape * shape
Definition: fvar.hpp:3947
int slicemax() const
Definition: fvar.hpp:4033
unsigned int slicesize() const
Definition: fvar.hpp:4054
Description not yet available.
Definition: fvar.hpp:3944
imatrix & elem(int i)
Definition: fvar.hpp:4091