ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
i5arr.cpp
Go to the documentation of this file.
1 
5 #include <fvar.hpp>
6 #include "admb_messages.h"
7 
10 {
11  allocate();
12 }
15 {
16  shallow_copy(other);
17 }
23 void i5_array::shallow_copy(const i5_array& other)
24 {
25  if (other.shape)
26  {
27  shape = other.shape;
28  ++(shape->ncopies);
29  t = other.t;
30  }
31  else
32  {
33 #ifdef DEBUG
34  cerr << "Warning -- Unable to shallow copy an unallocated i5_array.\n";
35 #endif
36  allocate();
37  }
38 }
41 {
42  deallocate();
43 }
46 {
47  t = nullptr;
48  shape = nullptr;
49 }
56 i5_array::i5_array(int hsl, int hsu)
57 {
58  allocate(hsl,hsu);
59 }
66 void i5_array::allocate(int hsl, int hsu)
67 {
68  if (hsl > hsu)
69  {
70  return allocate();
71  }
72  if ((t = new i4_array[static_cast<unsigned int>(hsu - hsl + 1)]) == 0)
73  {
74  cerr << " Error allocating memory in i5_array::allocate\n";
75  ad_exit(1);
76  }
77  if ((shape = new vector_shapex(hsl, hsu, t)) == 0)
78  {
79  cerr << " Error allocating memory in i5_array::allocate\n";
80  ad_exit(1);
81  }
82  t -= indexmin();
83  for (int i = hsl; i <= hsu; ++i)
84  {
85  t[i].allocate();
86  }
87 }
93  int hsl, int hsu,
94  int sl, int sh,
95  int nrl, int nrh,
96  int ncl, int nch,
97  int aa, int bb)
98 {
99  allocate(hsl, hsu);
100  for (int i = indexmin(); i <= indexmax(); ++i)
101  {
102  t[i].allocate(sl,sh,nrl,nrh,ncl,nch,aa,bb);
103  }
104 }
105 
110  void i5_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
111  const index_type& sl,const index_type& sh,
112  const index_type& nrl,const index_type& nrh,
113  const index_type& ncl,const index_type& nch,
114  const index_type& aa,const index_type& bb)
115  {
116  unsigned int ss =
117  static_cast<unsigned int>(hsu < hsl ? 0 : hsu - hsl + 1);
118  if (ss>0)
119  {
120  if ( (t = new i4_array[ss]) == 0)
121  {
122  cerr << " Error allocating memory in i5_array contructor\n";
123  ad_exit(21);
124  }
125  if ( (shape=new vector_shapex(hsl,hsu,t)) == 0)
126  {
127  cerr << " Error allocating memory in i5_array contructor\n";
128  ad_exit(21);
129  }
130  t -= indexmin();
131  for (int i=hsl; i<=hsu; i++)
132  {
133  (*this)(i).allocate(ad_integer(sl),ad_integer(sh),nrl(i),nrh(i),
134  ncl(i),nch(i),aa(i),bb(i));
135  }
136  }
137  else
138  {
139  t=0;
140  shape=0;
141  }
142  }
145 {
146  if (shape)
147  {
148  if (shape->ncopies > 0)
149  {
150  --(shape->ncopies);
151  }
152  else
153  {
154  t = static_cast<i4_array*>(shape->get_truepointer());
155  delete [] t;
156  delete shape;
157  }
158  allocate();
159  }
160 #if defined(DIAG)
161  else
162  {
163  cerr << "Warning -- Unable to deallocate an unallocated i5_array.\n";
164  }
165 #endif
166 }
167 
168 #if !defined (OPT_LIB)
169 
172 {
173  return elem(i);
174 }
177 {
178  return elem(i);
179 }
181 i3_array& i5_array::operator()(int i, int j)
182 {
183  return elem(i)(j);
184 }
186 imatrix& i5_array::operator()(int i, int j, int k)
187 {
188  return elem(i)(j, k);
189 }
191 ivector& i5_array::operator()(int i, int j, int k, int l)
192 {
193  return elem(i)(j, k, l);
194 }
196 int& i5_array::operator()(int i, int j, int k, int l, int m)
197 {
198  return elem(i)(j, k, l, m);
199 }
201 const i4_array& i5_array::operator()(int i) const
202 {
203  return elem(i);
204 }
206 const i4_array& i5_array::operator[](int i) const
207 {
208  return elem(i);
209 }
211 const i3_array& i5_array::operator()(int i, int j) const
212 {
213  return elem(i)(j);
214 }
216 const imatrix& i5_array::operator()(int i, int j, int k) const
217 {
218  return elem(i)(j, k);
219 }
221 const ivector& i5_array::operator()(int i, int j, int k, int l) const
222 {
223  return elem(i)(j, k, l);
224 }
226 const int& i5_array::operator()(int i, int j, int k, int l, int m) const
227 {
228  return elem(i)(j, k, l, m);
229 }
230 #endif
233 {
234  const int max = indexmax();
235  for (int i5 = indexmin(); i5 <= max; ++i5)
236  {
237  elem(i5).initialize();
238  }
239 }
void allocate(void)
Does NOT allocate, but initializes i5_array members.
Definition: i5arr.cpp:45
i4_array & operator()(int)
Definition: fvar.hpp:6271
void shallow_copy(const i5_array &)
Shallow copy other data structure pointers.
Definition: i5arr.cpp:23
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
i5_array()
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: i5arr.cpp:9
Description not yet available.
Definition: imatrix.h:69
int indexmin() const
Definition: fvar.hpp:6190
vector_shapex * shape
Definition: fvar.hpp:6069
i4_array & operator[](int)
Definition: fvar.hpp:6275
exitptr ad_exit
Definition: gradstrc.cpp:53
void * get_truepointer(void)
Returns address of first element in the vector.
Definition: vector_shapex.h:64
Description not yet available.
Definition: fvar.hpp:5769
~i5_array()
Destructor.
Definition: i5arr.cpp:40
int indexmax() const
Definition: fvar.hpp:6194
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void allocate(int hsl, int hsu, int sl, int sh, int nrl, int nrh, int ncl, int nch)
Allocate array with dimensions [hsl to hsu] x [sl to sh] x [nrl to nrh] x [ncl to nch]...
Definition: i4arr.cpp:118
void deallocate(void)
Deallocates i5_array memory if no copies exists.
Definition: i5arr.cpp:144
unsigned int ncopies
Copy counter to enable shallow copies.
Definition: vector_shapex.h:79
i4_array * t
Definition: fvar.hpp:6070
Holds &quot;shape&quot; information for vector objects.
Definition: vector_shapex.h:46
Description not yet available.
Definition: fvar.hpp:6067
i4_array & elem(int i)
Definition: fvar.hpp:6248
void initialize()
Initializes elements of i4_array to zero.
Definition: i4arr.cpp:15
Stores integer.
Definition: fvar.hpp:7654
Description not yet available.
Definition: fvar.hpp:3944
#define max(a, b)
Definition: cbivnorm.cpp:189
void initialize()
Initialize i5_array elements with zeros.
Definition: i5arr.cpp:232