ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
d6arr.cpp
Go to the documentation of this file.
1 
5 #if (__cplusplus > 199711L)
6  #include <algorithm>
7  #include <iterator>
8 #endif
9 #include "fvar.hpp"
10 #include "admb_messages.h"
11 
14 {
15 #if (__cplusplus <= 199711L)
16  for (int i = indexmin(); i <= indexmax(); ++i)
17  {
18  elem(i).initialize();
19  }
20 #else
21  if (operator!() == false)
22  {
23  auto begin = &elem(indexmin());
24  auto end = begin + size();
25  std::for_each(begin, end, [](d5_array& darray)
26  {
27  darray.initialize();
28  });
29  }
30 #endif
31 }
34 {
35  shallow_copy(other);
36 }
42 void d6_array::shallow_copy(const d6_array& other)
43 {
44  if (other.shape)
45  {
46  shape = other.shape;
47  ++(shape->ncopies);
48  t = other.t;
49  }
50  else
51  {
52 #ifdef DEBUG
53  cerr << "Warning -- Unable to shallow copy an unallocated d6_array.\n";
54 #endif
55  allocate();
56  }
57 }
60 {
61  if (shape)
62  {
63  if (shape->ncopies)
64  {
65  --(shape->ncopies);
66  }
67  else
68  {
69  t += indexmin();
70  delete [] t;
71  delete shape;
72  }
73  allocate();
74  }
75 #if defined(DIAG)
76  else
77  {
78  cerr << "Warning -- Unable to deallocate an unallocated d6_array.\n";
79  }
80 #endif
81 }
84 {
85  deallocate();
86 }
87 
94 {
95  int min = indexmin();
96  int max = indexmax();
97  if (min != other.indexmin() || max != other.indexmax())
98  {
99  cerr << "Incompatible bounds in"
100  << " d6_array& d6_array::operator=(const d6_array&).\n";
101  ad_exit(1);
102  }
103  for (int i = min; i <= max; ++i)
104  {
105  elem(i) = other.elem(i);
106  }
107  return *this;
108 }
114 void d6_array::allocate(const d6_array& other)
115 {
116  allocate(other.indexmin(), other.indexmax());
117  for (int i = indexmin(); i <= indexmax(); ++i)
118  {
119  elem(i).allocate(other.elem(i));
120  }
121 }
126 d6_array::d6_array(int hsl,int hsu,int sl,int sh,int nrl,
127  int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
128 {
129  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
130 }
131 
137  const index_type& sl,const index_type& sh,const index_type& nrl,
138  const index_type& nrh,const index_type& ncl,const index_type& nch,
139  const index_type& l5,const index_type& u5,
140  const index_type& l6,const index_type& u6)
141 {
142  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
143 }
144 void d6_array::allocate(int hsl, int hsu)
145 {
146  if (hsl > hsu)
147  {
148  return allocate();
149  }
150  if ((shape = new vector_shape(hsl, hsu)) == 0)
151  {
152  cerr << "Error: Unable to allocate d6_array memory in\n"
153  << " d6_array::allocate(int, int).\n";
154  ad_exit(1);
155  }
156  if ((t = new d5_array[size()]) == 0)
157  {
158  cerr << "Error: Unable to allocate d6_array memory in\n"
159  << " d6_array::allocate(int, int).\n";
160  ad_exit(1);
161  }
162  t -= indexmin();
163  for (int i = hsl; i <= hsu; ++i)
164  {
165  elem(i).allocate();
166  }
167 }
168 
172 void d6_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
173  int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
174 {
175  if ((shape = new vector_shape(hsl, hsu)) == 0)
176  {
177  cerr << " Error allocating memory in d5_array contructor\n";
178  ad_exit(21);
179  }
180  unsigned int ss = size();
181  if ((t = new d5_array[ss]) == 0)
182  {
183  cerr << " Error allocating memory in d5_array contructor\n";
184  ad_exit(21);
185  }
186  t -= indexmin();
187  for (int i = hsl; i <= hsu; ++i)
188  {
189  t[i].allocate(sl, sh, nrl, nrh, ncl, nch, l5, u5, l6, u6);
190  }
191 }
192 
196 void d6_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
197  const index_type& sl,const index_type& sh,const index_type& nrl,
198  const index_type& nrh,const index_type& ncl,const index_type& nch,
199  const index_type& l5,const index_type& u5,
200  const index_type& l6,const index_type& u6)
201 {
202  if ((shape = new vector_shape (hsl, hsu)) == 0)
203  {
204  cerr << " Error allocating memory in d5_array contructor\n";
205  }
206 
207  unsigned int ss = size();
208  if ( (t = new d5_array[ss]) == 0)
209  {
210  cerr << " Error allocating memory in d5_array contructor\n";
211  ad_exit(21);
212  }
213  t -= indexmin();
214  int i1=hsl;
215  int i2=hsu;
216  for (int i = i1; i <= i2; ++i)
217  {
218  (*this)(i).allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
219  ncl(i),nch(i), l5(i),u5(i),l6(i),u6(i));
220  }
221 }
227 double sum(const d6_array& darray)
228 {
229  double total = 0.0;
230  for (int i = darray.indexmin(); i <= darray.indexmax(); ++i)
231  {
232  total += sum(darray.elem(i));
233  }
234  return total;
235 }
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
d6_array()
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d6arr2.cpp:9
unsigned int ncopies
Definition: fvar.hpp:522
Description not yet available.
Definition: fvar.hpp:509
int indexmin() const
Definition: fvar.hpp:6812
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
d5_array & elem(int i)
Definition: fvar.hpp:6828
exitptr ad_exit
Definition: gradstrc.cpp:53
void allocate(void)
Does NOT allocate, but initializes d6_array members.
Definition: d6arr2.cpp:14
Description not yet available.
Definition: fvar.hpp:6673
~d6_array()
Destructor.
Definition: d6arr.cpp:83
d5_array * t
Definition: fvar.hpp:6676
void deallocate(void)
Deallocate d6_array memory.
Definition: d6arr.cpp:59
#define min(a, b)
Definition: cbivnorm.cpp:188
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int indexmax() const
Definition: fvar.hpp:6816
void shallow_copy(const d6_array &)
Shallow copy other data structure pointers.
Definition: d6arr.cpp:42
d6_array & operator=(const d6_array &)
Assigns element values from other to d6_array.
Definition: d6arr.cpp:93
unsigned int size() const
Definition: fvar.hpp:6820
void initialize()
Initialize all elements of d5_array to zero.
Definition: d5arr.cpp:117
void allocate(int hhsl, int hhsu, int hsl, int hsu, int sl, int sh, int nrl, int nrh, int ncl, int nch)
Allocate d5_array with specified dimensions.
Definition: d5arr.cpp:352
Description not yet available.
Definition: fvar.hpp:6331
Stores integer.
Definition: fvar.hpp:7654
#define max(a, b)
Definition: cbivnorm.cpp:189
void initialize()
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d6arr.cpp:13
vector_shape * shape
Definition: fvar.hpp:6675