ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
d7arr.cpp
Go to the documentation of this file.
1 
6 #if (__cplusplus > 199711L)
7  #include <algorithm>
8  #include <iterator>
9 #endif
10 #include "fvar.hpp"
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, [](d6_array& darray)
26  {
27  darray.initialize();
28  });
29  }
30 #endif
31 }
34 {
35  shallow_copy(other);
36 }
42 void d7_array::shallow_copy(const d7_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 }
91 {
92  int min = indexmin();
93  int max = indexmax();
94  if (min != other.indexmin() || max != other.indexmax())
95  {
96  cerr << "Incompatible bounds in"
97  << " d7_array& d7_array::operator=(const d7_array&).\n";
98  ad_exit(1);
99  }
100  for (int i = min; i <= max; ++i)
101  {
102  elem(i) = other.elem(i);
103  }
104  return *this;
105 }
111 void d7_array::allocate(const d7_array& other)
112 {
113  allocate(other.indexmin(), other.indexmax());
114  for (int i = indexmin(); i <= indexmax(); ++i)
115  {
116  elem(i).allocate(other.elem(i));
117  }
118 }
123 d7_array::d7_array(int l7,int u7,int hsl,int hsu,int sl,int sh,int nrl,
124  int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
125 {
126  allocate(l7,u7,hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
127 }
128 
134  const index_type& hsl,const index_type& hsu,
135  const index_type& sl,const index_type& sh,const index_type& nrl,
136  const index_type& nrh,const index_type& ncl,const index_type& nch,
137  const index_type& l5,const index_type& u5,
138  const index_type& l6,const index_type& u6)
139 {
140  allocate(l7,u7,hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
141 }
145 void d7_array::allocate(int l7, int u7, int hsl, int hsu, int sl, int sh,
146  int nrl, int nrh, int ncl, int nch, int l5, int u5, int l6, int u6)
147 {
148  allocate(l7, u7);
149  for (int i = l7; i <= u7; ++i)
150  {
151  elem(i).allocate(hsl, hsu, sl, sh, nrl, nrh, ncl, nch, l5, u5, l6, u6);
152  }
153 }
161 void d7_array::allocate(int l7, int u7)
162 {
163  if (l7 > u7)
164  {
165  return allocate();
166  }
167  if ((shape = new vector_shape(l7, u7)) == 0)
168  {
169  cerr << "Error: Unable to allocate d7_array memory in "
170  << "d7_array::allocate(int, int).\n";
171  ad_exit(1);
172  }
173  if ((t = new d6_array[size()]) == 0)
174  {
175  cerr << "Error: Unable to allocate d7_array memory in "
176  << "d7_array::allocate(int, int).\n";
177  ad_exit(1);
178  }
179  t -= indexmin();
180  for (int i = l7; i <= u7; ++i)
181  {
182  elem(i).allocate();
183  }
184 }
185 
190  void d7_array::allocate(const ad_integer& l7,const ad_integer& u7,
191  const index_type& hsl,const index_type& hsu,
192  const index_type& sl,const index_type& sh,const index_type& nrl,
193  const index_type& nrh,const index_type& ncl,const index_type& nch,
194  const index_type& l5,const index_type& u5,
195  const index_type& l6,const index_type& u6)
196  {
197  if ( (shape=new vector_shape (l7,u7)) == 0)
198  {
199  cerr << " Error allocating memory in d6_array contructor\n";
200  }
201 
202  unsigned int ss = size();
203  if ( (t = new d6_array[ss]) == 0)
204  {
205  cerr << " Error allocating memory in d6_array contructor\n";
206  ad_exit(21);
207  }
208  t -= indexmin();
209  int i1=l7;
210  int iu=u7;
211  for (int i=i1; i<=iu; i++)
212  {
213  (*this)(i).allocate(ad_integer(hsl(i)),ad_integer(hsu(i)),
214  sl(i),sh(i),nrl(i),nrh(i),ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i));
215  }
216  }
void allocate(void)
Description not yet available.
Definition: d7arr2.cpp:27
void initialize()
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d7arr.cpp:13
void allocate(int hhsl, int hhsu, int hsl, int hsu, int sl, int sh, int nrl, int nrh, int ncl, int nch, int l6, int u6)
Allocate d6_array with specified dimensions.
Definition: d6arr.cpp:172
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
unsigned int ncopies
Definition: fvar.hpp:522
unsigned int size() const
Definition: fvar.hpp:7222
Description not yet available.
Definition: fvar.hpp:509
d6_array & elem(int i)
Definition: fvar.hpp:7231
exitptr ad_exit
Definition: gradstrc.cpp:53
Description not yet available.
Definition: fvar.hpp:6673
void deallocate(void)
Deallocate d7_array memory.
Definition: d7arr.cpp:59
int indexmax() const
Definition: fvar.hpp:7218
d6_array * t
Definition: fvar.hpp:7057
#define min(a, b)
Definition: cbivnorm.cpp:188
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
d7_array & operator=(const d7_array &)
Assign element values from other to d7_array.
Definition: d7arr.cpp:90
void shallow_copy(const d7_array &)
Shallow copy other data structure pointers.
Definition: d7arr.cpp:42
vector_shape * shape
Definition: fvar.hpp:7056
~d7_array()
Destructor.
Definition: d7arr.cpp:83
d7_array()
Description not yet available.
Definition: d7arr2.cpp:18
int indexmin() const
Definition: fvar.hpp:7214
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