ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
f1b23d1.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <df1b2fun.h>
12 #include "admb_messages.h"
13 
18 df1b23array::df1b23array(int nrl,int nrh,int ncl,int nch,int nxl,int nxh)
19 {
20  if (nrl>nrh)
21  {
22  allocate();
23  }
24  else
25  {
26  allocate(nrl,nrh,ncl,nch,nxl,nxh);
27  }
28 }
29 
34 df1b23array::df1b23array(int nrl,int nrh,int ncl,int nch)
35 {
36  if (nrl>nrh)
37  {
38  allocate();
39  }
40  else
41  {
42  allocate(nrl,nrh,ncl,nch);
43  }
44 }
45 
50 df1b23array::df1b23array(int nrl,int nrh)
51 {
52  if (nrl>nrh)
53  {
54  allocate();
55  }
56  else
57  {
58  allocate(nrl,nrh);
59  }
60 }
61 
67 {
68  allocate();
69 }
70 
75 void df1b23array::allocate(int nrl,int nrh,int ncl,int nch,
76  int nxl,int nxh,const char * s)
77 {
78  allocate(nrl,nrh,ncl,nch,nxl,nxh);
79 }
80 
81 /*
82 void df1b23array::allocate(int nrl,int nrh,int ncl,int nch,const char * s)
83 {
84  allocate(nrl,nrh,ncl,nch);
85 }
86 
87 void df1b23array::allocate(int nrl,int nrh,const index_type& ncl,
88  const index_type& nch,const char * s)
89 {
90  allocate(nrl,nrh,ncl,nch);
91 }
92 */
93 
98 void df1b23array::allocate(int nrl,int nrh,
99  const index_type& ncl, const index_type& nch,
100  const index_type& nxl, const index_type& nxh,
101  const char * s)
102 {
103  allocate(nrl,nrh,ncl,nch,nxl,nxh);
104 }
105 
110 void df1b23array::allocate(int nrl,int nrh,int ncl,int nch,
111  int nxl,int nxh)
112 {
113  index_min=nrl;
114  index_max=nrh;
115  if ((v = new df1b2matrix[size()]) == 0)
116  {
117  cerr << " Error allocating memory in df1b23array contructor\n";
118  ad_exit(21);
119  }
120  if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
121  {
122  cerr << " Error allocating memory in df1b23array contructor\n";
123  }
124  v -= indexmin();
125  for (int i=nrl; i<=nrh; i++)
126  {
127  v[i].allocate(ncl,nch,nxl,nxh);
128  }
129 }
130 
135 void df1b23array::allocate(int nrl,int nrh,int ncl,int nch)
136 {
137  index_min=nrl;
138  index_max=nrh;
139  if ((v = new df1b2matrix[size()]) == 0)
140  {
141  cerr << " Error allocating memory in df1b23array contructor\n";
142  ad_exit(21);
143  }
144  if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
145  {
146  cerr << " Error allocating memory in df1b23array contructor\n";
147  ad_exit(21);
148  }
149  v -= indexmin();
150  for (int i=nrl; i<=nrh; i++)
151  {
152  v[i].allocate(ncl,nch);
153  }
154 }
155 
160 void df1b23array::allocate(int nrl,int nrh,const index_type& ncl,
161  const index_type& nch)
162 {
163  index_min=nrl;
164  index_max=nrh;
165  if ((v = new df1b2matrix[size()]) == 0)
166  {
167  cerr << " Error allocating memory in df1b23array contructor\n";
168  ad_exit(21);
169  }
170  if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
171  {
172  cerr << " Error allocating memory in df1b23array contructor\n";
173  }
174  v -= indexmin();
175  for (int i=nrl; i<=nrh; i++)
176  {
177  v[i].allocate(ad_integer(ncl(i)),ad_integer(nch(i)));
178  }
179 }
180 
185 void df1b23array::allocate(int nrl,int nrh,
186  const index_type& ncl,const index_type& nch,
187  const index_type& nxl,const index_type& nxh)
188 {
189  index_min=nrl;
190  index_max=nrh;
191  if ((v = new df1b2matrix[size()]) == 0)
192  {
193  cerr << " Error allocating memory in df1b23array contructor\n";
194  ad_exit(21);
195  }
196  if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
197  {
198  cerr << " Error allocating memory in df1b23array contructor\n";
199  }
200  v -= indexmin();
201  for (int i=nrl; i<=nrh; i++)
202  {
203  v[i].allocate(ad_integer(ncl(i)),ad_integer(nch(i)),nxl(i),nxh(i));
204  }
205 }
222  const int nrl, const int nrh,
223  const ivector& ncl, const ivector& nch,
224  const int nxl, const int nxh,
225  const char* s)
226 {
227  index_min=nrl;
228  index_max=nrh;
229  if ( (v = new df1b2matrix[size()]) == 0)
230  {
231  cerr << " Error allocating memory in df1b23array contructor\n";
232  ad_exit(21);
233  }
234  if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
235  {
236  cerr << " Error allocating memory in df1b23array contructor\n";
237  }
238  v -= indexmin();
239  for (int i=nrl; i<=nrh; i++)
240  {
241  v[i].allocate(ncl(i), nch(i), nxl, nxh);
242  }
243 }
248 {
249  index_min = x.index_min;
250  index_max = x.index_max;
251  v = x.v;
252  shape = x.shape;
253  if (shape) (shape->ncopies)++;
254 }
261 void df1b23array::allocate(int nrl,int nrh)
262 {
263  index_min=nrl;
264  index_max=nrh;
265  if ((v = new df1b2matrix[size()]) == 0)
266  {
267  cerr << " Error allocating memory in df1b23array contructor\n";
268  ad_exit(21);
269  }
270  if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
271  {
272  cerr << " Error allocating memory in df1b23array contructor\n";
273  }
274  v -= indexmin();
275 }
280 {
281  if (shape)
282  {
283  if (shape->ncopies)
284  {
285  (shape->ncopies)--;
286  }
287  else
288  {
289  deallocate();
290  }
291  }
292 }
297 {
298  if (shape)
299  {
300  v=(df1b2matrix*)(shape->trueptr);
301  delete [] v;
302  v=0;
303  delete shape;
304  shape=0;
305  index_min=1;
306  index_max=0;
307  }
308 }
313 {
314  index_min=1;
315  index_max=0;
316  v=0;
317  shape=0;
318 }
319 
325 {
327  df1b2variable tmp;
328  tmp=0.0;
329  int mmin=x.indexmin();
330  int mmax=x.indexmax();
331  for (int i=mmin;i<=mmax;i++)
332  {
333  tmp+=sum(x(i));
334  }
335  return tmp;
336 }
337 
338 #if !defined(OPT_LIB)
339 
344 df1b2variable& df1b23array::operator () (int i,int j,int k)
345 {
346  if (i < indexmin() || i > indexmax())
347  {
348  ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
349  "df1b2variable& df1b23array::operator () (int i,int j,int k)",
350  indexmin(), indexmax(), i);
351  }
352  return v[i][j][k];
353 }
354 
360 {
361  if (i < indexmin() || i > indexmax())
362  {
363  ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
364  "df1b2vector& df1b23array::operator () (int i,int j)",
365  indexmin(), indexmax(), i);
366  }
367  return v[i][j];
368 }
369 
375 {
376  if (i < indexmin() || i > indexmax())
377  {
378  ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
379  "df1b2matrix& df1b23array::operator () (int i)",
380  indexmin(), indexmax(), i);
381  }
382  return v[i];
383 }
384 
390 {
391  if (i < indexmin() || i > indexmax())
392  {
393  ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
394  "df1b2matrix& df1b23array::operator [] (int i)",
395  indexmin(), indexmax(), i);
396  }
397  return v[i];
398 }
399 
400 #endif // #if !defined(OPT_LIB)
401 
407 {
408  int rmin=indexmin();
409  int rmax=indexmax();
410  for (int i=rmin;i<=rmax;i++)
411  {
412  (*this)(i).initialize();
413  }
414 }
vector_shapex * shape
Definition: df1b2fun.h:1124
void * trueptr
Address of first element in the vector.
Definition: vector_shapex.h:82
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
df1b2matrix & operator[](int i)
Definition: df1b2fun.h:1178
int index_max
Definition: df1b2fun.h:1122
#define x
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
~df1b23array()
Destructor.
Definition: f1b23d1.cpp:279
void allocate(int nrl, int nrh, int ncl, int nch)
Description not yet available.
Definition: f1b2vc5.cpp:663
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
int index_min
Definition: df1b2fun.h:1121
Description not yet available.
Definition: df1b2fun.h:953
exitptr ad_exit
Definition: gradstrc.cpp:53
df1b2matrix * v
Definition: df1b2fun.h:1123
void allocate(void)
Does not allocate, but initialize member variables.
Definition: f1b23d1.cpp:312
Description not yet available.
Definition: df1b2fun.h:266
int indexmin(void)
Definition: df1b2fun.h:1129
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
Description not yet available.
Definition: df1b2fun.h:1119
unsigned int ncopies
Copy counter to enable shallow copies.
Definition: vector_shapex.h:79
#define ADMB_ARRAY_BOUNDS_ERROR(message, function, lower_bounds, upper_bounds, index)
Definition: admb_messages.h:47
Holds &quot;shape&quot; information for vector objects.
Definition: vector_shapex.h:46
int indexmax(void)
Definition: df1b2fun.h:1130
Description not yet available.
Definition: df1b2fun.h:1042
Description not yet available.
unsigned int size() const
Definition: df1b2fun.h:1131
Stores integer.
Definition: fvar.hpp:7654
void initialize(void)
Description not yet available.
Definition: f1b23d1.cpp:406
void deallocate(void)
Deallocates class memory memory.
Definition: f1b23d1.cpp:296
df1b23array(void)
Description not yet available.
Definition: f1b23d1.cpp:66
df1b2variable & operator()(int i, int j, int k)
Definition: df1b2fun.h:1175