ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
f5arr.cpp
Go to the documentation of this file.
1 
5 #include "fvar.hpp"
6 #include "admb_messages.h"
7 
13 {
14  int mmin = indexmin();
15  int mmax = indexmax();
16  dvar4_array* pti = t + mmin;
17  for (int i = mmin; i <= mmax; ++i)
18  {
19  pti->initialize();
20 
21  ++pti;
22  }
23 }
24 
29 dvar5_array dvar5_array::sub(int nrl,int nrh)
30 {
31  if (allocated(*this))
32  {
33  dvar5_array tmp(nrl,nrh);
34 
35  dvar4_array* pti = t + nrl;
36  dvar4_array* ptmpi = &tmp(nrl);
37  for (int i=nrl; i<=nrh; i++)
38  {
39  ptmpi->shallow_copy(*pti);
40 
41  ++pti;
42  ++ptmpi;
43  }
44 
45  return tmp;
46  }
47  return *this;
48 }
51 {
52  shallow_copy(other);
53 }
60 {
61  if (other.shape)
62  {
63  shape = other.shape;
64  ++(shape->ncopies);
65  t = other.t;
66  }
67  else
68  {
69 #ifdef DEBUG
70  cerr << "Warning -- Unable to shallow copy an unallocated dvar5_array.\n";
71 #endif
72  allocate();
73  }
74 }
80  {
81  d5_array& m2=(d5_array&) _m2;
82  allocate(m2);
83  (*this)=m2;
84  }
87 {
88  if (shape)
89  {
90  if (shape->ncopies > 0)
91  {
92  --(shape->ncopies);
93  }
94  else
95  {
96  t += indexmin();
97  delete [] t;
98  delete shape;
99  }
100  allocate();
101  }
102 #if defined(DIAG)
103  else
104  {
105  cerr << "Warning -- Unable to deallocate an unallocated dvar5_array.\n";
106  }
107 #endif
108 }
111 {
112  deallocate();
113 }
114 
120 {
121  int mmin = indexmin();
122  int mmax = indexmax();
123 #ifndef OPT_LIB
124  if (mmin != m.indexmin() || mmax != m.indexmax())
125  {
126  cerr << "Incompatible bounds in dvar5_array& dvar5_array::operator=(const dvar5_array&)\n";
127  ad_exit(1);
128  }
129 #endif
130  dvar4_array* pti = t + mmin;
131  const dvar4_array* pmi = &m(mmin);
132  for (int i = mmin; i <= mmax; ++i)
133  {
134  *pti = *pmi;
135 
136  ++pti;
137  ++pmi;
138  }
139  return *this;
140 }
141 
147 {
148  int mmin = indexmin();
149  int mmax = indexmax();
150 #ifndef OPT_LIB
151  if (mmin != m.indexmin() || mmax != m.indexmax())
152  {
153  cerr << "Incompatible bounds in dvar5_array& dvar5_array::operator=(const dvar5_array&)\n";
154  ad_exit(1);
155  }
156 #endif
157  dvar4_array* pti = t + mmin;
158  const d4_array* pmi = &m(mmin);
159  for (int i = mmin; i <= mmax; ++i)
160  {
161  *pti = *pmi;
162 
163  ++pti;
164  ++pmi;
165  }
166  return *this;
167 }
168 
173 {
174  int mmin = m1.indexmin();
175  int mmax = m1.indexmax();
176 
177  if ((shape = new vector_shape(mmin, mmax)) == 0)
178  {
179  cerr << " Error: dvar5_array unable to allocate memory in "
180  << __FILE__ << ':' << __LINE__ << '\n';
181  ad_exit(1);
182  }
183  if ( (t = new dvar4_array[size()]) == 0)
184  {
185  cerr << " Error: dvar5_array unable to allocate memory in "
186  << __FILE__ << ':' << __LINE__ << '\n';
187  ad_exit(1);
188  }
189  t -= mmin;
190 
191  dvar4_array* pti = t + mmin;
192  const dvar4_array* pm1i = &m1(mmin);
193  for (int i = mmin; i <= mmax; ++i)
194  {
195  pti->allocate(*pm1i);
196 
197  ++pti;
198  ++pm1i;
199  }
200 }
205 {
206  int mmin = m1.indexmin();
207  int mmax = m1.indexmax();
208  if ((shape = new vector_shape(mmin, mmax)) == 0)
209  {
210  cerr << " Error: dvar5_array unable to allocate memory in "
211  << __FILE__ << ':' << __LINE__ << '\n';
212  ad_exit(1);
213  }
214  if ((t = new dvar4_array[size()]) == 0)
215  {
216  cerr << " Error: dvar5_array unable to allocate memory in "
217  << __FILE__ << ':' << __LINE__ << '\n';
218  ad_exit(1);
219  }
220  t -= mmin;
221  dvar4_array* pti = t + mmin;
222  const d4_array* pm1i = &m1(mmin);
223  for (int i = mmin; i <= mmax; ++i)
224  {
225  pti->allocate(*pm1i);
226 
227  ++pti;
228  ++pm1i;
229  }
230 }
231 
232  #ifndef OPT_LIB
233 
238  dvar4_array& dvar5_array::operator ( ) (int i)
239  {
240  if (i < indexmin() || i > indexmax())
241  {
242  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
243  "dvar3_array& dvar5_array::operator () (int i)",
244  indexmin(), indexmax(), i);
245  }
246  return t[i];
247  }
248 
254  {
255  if (i < indexmin() || i > indexmax())
256  {
257  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
258  "dvar3_array& dvar5_array::operator [] (int i)",
259  indexmin(), indexmax(), i);
260  }
261  return t[i];
262  }
263 
268 dvar3_array& dvar5_array::operator ( ) (int i ,int j)
269 {
270  if (i < indexmin() || i > indexmax())
271  {
272  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
273  "dvar3_array& dvar5_array::operator ( ) (int i,int j)",
274  indexmin(), indexmax(), i);
275  }
276  return (t + i)->operator()(j);
277 }
278 
283 dvar_matrix& dvar5_array::operator ( ) (int i,int j,int k)
284 {
285  if (i < indexmin() || i > indexmax())
286  {
287  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
288  "dvar_matrix& dvar5_array::operator ( ) (int i,int j,int k)",
289  indexmin(), indexmax(), i);
290  }
291  return (t + i)->operator()(j,k);
292 }
293 
298 dvar_vector& dvar5_array::operator ( ) (int i,int j,int k,int l)
299 {
300  if (i < indexmin() || i > indexmax())
301  {
302  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
303  "dvar_vector& dvar5_array::operator ( ) (int i,int j,int k,int l)",
304  indexmin(), indexmax(), i);
305  }
306  return (t + i)->operator()(j,k,l);
307 }
308 
313 prevariable dvar5_array::operator ( ) (int i,int j,int k,int l,int m)
314 {
315  if (i < indexmin() || i > indexmax())
316  {
317  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
318  "prevariable dvar5_array::operator ( ) (int i,int j,int k,int l,int m)",
319  indexmin(), indexmax(), i);
320  }
321  return (t + i)->operator()(j,k,l,m);
322 }
323 
328 const dvar4_array& dvar5_array::operator()(int i) const
329 {
330  if (i<indexmin()||i>indexmax())
331  { cerr << "Error index out of bounds in\n"
332  "dvar4_array& dvar5_array::operator ( )" << endl;
333  ad_exit(1);
334  }
335  return t[i];
336 }
337 
342 const dvar4_array& dvar5_array::operator[](int i) const
343 {
344  if (i<indexmin()||i>indexmax())
345  { cerr << "Error index out of bounds in\n"
346  "dvar4_array& dvar5_array::operator []" << endl;
347  ad_exit(1);
348  }
349  return t[i];
350 }
351 
356 const dvar3_array& dvar5_array::operator()(int i, int j) const
357 {
358  if (i<indexmin()||i>indexmax())
359  { cerr << "Error index out of bounds in\n"
360  "dvar3_array& dvar5_array::operator ( )" << endl;
361  ad_exit(1);
362  }
363  return (t + i)->operator()(j);
364 }
365 
370 const dvar_matrix& dvar5_array::operator()(int i, int j, int k) const
371 {
372  if (i<indexmin()||i>indexmax())
373  { cerr << "Error index out of bounds in\n"
374  "dvar3_array& dvar5_array::operator ( )" << endl;
375  ad_exit(1);
376  }
377  return (t + i)->operator()(j,k);
378 }
379 
384 const dvar_vector& dvar5_array::operator()(int i, int j, int k, int l) const
385 {
386  if (i<indexmin()||i>indexmax())
387  { cerr << "Error hslice index out of bounds in\n"
388  "dvar_vector& dvar5_array::operator ( )" << endl;
389  ad_exit(1);
390  }
391  return (t + i)->operator()(j,k,l);
392 }
393 
398 const prevariable dvar5_array::operator()(int i, int j, int k, int l, int m) const
399 {
400  if (i<indexmin()||i>indexmax())
401  { cerr << "Error hslice index out of bounds in\n"
402  "dvar_vector& dvar5_array::operator ( )" << endl;
403  ad_exit(1);
404  }
405  return (t + i)->operator()(j,k,l,m);
406 }
407 #endif
408 
413 dvar5_array::dvar5_array(int hsl,int hsu,int sl,int sh,int nrl,
414  int nrh,int ncl,int nch,int l5,int u5)
415 {
416  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5);
417 }
418 
424  const index_type& sl,const index_type& sh,const index_type& nrl,
425  const index_type& nrh,const index_type& ncl,const index_type& nch,
426  const index_type& l5,const index_type& u5)
427 {
428  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5);
429 }
430 
436  int hsl, int hsu,
437  int sl, int sh,
438  int nrl, int nrh,
439  int ncl, int nch,
440  int l5, int u5)
441 {
442  if ((shape = new vector_shape(hsl, hsu)) == 0)
443  {
444  cerr << " Error: dvar5_array unable to allocate memory in "
445  << __FILE__ << ':' << __LINE__ << '\n';
446  ad_exit(1);
447  }
448  if ((t = new dvar4_array[size()]) == 0)
449  {
450  cerr << " Error: dvar5_array unable to allocate memory in "
451  << __FILE__ << ':' << __LINE__ << '\n';
452  ad_exit(1);
453  }
454  t -= hsl;
455 
456  dvar4_array* pti = t + hsl;
457  for (int i = hsl; i <= hsu; ++i)
458  {
459  pti->allocate(sl, sh, nrl, nrh, ncl, nch, l5, u5);
460  ++pti;
461  }
462 }
470 dvar5_array::dvar5_array(int hsl, int hsu)
471 {
472  allocate(hsl, hsu);
473 }
481 void dvar5_array::allocate(int hsl, int hsu)
482 {
483  if ((shape = new vector_shape(hsl, hsu)) == 0)
484  {
485  cerr << " Error: dvar5_array unable to allocate memory in "
486  << __FILE__ << ':' << __LINE__ << '\n';
487  ad_exit(1);
488  }
489  if ((t = new dvar4_array[size()]) == 0)
490  {
491  cerr << " Error: dvar5_array unable to allocate memory in "
492  << __FILE__ << ':' << __LINE__ << '\n';
493  ad_exit(1);
494  }
495  t -= hsl;
496  dvar4_array* pti = t + hsl;
497  for (int i = hsl; i <= hsu; ++i)
498  {
499  pti->allocate();
500  ++pti;
501  }
502 }
519  const ad_integer& hsl, const ad_integer& hsu,
520  const index_type& sl, const index_type& sh,
521  const index_type& nrl, const index_type& nrh,
522  const index_type& ncl, const index_type& nch,
523  const index_type& l5, const index_type& u5)
524 {
525  if ((shape = new vector_shape(hsl, hsu)) == 0)
526  {
527  cerr << " Error: dvar5_array unable to allocate memory in "
528  << __FILE__ << ':' << __LINE__ << '\n';
529  ad_exit(1);
530  }
531  if ((t = new dvar4_array[size()]) == 0)
532  {
533  cerr << " Error: dvar5_array unable to allocate memory in "
534  << __FILE__ << ':' << __LINE__ << '\n';
535  ad_exit(1);
536  }
537 
538  int il=hsl;
539  int iu=hsu;
540  t -= il;
541 
542  dvar4_array* pti = t + hsl;
543  for (int i = il; i <= iu; ++i)
544  {
545  pti->allocate(
546  ad_integer(sl(i)), ad_integer(sh(i)),
547  nrl(i), nrh(i),
548  ncl(i), nch(i),
549  l5(i),u5(i));
550  ++pti;
551  }
552 }
~dvar5_array()
Destructor.
Definition: f5arr.cpp:110
Base class for dvariable.
Definition: fvar.hpp:1315
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
unsigned int ncopies
Definition: fvar.hpp:522
Description not yet available.
Definition: fvar.hpp:509
Description not yet available.
Definition: fvar.hpp:5433
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_a59.cpp:13
void shallow_copy(const dvar4_array &)
Shallow copy other data structure pointers.
Definition: f4arr.cpp:28
void initialize(void)
Description not yet available.
Definition: f4arr.cpp:586
dvar5_array()
Description not yet available.
Definition: f5arr3.cpp:17
dvar4_array & operator[](int i)
Definition: fvar.hpp:6586
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
void deallocate(void)
Deallocate dvar5_array memory.
Definition: f5arr.cpp:86
dvar5_array sub(int hhsl, int hhsu)
Description not yet available.
Definition: f5arr.cpp:29
dvar4_array & operator()(int i)
Definition: fvar.hpp:6582
Description not yet available.
Definition: fvar.hpp:5161
dvar5_array & operator=(const d5_array &)
Description not yet available.
Definition: f5arr.cpp:146
int indexmax() const
Definition: fvar.hpp:6650
prnstream & endl(prnstream &)
Description not yet available.
Definition: fvar.hpp:6498
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int indexmin() const
Definition: fvar.hpp:6646
void allocate(int hsl, int hsu, int sl, int sh, int nrl, int nrh, int ncl, int nch)
Allocate variable array with dimensions [hsl to hsu] x [sl to sh] x [nrl to nrh] x [ncl to nch]...
Definition: f4arr.cpp:309
void allocate(void)
Description not yet available.
Definition: f5arr3.cpp:26
dvar4_array * t
Definition: fvar.hpp:6501
Description not yet available.
Definition: fvar.hpp:4197
#define ADMB_ARRAY_BOUNDS_ERROR(message, function, lower_bounds, upper_bounds, index)
Definition: admb_messages.h:47
void initialize()
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: f5arr.cpp:12
int indexmin() const
Definition: fvar.hpp:6475
vector_shape * shape
Definition: fvar.hpp:6500
int indexmax() const
Definition: fvar.hpp:6479
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
Description not yet available.
Definition: fvar.hpp:6331
void shallow_copy(const dvar5_array &)
Shallow copy other data structure pointers.
Definition: f5arr.cpp:59
Stores integer.
Definition: fvar.hpp:7654
unsigned int size() const
Definition: fvar.hpp:6654