ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
f6arr.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 "fvar.hpp"
12 #include "admb_messages.h"
13 
19 {
20  int mmin=indexmin();
21  int mmax=indexmax();
22  dvar5_array* pti = t + mmin;
23  for (int i=mmin; i<=mmax; ++i)
24  {
25  pti->initialize();
26  ++pti;
27  }
28 }
31 {
32  shallow_copy(other);
33 }
40 {
41  if (other.shape)
42  {
43  shape = other.shape;
44  ++(shape->ncopies);
45  t = other.t;
46  }
47  else
48  {
49 #ifdef DEBUG
50  cerr << "Warning -- Unable to shallow copy an unallocated dvar6_array.\n";
51 #endif
52  allocate();
53  }
54 }
55 
61  {
62  d6_array& m2=(d6_array&) _m2;
63  allocate(m2);
64  operator=(m2);
65  }
68 {
69  if (shape)
70  {
71  if (shape->ncopies > 0)
72  {
73  --(shape->ncopies);
74  }
75  else
76  {
77  t += indexmin();
78  delete [] t;
79  delete shape;
80  }
81  allocate();
82  }
83 #if defined(DIAG)
84  else
85  {
86  cerr << "Warning -- Unable to deallocate an unallocated dvar6_array.\n";
87  }
88 #endif
89 }
92 {
93  deallocate();
94 }
95 
101 {
102  int mmin=indexmin();
103  int mmax=indexmax();
104 #ifndef OPT_LIB
105  if (mmin!=m.indexmin() || mmax!=m.indexmax())
106  {
107  cerr << "Incompatible bounds in dvar6_array& dvar6_array::operator=(const dvar6_array&)\n";
108  ad_exit(1);
109  }
110 #endif
111  dvar5_array* pti = t + mmin;
112  const dvar5_array* pmi = &m(mmin);
113  for (int i=mmin; i<=mmax; ++i)
114  {
115  *pti = *pmi;
116  ++pti;
117  ++pmi;
118  }
119  return *this;
120 }
121 
127 {
128  int mmin=indexmin();
129  int mmax=indexmax();
130 #ifndef OPT_LIB
131  if (mmin!=m.indexmin() || mmax!=m.indexmax())
132  {
133  cerr << "Incompatible bounds in dvar6_array& dvar6_array::operator=(const d6_array&)\n";
134  ad_exit(1);
135  }
136 #endif
137  dvar5_array* pti = t + mmin;
138  const d5_array* pmi = &m(mmin);
139  for (int i=mmin; i<=mmax; i++)
140  {
141  *pti = *pmi;
142  ++pti;
143  ++pmi;
144  }
145  return *this;
146 }
147 
152 {
153  int min = m1.indexmin();
154  int max = m1.indexmax();
155  if ((shape=new vector_shape(min, max)) == 0)
156  {
157  cerr << " Error allocating memory in dvar6_array::allocate" << endl;
158  ad_exit(1);
159  }
160  if ((t = new dvar5_array[size()]) == 0)
161  {
162  cerr << " Error allocating memory in dvar6_array::allocate" << endl;
163  ad_exit(1);
164  }
165  t -= min;
166  dvar5_array* pti = t + min;
167  const dvar5_array* pm1i = &m1(min);
168  for (int i = min; i <= max; ++i)
169  {
170  pti->allocate(*pm1i);
171  ++pti;
172  ++pm1i;
173  }
174 }
179 {
180  int min = m1.indexmin();
181  int max = m1.indexmax();
182  if ((shape=new vector_shape(min, max)) == 0)
183  {
184  cerr << "Error allocating memory in dvar5_array contructor" << endl;
185  ad_exit(1);
186  }
187  if ((t = new dvar5_array[size()]) == 0)
188  {
189  cerr << "Error allocating memory in dvar5_array contructor" << endl;
190  ad_exit(21);
191  }
192  t -= min;
193  dvar5_array* pti = t + min;
194  const d5_array* pm1i = &m1(min);
195  for (int i = min; i <= max; ++i)
196  {
197  pti->allocate(*pm1i);
198  ++pti;
199  ++pm1i;
200  }
201 }
202 
203 #ifndef OPT_LIB
204 
209 dvar5_array& dvar6_array::operator ( ) (int i)
210 {
211  if (i < indexmin() || i > indexmax())
212  {
213  ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
214  "dvar5_array& dvar6_array::operator()(int i)",
215  indexmin(), indexmax(), i);
216  }
217  return t[i];
218 }
219 
225 {
226  if (i < indexmin() || i > indexmax())
227  {
228  ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
229  "dvar5_array& dvar6_array::operator[](int i)",
230  indexmin(), indexmax(), i);
231  }
232  return t[i];
233 }
234 
240 {
241  if (i < indexmin() || i > indexmax())
242  {
243  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
244  "dvar5_array& dvar6_array::operator()(int i, int j)",
245  indexmin(), indexmax(), i);
246  }
247  return (t + i)->operator()(j);
248 }
249 
254 dvar3_array& dvar6_array::operator ( ) (int i,int j,int k)
255 {
256  if (i < indexmin() || i > indexmax())
257  {
258  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
259  "dvar5_array& dvar6_array::operator()(int i, int j, int k)",
260  indexmin(), indexmax(), i);
261  }
262  return (t + i)->operator()(j,k);
263 }
264 
269 dvar_matrix& dvar6_array::operator()(int i,int j,int k,int l)
270 {
271  if (i < indexmin() || i > indexmax())
272  {
273  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
274  "dvar_matrix& dvar6_array::operator()(int i, int j, int k, int l)",
275  indexmin(), indexmax(), i);
276  }
277  return (t + i)->operator()(j,k,l);
278 }
279 
284 dvar_vector& dvar6_array::operator()(int i,int j,int k,int l,int m)
285 {
286  if (i < indexmin() || i > indexmax())
287  {
288  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
289  "dvar_vector& dvar6_array::operator()(int i, int j, int k, int l, int m)",
290  indexmin(), indexmax(), i);
291  }
292  return (t + i)->operator()(j,k,l,m);
293 }
294 
299 prevariable dvar6_array::operator()(int i, int j, int k, int l, int m, int n)
300 {
301  if (i < indexmin() || i > indexmax())
302  {
303  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
304 "prevariable dvar6_array::operator()(int i, int j, int k, int l, int m, int n)",
305  indexmin(), indexmax(), i);
306  }
307  return (t + i)->operator()(j,k,l,m,n);
308 }
309 
314 const dvar5_array& dvar6_array::operator()(int i) const
315 {
316  if (i<indexmin()||i>indexmax())
317  { cerr << "Error index out of bounds in\n"
318  "dvar5_array& dvar6_array::operator ( )" << endl;
319  ad_exit(1);
320  }
321  return t[i];
322 }
323 
328 const dvar5_array& dvar6_array::operator[](int i) const
329 {
330  if (i<indexmin()||i>indexmax())
331  { cerr << "Error index out of bounds in\n"
332  "dvar5_array& dvar6_array::operator []" << endl;
333  ad_exit(1);
334  }
335  return t[i];
336 }
337 
342 const dvar4_array& dvar6_array::operator()(int i ,int j) const
343 {
344  if (i<indexmin()||i>indexmax())
345  { cerr << "Error hslice index out of bounds in\n"
346  "dvar_matrix& dvar6_array::operator ( )" << endl;
347  ad_exit(1);
348  }
349  return (t + i)->operator()(j);
350 }
351 
356 const dvar3_array& dvar6_array::operator()(int i, int j, int k) const
357 {
358  if (i<indexmin()||i>indexmax())
359  { cerr << "Error hslice index out of bounds in\n"
360  "dvar_vector& dvar4_array::operator ( )" << endl;
361  ad_exit(1);
362  }
363  return (t + i)->operator()(j,k);
364 }
365 
370 const dvar_matrix& dvar6_array::operator()(int i, int j, int k, int l) const
371 {
372  if (i<indexmin()||i>indexmax())
373  { cerr << "Error hslice index out of bounds in\n"
374  "dvar-vector& dvar4_array::operator ( )" << endl;
375  ad_exit(1);
376  }
377  return (t + i)->operator()(j,k,l);
378 }
379 
384 const dvar_vector& dvar6_array::operator()(int i, int j, int k, int l, int m)
385  const
386 {
387  if (i<indexmin()||i>indexmax())
388  { cerr << "Error hslice index out of bounds in\n"
389  "prevariable& dvar4_array::operator ( )" << endl;
390  ad_exit(1);
391  }
392  return (t + i)->operator()(j,k,l,m);
393 }
394 
399 const prevariable dvar6_array::operator()(int i, int j, int k, int l, int m,
400  int n) const
401 {
402  if (i<indexmin()||i>indexmax())
403  {
404  cerr << "Error hslice index out of bounds in\n"
405  "prevariable& dvar4_array::operator ( )" << endl;
406  ad_exit(1);
407  }
408  return (t + i)->operator()(j,k,l,m,n);
409 }
410 #endif
411 
416 dvar6_array::dvar6_array(int hsl,int hsu)
417 {
418  allocate(hsl,hsu);
419 }
420 
421 
426 dvar6_array::dvar6_array(int hsl,int hsu,int sl,int sh,int nrl,
427  int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
428 {
429  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
430 }
431 
437  const index_type& sl,const index_type& sh,const index_type& nrl,
438  const index_type& nrh,const index_type& ncl,const index_type& nch,
439  const index_type& l5,const index_type& u5,
440  const index_type& l6,const index_type& u6)
441 {
442  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
443 }
444 
449 void dvar6_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
450  int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
451  {
452  if ( (shape=new vector_shape(hsl,hsu)) == 0)
453  {
454  cerr << " Error allocating memory in dvar5_array contructor\n";
455  ad_exit(21);
456  }
457  if ( (t = new dvar5_array[size()]) == 0)
458  {
459  cerr << " Error allocating memory in dvar5_array contructor\n";
460  ad_exit(21);
461  }
462  t -= hsl;
463  dvar5_array* pti = t + hsl;
464  for (int i=hsl; i<=hsu; i++)
465  {
466  pti->allocate(sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
467  ++pti;
468  }
469  }
470 
475  void dvar6_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
476  const index_type& sl,const index_type& sh,const index_type& nrl,
477  const index_type& nrh,const index_type& ncl,const index_type& nch,
478  const index_type& l5,const index_type& u5,
479  const index_type& l6,const index_type& u6)
480  {
481  if ( (shape=new vector_shape (hsl,hsu)) == 0)
482  {
483  cerr << " Error allocating memory in dvar5_array contructor\n";
484  }
485 
486  if ( (t = new dvar5_array[size()]) == 0)
487  {
488  cerr << " Error allocating memory in dvar5_array contructor\n";
489  ad_exit(21);
490  }
491  t -= hsl;
492  dvar5_array* pti = t + hsl;
493  for (int i = hsl; i <= hsu; ++i)
494  {
495  pti->allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
496  ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i));
497  ++pti;
498  }
499  }
500 
507 void dvar6_array::allocate(int hsl, int hsu)
508 {
509  if ((shape = new vector_shape(hsl, hsu)) == 0)
510  {
511  cerr << " Error allocating memory in dvar5_array contructor\n";
512  ad_exit(1);
513  }
514  if ((t = new dvar5_array[size()]) == 0)
515  {
516  cerr << " Error allocating memory in dvar5_array contructor\n";
517  ad_exit(1);
518  }
519  t -= hsl;
520  dvar5_array* pti = t + hsl;
521  for (int i = hsl; i <= hsu; ++i)
522  {
523  pti->allocate();
524  ++pti;
525  }
526 }
Base class for dvariable.
Definition: fvar.hpp:1315
dvar5_array & operator[](int i)
Definition: fvar.hpp:6956
void deallocate(void)
Deallocate dvar6_array memory.
Definition: f6arr.cpp:67
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
Description not yet available.
Definition: fvar.hpp:6861
unsigned int ncopies
Definition: fvar.hpp:522
Description not yet available.
Definition: fvar.hpp:509
int indexmin() const
Definition: fvar.hpp:6812
Description not yet available.
Definition: fvar.hpp:5433
unsigned int size() const
Definition: fvar.hpp:7036
dvar5_array * t
Definition: fvar.hpp:6864
~dvar6_array()
Destructor.
Definition: f6arr.cpp:91
vector_shape * shape
Definition: fvar.hpp:6863
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
Description not yet available.
Definition: fvar.hpp:6673
dvar6_array()
Description not yet available.
Definition: f6arr2.cpp:17
void allocate(int hhsl, int hhsu, int hsl, int hsu, int sl, int sh, int nrl, int nrh, int ncl, int nch)
Allocate dvar5_array with dimensions [hsl to hsu] x [sl to sh] x [nrl to nrh] x [ncl to nch] x [l5 to...
Definition: f5arr.cpp:435
prnstream & endl(prnstream &)
dvar5_array & operator()(int i)
Definition: fvar.hpp:6952
#define min(a, b)
Definition: cbivnorm.cpp:188
Description not yet available.
Definition: fvar.hpp:6498
void allocate(void)
Description not yet available.
Definition: f6arr2.cpp:26
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int indexmax() const
Definition: fvar.hpp:6816
int indexmin() const
Definition: fvar.hpp:7028
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
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
Description not yet available.
Definition: fvar.hpp:6331
int indexmax() const
Definition: fvar.hpp:7032
void shallow_copy(const dvar6_array &)
Shallow copy other data structure pointers.
Definition: f6arr.cpp:39
Stores integer.
Definition: fvar.hpp:7654
#define max(a, b)
Definition: cbivnorm.cpp:189
void initialize()
Description not yet available.
Definition: f6arr.cpp:18
dvar6_array & operator=(const d6_array &)
Description not yet available.
Definition: f6arr.cpp:126