ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
f4arr.cpp
Go to the documentation of this file.
1 
5 #include "fvar.hpp"
6 #include "admb_messages.h"
7 
14 dvar4_array::dvar4_array(int nrl, int nrh)
15 {
16  allocate(nrl, nrh);
17 }
20 {
21  shallow_copy(other);
22 }
29 {
30  if (other.shape)
31  {
32  shape = other.shape;
33  ++(shape->ncopies);
34  t = other.t;
35  }
36  else
37  {
38 #ifdef DEBUG
39  cerr << "Warning -- Unable to shallow copy an unallocated dvar4_array.\n";
40 #endif
41  allocate();
42  }
43 }
44 
49  dvar4_array dvar4_array::sub(int nrl,int nrh)
50  {
51  if (allocated(*this))
52  {
53  dvar4_array tmp(nrl,nrh);
54  for (int i=nrl; i<=nrh; i++)
55  {
56  tmp[i].shallow_copy((*this)(i));
57  }
58  return tmp;
59  }
60  else
61  {
62  return *this;
63  }
64  }
67 {
68  if (shape)
69  {
70  if (shape->ncopies > 0)
71  {
72  --(shape->ncopies);
73  }
74  else
75  {
76  t += indexmin();
77  delete [] t;
78  delete shape;
79  }
80  allocate();
81  }
82 #if defined(DIAG)
83  else
84  {
85  cerr << "Warning -- Unable to deallocate an unallocated dvar4_array.\n";
86  }
87 #endif
88 }
89 
92 {
93  deallocate();
94 }
95 
96 #ifndef OPT_LIB
97 
102  dvar3_array& dvar4_array::operator ( ) (int i)
103  {
104  if (i < hslicemin() || i > hslicemax())
105  {
106  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
107  "dvar3_array& dvar4_array::operator() (int i)",
108  hslicemin(), hslicemax(), i);
109  }
110  return t[i];
111  }
112 
118  {
119  if (i < hslicemin() || i > hslicemax())
120  {
121  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
122  "dvar3_array& dvar4_array::operator[] (int i)",
123  hslicemin(), hslicemax(), i);
124  }
125  return t[i];
126  }
127 
133 {
134  if (i < hslicemin() || i > hslicemax())
135  {
136  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
137  "dvar_matrix& dvar4_array::operator() (int i, int j)",
138  hslicemin(), hslicemax(), i);
139  }
140  return (t + i)->operator()(j);
141 }
142 
147 dvar_vector& dvar4_array::operator()(int i, int j, int k)
148 {
149  if (i < hslicemin() || i > hslicemax())
150  {
151  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
152  "dvar_vector& dvar4_array::operator() (int i, int j, int k)",
153  hslicemin(), hslicemax(), i);
154  }
155  return (t + i)->operator()(j, k);
156 }
157 
162  prevariable dvar4_array::operator ( ) (int i,int j,int k,int l)
163  {
164  if (i < hslicemin() || i > hslicemax())
165  {
166  ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
167  "prevariable& dvar4_array::operator() (int i, int j, int k)",
168  hslicemin(), hslicemax(), i);
169  }
170  return ( ((*this)(i,j,k))(l));
171  }
172 
177 const dvar3_array& dvar4_array::operator()(int i) const
178  {
179  if (i<hslicemin()||i>hslicemax())
180  { cerr << "Error hslice index out of bounds in\n"
181  "dvar3_array& dvar4_array::operator ( )" << endl;
182  ad_exit(1);
183  }
184  return t[i];
185  }
186 
191 const dvar3_array& dvar4_array::operator[](int i) const
192  {
193  if (i<hslicemin()||i>hslicemax())
194  { cerr << "Error hslice index out of bounds in\n"
195  "dvar3_array& dvar4_array::operator ( )" << endl;
196  ad_exit(1);
197  }
198  return t[i];
199  }
200 
205 const dvar_matrix& dvar4_array::operator()(int i, int j) const
206 {
207  if (i<hslicemin()||i>hslicemax())
208  { cerr << "Error hslice index out of bounds in\n"
209  "dvarmatrix& dvar4_array::operator ( )" << endl;
210  ad_exit(1);
211  }
212  return (t + i)->operator()(j);
213 }
214 
219 const dvar_vector& dvar4_array::operator()(int i, int j, int k) const
220 {
221  if (i<hslicemin()||i>hslicemax())
222  { cerr << "Error hslice index out of bounds in\n"
223  "dvarvector& dvar4_array::operator ( )" << endl;
224  ad_exit(1);
225  }
226  return (t + i)->operator()(j, k);
227 }
228 
233 const prevariable dvar4_array::operator()(int i, int j, int k, int l) const
234 {
235  if (i<hslicemin()||i>hslicemax())
236  { cerr << "Error hslice index out of bounds in\n"
237  "double& dvar4_array::operator ( )" << endl;
238  ad_exit(1);
239  }
240  return (t + i)->operator()(j, k, l);
241 }
242 #endif
243 
249 {
250  int mmin = hslicemin();
251  int mmax = hslicemax();
252 #ifndef OPT_LIB
253  if (mmin!=m.hslicemin() || mmax!=m.hslicemax())
254  {
255  cerr << "Incompatible bounds in dvar4_array& dvar4_array::operator=(const d4_array&)\n";
256  ad_exit(1);
257  }
258 #endif
259  dvar3_array* pti = t + mmin;
260  const d3_array* pmi = &m(mmin);
261  for (int i=mmin; i<=mmax; ++i)
262  {
263  *pti = *pmi;
264  ++pti;
265  ++pmi;
266  }
267  return *this;
268 }
269 
275 {
276  int mmin = hslicemin();
277  int mmax = hslicemax();
278 #ifndef OPT_LIB
279  if (mmin!=m.hslicemin() || mmax!=m.hslicemax())
280  {
281  cerr << "Incompatible bounds in dvar4_array& dvar4_array::operator=(const dvar4_array&)\n";
282  ad_exit(1);
283  }
284 #endif
285  dvar3_array* pti = t + mmin;
286  const dvar3_array* pmi = &m(mmin);
287  for (int i=mmin; i<=mmax; ++i)
288  {
289  *pti = *pmi;
290  ++pti;
291  ++pmi;
292  }
293  return *this;
294 }
295 
310  int hsl, int hsu,
311  int sl, int sh,
312  int nrl, int nrh,
313  int ncl, int nch)
314 {
315  if ((shape = new four_array_shape(hsl, hsu)) == 0)
316  {
317  cerr << " Error: dvar4_array unable to allocate memory in "
318  << __FILE__ << ':' << __LINE__ << '\n';
319  ad_exit(1);
320  }
321  if ((t = new dvar3_array[hslicesize()]) == 0)
322  {
323  cerr << " Error: dvar4_array unable to allocate memory in "
324  << __FILE__ << ':' << __LINE__ << '\n';
325  ad_exit(1);
326  }
327  t -= hsl;
328 
329  dvar3_array* pti = t + hsl;
330  for (int i = hsl; i <= hsu; ++i)
331  {
332  pti->allocate(sl, sh, nrl, nrh, ncl, nch);
333  ++pti;
334  }
335 }
350  int hsl, int hsu,
351  int sl, int sh,
352  int nrl, int nrh,
353  const ivector& ncl, const ivector& nch)
354 {
355  if ((shape = new four_array_shape(hsl, hsu)) == 0)
356  {
357  cerr << " Error: dvar4_array unable to allocate memory in "
358  << __FILE__ << ':' << __LINE__ << '\n';
359  ad_exit(1);
360  }
361  if ((t = new dvar3_array[hslicesize()]) == 0)
362  {
363  cerr << " Error: dvar4_array unable to allocate memory in "
364  << __FILE__ << ':' << __LINE__ << '\n';
365  ad_exit(1);
366  }
367  t -= hsl;
368 
369  dvar3_array* pti = t + hsl;
370  for (int i=hsl; i<=hsu; ++i)
371  {
372  pti->allocate(sl, sh, nrl, nrh, ncl, nch);
373  ++pti;
374  }
375 }
376 
391  ad_integer hsl, ad_integer hsu,
392  const index_type& sl, const index_type& sh,
393  const index_type& nrl, const index_type& nrh,
394  const index_type& ncl,const index_type& nch)
395 {
396  if ( (shape=new four_array_shape(hsl,hsu)) == 0)
397  {
398  cerr << " Error: dvar4_array unable to allocate memory in "
399  << __FILE__ << ':' << __LINE__ << '\n';
400  ad_exit(1);
401  }
402  if ((t = new dvar3_array[hslicesize()]) == 0)
403  {
404  cerr << " Error: dvar4_array unable to allocate memory in "
405  << __FILE__ << ':' << __LINE__ << '\n';
406  ad_exit(1);
407  }
408  int il = hsl;
409  int iu = hsu;
410  t -= il;
411 
412  dvar3_array* pti = t + il;
413  for (int i = il; i <= iu; ++i)
414  {
415  pti->allocate(sl(i), sh(i), nrl(i), nrh(i), ncl(i), nch(i));
416  ++pti;
417  }
418 }
424  ad_integer hsl, ad_integer hsu,
425  const index_type& sl, const index_type& sh,
426  const index_type& nrl, const index_type& nrh)
427 {
428  if ((shape = new four_array_shape(hsl, hsu)) == 0)
429  {
430  cerr << " Error: dvar4_array unable to allocate memory in "
431  << __FILE__ << ':' << __LINE__ << '\n';
432  ad_exit(1);
433  }
434  if ((t = new dvar3_array[hslicesize()]) == 0)
435  {
436  cerr << " Error: dvar4_array unable to allocate memory in "
437  << __FILE__ << ':' << __LINE__ << '\n';
438  ad_exit(1);
439  }
440  int il = hsl;
441  int iu = hsu;
442  t -= il;
443 
444  dvar3_array* pti = t + il;
445  for (int i = il; i <= iu; ++i)
446  {
447  pti->allocate(sl(i), sh(i), nrl(i), nrh(i));
448  ++pti;
449  }
450 }
456  ad_integer hsl, ad_integer hsu,
457  const index_type& sl, const index_type& sh)
458 {
459  if ( (shape=new four_array_shape(hsl,hsu)) == 0)
460  {
461  cerr << " Error: dvar4_array unable to allocate memory in "
462  << __FILE__ << ':' << __LINE__ << '\n';
463  ad_exit(1);
464  }
465  if ( (t = new dvar3_array[hslicesize()]) == 0)
466  {
467  cerr << " Error: dvar4_array unable to allocate memory in "
468  << __FILE__ << ':' << __LINE__ << '\n';
469  ad_exit(1);
470  }
471  int il=hsl;
472  int iu=hsu;
473  t -= il;
474 
475  dvar3_array* pti = t + il;
476  for (int i = il; i <= iu; ++i)
477  {
478  pti->allocate(sl(i), sh(i));
479  ++pti;
480  }
481 }
488 {
489  if ((shape = new four_array_shape(hsl, hsu)) == 0)
490  {
491  cerr << " Error: dvar4_array unable to allocate memory in "
492  << __FILE__ << ':' << __LINE__ << '\n';
493  ad_exit(1);
494  }
495  if ((t = new dvar3_array[hslicesize()]) == 0)
496  {
497  cerr << " Error: dvar4_array unable to allocate memory in "
498  << __FILE__ << ':' << __LINE__ << '\n';
499  ad_exit(1);
500  }
501  int il = hsl;
502  int iu = hsu;
503  t -= il;
504 
505  dvar3_array* pti = t + il;
506  for (int i = il; i <= iu; ++i)
507  {
508  pti->allocate();
509  ++pti;
510  }
511 }
526  int hsl, int hsu,
527  int sl, int sh,
528  const ivector& nrl, const ivector& nrh,
529  const ivector& ncl, const ivector& nch)
530 {
531  if ((shape = new four_array_shape(hsl, hsu)) == 0)
532  {
533  cerr << " Error: dvar4_array unable to allocate memory in "
534  << __FILE__ << ':' << __LINE__ << '\n';
535  ad_exit(1);
536  }
537  if ((t = new dvar3_array[hslicesize()]) == 0)
538  {
539  cerr << " Error: dvar4_array unable to allocate memory in "
540  << __FILE__ << ':' << __LINE__ << '\n';
541  ad_exit(1);
542  }
543  t -= hsl;
544  dvar3_array* pti = t + hsl;
545  for (int i = hsl; i <= hsu; ++i)
546  {
547  pti->allocate(sl, sh, nrl(i), nrh(i), ncl(i), nch(i));
548  ++pti;
549  }
550 }
555  dvar4_array::dvar4_array(int hsl,int hsu,int sl,int sh,int nrl,
556  int nrh,int ncl,int nch)
557  {
558  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch);
559  }
560 
566  const index_type& sh, const index_type& nrl,const index_type& nrh,
567  const index_type& ncl,const index_type& nch)
568  {
569  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch);
570  }
571 
576  dvar4_array::dvar4_array(int hsl,int hsu, int sl,int sh,ivector nrl,
577  ivector nrh,ivector ncl,ivector nch)
578  {
579  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch);
580  }
581 
587 {
588  if (!(!(*this))) // only initialize allocated objects
589  {
590  int min = hslicemin();
591  int max = hslicemax();
592  dvar3_array* pti = t + min;
593  for (int i = min; i <= max; ++i)
594  {
595  pti->initialize();
596  ++pti;
597  }
598  }
599 }
600 
605 dvar4_array::dvar4_array(int hsl, int hsu, int sl, const ivector& sh,
606  int nrl, const imatrix& nrh, int ncl, int nch)
607  {
608  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch);
609  }
610 
614  int hsl, int hsu,
615  int sl, const ivector& sh,
616  int nrl, const imatrix& nrh,
617  int ncl, int nch)
618 {
619  //int rmin=nrh.rowmin();
620  //int cmin=nrh(rmin).indexmin();
621  if ((shape = new four_array_shape(hsl, hsu)) == 0)
622  {
623  cerr << " Error: dvar4_array unable to allocate memory in "
624  << __FILE__ << ':' << __LINE__ << '\n';
625  ad_exit(1);
626  }
627  if ((t = new dvar3_array[hslicesize()]) == 0)
628  {
629  cerr << " Error: dvar4_array unable to allocate memory in "
630  << __FILE__ << ':' << __LINE__ << '\n';
631  ad_exit(1);
632  }
633  t -= hsl;
634 
635  dvar3_array* pti = t + hsl;
636  for (int i = hsl; i <= hsu; ++i)
637  {
638  pti->allocate(sl,sh(i),nrl,nrh(i),ncl,nch);
639  ++pti;
640  }
641 }
642 
648 {
649  allocate(m1);
650  int min = hslicemin();
651  int max = hslicemax();
652 
653  dvar3_array* pti = t + min;
654  const d3_array* pm1i = &m1(min);
655  for (int i = min; i <= max; ++i)
656  {
657  *pti = *pm1i;
658 
659  ++pti;
660  ++pm1i;
661  }
662 }
663 
668 {
669  int min = m1.hslicemin();
670  int max = m1.hslicemax();
671  if ((shape = new four_array_shape(min, max)) == 0)
672  {
673  cerr << " Error: dvar4_array unable to allocate memory in "
674  << __FILE__ << ':' << __LINE__ << '\n';
675  ad_exit(1);
676  }
677  if ((t = new dvar3_array[hslicesize()]) == 0)
678  {
679  cerr << " Error: dvar4_array unable to allocate memory in "
680  << __FILE__ << ':' << __LINE__ << '\n';
681  ad_exit(1);
682  }
683  t -= min;
684 
685  dvar3_array* pti = t + min;
686  const d3_array* pm1i = &m1(min);
687  for (int i = min; i <= max; ++i)
688  {
689  pti->allocate(*pm1i);
690  ++pti;
691  ++pm1i;
692  }
693 }
698 {
699  int min = m1.hslicemin();
700  int max = m1.hslicemax();
701  if ((shape = new four_array_shape(min, max)) == 0)
702  {
703  cerr << " Error: dvar4_array unable to allocate memory in "
704  << __FILE__ << ':' << __LINE__ << '\n';
705  ad_exit(1);
706  }
707  if ((t = new dvar3_array[hslicesize()]) == 0)
708  {
709  cerr << " Error: dvar4_array unable to allocate memory in "
710  << __FILE__ << ':' << __LINE__ << '\n';
711  ad_exit(1);
712  }
713  t -= min;
714 
715  dvar3_array* pti = t + min;
716  const dvar3_array* pm1i = &m1(min);
717  for (int i = min; i <= max; ++i)
718  {
719  pti->allocate(*pm1i);
720  ++pti;
721  ++pm1i;
722  }
723 }
724 
725 /*
726 dvar4_array::dvar4_array(int hsl,int hsu, int sl, const ivector& sh,int nrl,
727  const imatrix& nrh,int ncl,int nch)
728  {
729  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch);
730  }
731 
732  void dvar4_array::allocate(int hsl,int hsu, int sl, const ivector& sh,int nrl,
733  const imatrix& nrh,int ncl,int nch)
734  {
735  int rmin=nrh.rowmin();
736  int cmin=nrh(nrh.rowmin()).indexmin;
737  if ( (shape=new four_array_shape(hsl,hsu)) == 0)
738  {
739  cerr << " Error allocating memory in dvar4_array contructor\n";
740  }
741  int ss=hslicesize();
742  if ( (t = new dvar3_array[ss]) == 0)
743  {
744  cerr << " Error allocating memory in dvar3_array contructor\n";
745  ad_exit(21);
746  }
747  t -= hslicemin();
748  for (int i=hsl; i<=hsu; i++)
749  {
750  (*this)(i).allocate(sl,sh(i),nrl,nrh(i),ncl,nch(i));
751  }
752  }
753 */
Base class for dvariable.
Definition: fvar.hpp:1315
dvar4_array & operator=(const d4_array &)
Description not yet available.
Definition: f4arr.cpp:248
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: imatrix.h:69
void allocate(int sl, int sh, int nrl, int nrh, int ncl, int nch)
Allocate variable vector of matrices with dimensions [sl to sh] x ([nrl to nrh] x [ncl to nch]) where...
Definition: f3arr.cpp:91
friend class four_array_shape
Definition: fvar.hpp:5569
four_array_shape * shape
Definition: fvar.hpp:5435
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
void initialize(void)
Description not yet available.
Definition: f3arr.cpp:17
int hslicemax() const
Definition: fvar.hpp:5317
dvar3_array & operator()(int i)
Definition: fvar.hpp:5516
void allocate(void)
Initializes to NULL.
Definition: f4arr3.cpp:20
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
Description not yet available.
Definition: fvar.hpp:5161
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
#define min(a, b)
Definition: cbivnorm.cpp:188
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void deallocate(void)
Deallocate dvar4_array memory.
Definition: f4arr.cpp:66
dvar4_array sub(int, int)
Description not yet available.
Definition: f4arr.cpp:49
unsigned int hslicesize() const
Definition: fvar.hpp:5660
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
dvar3_array * t
Definition: fvar.hpp:5436
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
int hslicemax() const
Definition: fvar.hpp:5624
~dvar4_array()
Destructor.
Definition: f4arr.cpp:91
dvar4_array()
Default Constructor.
Definition: f4arr3.cpp:14
unsigned int ncopies
Definition: fvar.hpp:5140
Stores integer.
Definition: fvar.hpp:7654
#define max(a, b)
Definition: cbivnorm.cpp:189
int hslicemin() const
Definition: fvar.hpp:5313
Description not yet available.
Definition: fvar.hpp:3727
int indexmin() const
Definition: fvar.hpp:5621
int hslicemin() const
Definition: fvar.hpp:5623
dvar3_array & operator[](int i)
Definition: fvar.hpp:5520