ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
f7arr.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  dvar6_array* pti = t + mmin;
23  for (int i=mmin; i<=mmax; i++)
24  {
25  pti->initialize();
26  ++pti;
27  }
28  }
29 
36 void dvar7_array::allocate(int l7, int u7)
37 {
38  if ((shape = new vector_shape(l7, u7)) == 0)
39  {
40  cerr << " Error allocating memory in d6_array contructor\n";
41  ad_exit(21);
42  }
43  unsigned int ss = size();
44  if ((t = new dvar6_array[ss]) == 0)
45  {
46  cerr << " Error allocating memory in d6_array contructor\n";
47  ad_exit(21);
48  }
49  t -= indexmin();
50  dvar6_array* pti = t + l7;
51  for (int i = l7; i <= u7; ++i)
52  {
53  pti->allocate();
54  ++pti;
55  }
56 }
57 
60 {
61  shallow_copy(other);
62 }
69 {
70  if (other.shape)
71  {
72  shape = other.shape;
73  ++(shape->ncopies);
74  t = other.t;
75  }
76  else
77  {
78 #ifdef DEBUG
79  cerr << "Warning -- Unable to shallow copy an unallocated dvar7_array.\n";
80 #endif
81  allocate();
82  }
83 }
85 
91  {
92  allocate(m2);
93  (*this)=m2;
94  }
97 {
98  if (shape)
99  {
100  if (shape->ncopies > 0)
101  {
102  --(shape->ncopies);
103  }
104  else
105  {
106  t += indexmin();
107  delete [] t;
108  delete shape;
109  }
110  allocate();
111  }
112 #if defined(DIAG)
113  else
114  {
115  cerr << "Warning -- Unable to deallocate an unallocated dvar7_array.\n";
116  }
117 #endif
118 }
119 
125  {
126  deallocate();
127  }
128 
134  {
135  int mmin=indexmin();
136  int mmax=indexmax();
137 #ifndef OPT_LIB
138  if (mmin!=m.indexmin() || mmax!=m.indexmax())
139  {
140  cerr << "Incompatible bounds in"
141  " dvar5_array& dvar5_array:: operator = (const dvar5_array& m)"
142  << endl;
143  ad_exit(1);
144  }
145 #endif
146  dvar6_array* pti = t + mmin;
147  const dvar6_array* pmi = &m(mmin);
148  for (int i=mmin; i<=mmax; i++)
149  {
150  *pti = *pmi;
151  ++pti;
152  ++pmi;
153  }
154  return *this;
155  }
156 
162  {
163  int mmin=indexmin();
164  int mmax=indexmax();
165 #ifndef OPT_LIB
166  if (mmin!=m.indexmin() || mmax!=m.indexmax())
167  {
168  cerr << "Incompatible bounds in"
169  " dvar7_array& dvar7_array:: operator = (const d7_array& m)"
170  << endl;
171  ad_exit(1);
172  }
173 #endif
174  dvar6_array* pti = t + mmin;
175  const d6_array* pmi = &m(mmin);
176  for (int i=mmin; i<=mmax; i++)
177  {
178  *pti = *pmi;
179 
180  ++pti;
181  ++pmi;
182  }
183  return *this;
184  }
185 
192 {
193  int mmin = m1.indexmin();
194  int mmax = m1.indexmax();
195  if ((shape = new vector_shape(mmin, mmax)) == 0)
196  {
197  cerr << " Error allocating memory in dvar6_array contructor" << endl;
198  }
199  unsigned int ss = size();
200  if ((t = new dvar6_array[ss]) == 0)
201  {
202  cerr << " Error allocating memory in dvar6_array contructor" << endl;
203  ad_exit(21);
204  }
205  t -= mmin;
206  dvar6_array* pti = t + mmin;
207  const dvar6_array* pm1i = &m1(mmin);
208  for (int i = mmin; i <= mmax; ++i)
209  {
210  pti->allocate(*pm1i);
211  ++pm1i;
212  ++pti;
213  }
214 }
215 
221 {
222  int mmin = m1.indexmin();
223  int mmax = m1.indexmax();
224  if ((shape = new vector_shape(mmin, mmax)) == 0)
225  {
226  cerr << " Error allocating memory in dvar6_array contructor" << endl;
227  }
228  unsigned int ss = size();
229  if ((t = new dvar6_array[ss]) == 0)
230  {
231  cerr << " Error allocating memory in dvar6_array contructor" << endl;
232  ad_exit(21);
233  }
234  t -= mmin;
235  dvar6_array* pti = t + mmin;
236  const d6_array* pm1i = &m1(mmin);
237  for (int i = mmin; i <= mmax; ++i)
238  {
239  pti->allocate(*pm1i);
240  ++pm1i;
241  ++pti;
242  }
243 }
244 
245  #ifndef OPT_LIB
246 
251  dvar6_array& dvar7_array::operator ( ) (int i)
252  {
253  if (i < indexmin() || i > indexmax())
254  {
255  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
256  "dvar6_array& dvar7_array::operator () (int i)",
257  indexmin(), indexmax(), i);
258  }
259  return t[i];
260  }
261 
267  {
268  if (i < indexmin() || i > indexmax())
269  {
270  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
271  "dvar6_array& dvar7_array::operator [] (int i)",
272  indexmin(), indexmax(), i);
273  }
274  return t[i];
275  }
276 
282 {
283  if (i < indexmin() || i > indexmax())
284  {
285  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
286  "dvar5_array& dvar7_array::operator ( ) (int i, int j)",
287  indexmin(), indexmax(), i);
288  }
289  return (t + i)->operator()(j);
290 }
291 
296 dvar4_array& dvar7_array::operator()(int i, int j, int k)
297 {
298  if (i < indexmin() || i > indexmax())
299  {
300  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
301  "dvar4_array& dvar7_array::operator ( ) (int i, int j, int k)",
302  indexmin(), indexmax(), i);
303  }
304  return (t + i)->operator()(j,k);
305 }
306 
311 dvar3_array& dvar7_array::operator()(int i, int j, int k, int l)
312 {
313  if (i < indexmin() || i > indexmax())
314  {
315  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
316  "dvar3_array& dvar7_array::operator ( ) (int i, int j, int k, int l)",
317  indexmin(), indexmax(), i);
318  }
319  return (t + i)->operator()(j,k,l);
320 }
321 
326 dvar_matrix& dvar7_array::operator()(int i,int j,int k,int l,int m)
327 {
328  if (i < indexmin() || i > indexmax())
329  {
330  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
331  "dvar_matrix& dvar7_array::operator()(int i, int j, int k, int l, int m)",
332  indexmin(), indexmax(), i);
333  }
334  return (t + i)->operator()(j,k,l,m);
335 }
336 
341 dvar_vector& dvar7_array::operator ( ) (int i,int j,int k,int l,int m, int n)
342 {
343  if (i < indexmin() || i > indexmax())
344  {
345  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
346 "dvar_vector& dvar7_array::operator()(int i,int j, int k, int l, int m, int n)",
347  indexmin(), indexmax(), i);
348  }
349  return (t + i)->operator()(j,k,l,m,n);
350 }
351 
356 prevariable dvar7_array::operator()(int i,int j,int k,int l,int m, int n,int _p)
357 {
358  if (i < indexmin() || i > indexmax())
359  {
360  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
361 "dvar7_array::operator()(int i, int j, int k, int l, int m, int n, int _p)",
362  indexmin(), indexmax(), i);
363  }
364  return (t + i)->operator()(j,k,l,m,n,_p);
365 }
366 
371 const dvar6_array& dvar7_array::operator()(int i) const
372  {
373  if (i<indexmin()||i>indexmax())
374  { cerr << "Error index out of bounds in\n"
375  "dvar6_array& dvar7_array::operator ( )" << endl;
376  ad_exit(1);
377  }
378  return t[i];
379  }
380 
385 const dvar6_array& dvar7_array::operator[](int i) const
386  {
387  if (i<indexmin()||i>indexmax())
388  { cerr << "Error index out of bounds in\n"
389  "dvar5_array& dvar6_array::operator []" << endl;
390  ad_exit(1);
391  }
392  return t[i];
393  }
394 
399 const dvar5_array& dvar7_array::operator()(int i ,int j) const
400 {
401  if (i<indexmin()||i>indexmax())
402  { cerr << "Error hslice index out of bounds in\n"
403  "dvar3_array& dvar7_array::operator ( )" << endl;
404  ad_exit(1);
405  }
406  return (t + i)->operator()(j);
407 }
408 
413 const dvar4_array& dvar7_array::operator()(int i,int j,int k) const
414 {
415  if (i<indexmin()||i>indexmax())
416  { cerr << "Error hslice index out of bounds in\n"
417  "dvar_matrix& dvar7_array::operator ( )" << endl;
418  ad_exit(1);
419  }
420  return (t + i)->operator()(j,k);
421 }
422 
427 const dvar3_array& dvar7_array::operator()(int i, int j, int k, int l) const
428 {
429  if (i<indexmin()||i>indexmax())
430  { cerr << "Error hslice index out of bounds in\n"
431  "dvar-vector& dvar7_array::operator ( )" << endl;
432  ad_exit(1);
433  }
434  return (t + i)->operator()(j,k,l);
435 }
436 
441 const dvar_matrix& dvar7_array::operator()(int i, int j, int k, int l, int m) const
442 {
443  if (i<indexmin()||i>indexmax())
444  { cerr << "Error hslice index out of bounds in\n"
445  "prevariable& dvar7_array::operator ( )" << endl;
446  ad_exit(1);
447  }
448  return (t + i)->operator()(j,k,l,m);
449 }
450 
455 const dvar_vector& dvar7_array::operator()(int i, int j, int k, int l, int m,
456  int n) const
457 {
458  if (i<indexmin()||i>indexmax())
459  { cerr << "Error hslice index out of bounds in\n"
460  "prevariable& dvar7_array::operator ( )" << endl;
461  ad_exit(1);
462  }
463  return (t + i)->operator()(j,k,l,m,n);
464 }
465 
470 const prevariable dvar7_array::operator()(int i, int j, int k, int l, int m,
471  int n, int _p) const
472 {
473  if (i<indexmin()||i>indexmax())
474  { cerr << "Error hslice index out of bounds in\n"
475  "prevariable& dvar7_array::operator ( )" << endl;
476  ad_exit(1);
477  }
478  return (t + i)->operator()(j,k,l,m,n,_p);
479 }
480 #endif
481 
486 dvar7_array::dvar7_array(int hsl,int hsu,int sl,int sh,int nrl,
487  int nrh,int ncl,int nch,int l5,int u5,int l6,int u6,int l7,int u7)
488 {
489  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
490 }
491 
497  const index_type& sl,const index_type& sh,const index_type& nrl,
498  const index_type& nrh,const index_type& ncl,const index_type& nch,
499  const index_type& l5,const index_type& u5,
500  const index_type& l6,const index_type& u6,
501  const index_type& l7,const index_type& u7)
502 {
503  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
504 }
505 
509 void dvar7_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
510  int nrh,int ncl,int nch,int l5,int u5,int l6,int u6,int l7,int u7)
511 {
512  if ((shape = new vector_shape(hsl, hsu)) == 0)
513  {
514  cerr << " Error allocating memory in dvar6_array contructor\n";
515  ad_exit(21);
516  }
517  unsigned int ss = size();
518  if ((t = new dvar6_array[ss]) == 0)
519  {
520  cerr << " Error allocating memory in dvar6_array contructor\n";
521  ad_exit(21);
522  }
523  t -= hsl;
524  dvar6_array* pti = t + hsl;
525  for (int i = hsl; i <= hsu; ++i)
526  {
527  pti->allocate(sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
528  ++pti;
529  }
530 }
531 
536  const ad_integer& hsl, const ad_integer& hsu,
537  const index_type& sl, const index_type& sh,
538  const index_type& nrl, const index_type& nrh,
539  const index_type& ncl, const index_type& nch,
540  const index_type& l5, const index_type& u5,
541  const index_type& l6, const index_type& u6,
542  const index_type& l7, const index_type& u7)
543 {
544  if ((shape = new vector_shape(hsl, hsu)) == 0)
545  {
546  cerr << " Error allocating memory in dvar6_array contructor\n";
547  }
548  unsigned int ss = size();
549  if ((t = new dvar6_array[ss]) == 0)
550  {
551  cerr << " Error allocating memory in dvar6_array contructor\n";
552  ad_exit(21);
553  }
554  t -= indexmin();
555  int il=hsl;
556  int iu=hsu;
557  dvar6_array* pti = t + il;
558  for (int i=il; i<=iu; i++)
559  {
560  pti->allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
561  ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i),l7(i),u7(i));
562  ++pti;
563  }
564 }
void allocate(int hhsl, int hhsu)
Allocate vector of dvar5_array with dimension [hsl to hsu].
Definition: f6arr.cpp:507
Base class for dvariable.
Definition: fvar.hpp:1315
dvar6_array * t
Definition: fvar.hpp:7265
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:7054
Description not yet available.
Definition: fvar.hpp:6861
unsigned int ncopies
Definition: fvar.hpp:522
void shallow_copy(const dvar7_array &)
Shallow copy other data structure pointers.
Definition: f7arr.cpp:68
Description not yet available.
Definition: fvar.hpp:509
Description not yet available.
Definition: fvar.hpp:5433
dvar6_array & operator[](int i)
Definition: fvar.hpp:7367
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
dvar6_array & operator()(int i)
Definition: fvar.hpp:7363
Description not yet available.
Definition: fvar.hpp:6673
int indexmax() const
Definition: fvar.hpp:7455
int indexmax() const
Definition: fvar.hpp:7218
~dvar7_array()
Description not yet available.
Definition: f7arr.cpp:124
prnstream & endl(prnstream &)
Description not yet available.
Definition: fvar.hpp:6498
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
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 allocate(void)
Description not yet available.
Definition: f7arr2.cpp:26
dvar7_array & operator=(const d7_array &)
Description not yet available.
Definition: f7arr.cpp:161
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
int indexmin() const
Definition: fvar.hpp:7451
void deallocate(void)
Deallocate dvar7_array memory.
Definition: f7arr.cpp:96
unsigned int size() const
Definition: fvar.hpp:7459
Description not yet available.
Definition: fvar.hpp:7262
int indexmin() const
Definition: fvar.hpp:7214
Stores integer.
Definition: fvar.hpp:7654
vector_shape * shape
Definition: fvar.hpp:7264
dvar7_array()
Description not yet available.
Definition: f7arr2.cpp:17
void initialize()
Description not yet available.
Definition: f6arr.cpp:18
void initialize()
Description not yet available.
Definition: f7arr.cpp:18