ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_ar1.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  */
7 #include "fvar.hpp"
8 
11 {
12  deallocate();
13 }
16 {
17  if (shape)
18  {
19 #if defined(DIAG)
20  cout << " Deallocating dvar_vector with ptr_address\n "
21  << &va << " pointing at " << (va+indexmin()) << "\n";
22 #endif
23  if (shape->ncopies > 0)
24  {
25  --(shape->ncopies);
26  }
27  else
28  {
30  *(arr_link**) va = link_ptr;
32  gs->ARR_LIST1->arr_free(va);
33  delete shape;
34  }
35  allocate();
36  }
37 #if defined(DIAG)
38  else
39  {
40  cerr << "Warning -- Unable to deallocate an unallocated dvar_vector.\n";
41  }
42 #endif
43 }
46 {
47  shallow_copy(other);
48 
49 #if defined(DIAG)
50  cout << " Making copy for dvar_vector with ptr_address\n "
51  << &va << " pointing at " << (va+indexmin()) << "\n";
52 #endif
53 }
60 {
61  if (other.shape)
62  {
63  shape = other.shape;
64  ++(shape->ncopies);
65 
66  index_min = other.index_min;
67  index_max = other.index_max;
68 
69  link_ptr = other.link_ptr;
70  va = other.va;
71  }
72  else
73  {
74 #if defined(DIAG)
75  cerr << "Warning -- Unable to shallow copy an unallocated dvar_vector.\n";
76 #endif
77  allocate();
78  }
79 }
80 
86  {
87 #ifndef OPT_LIB
88  if (pdv.ub<pdv.lb)
89  {
90  cerr << "lower index greater than upper index in dvar_vector::"
91  " dvar-vector(const predvar_vector&) " << endl;
92  ad_exit (1);
93  }
94  if ((pdv.lb<pdv.p->indexmin()) || (pdv.lb>pdv.p->indexmax()))
95  {
96  cerr << "lower index out of bounds in dvar_vector::"
97  " operator(int lb,int ub) " << endl;
98  ad_exit (1);
99  }
100 
101  if ((pdv.ub<pdv.p->indexmin()) || (pdv.ub>pdv.p->indexmax()))
102  {
103  cerr << " upper index out of bounds in dvar_vector::"
104  " operator(int lb,int ub) " << endl;
105  ad_exit (1);
106  }
107 #endif
108  index_min=pdv.lb;
109  index_max=pdv.ub;
110  shape=pdv.p->shape;
111  link_ptr=pdv.p->link_ptr;
112  (shape->ncopies)++;
113  va = pdv.p->va;
114 #if defined(DIAG)
115  cout << " Making copy for dvar_vector with ptr_address\n "
116  << &va << " pointing at " << (va+indexmin()) << "\n";
117 #endif
118  }
119 
120 /*
121 dvar_vector::dvar_vector(const dvar_vector& t, int lb, int ub)
122  {
123 #ifndef OPT_LIB
124  if (ub<lb)
125  {
126  cerr << "lower index greater than upper index in dvar_vector::"
127  " operator(int lb,int ub) " << endl;
128  ad_exit (1);
129  }
130  if ((lb<t.indexmin()) || (lb>t.indexmax()))
131  {
132  cerr << "lower index out of bounds in dvar_vector::"
133  " operator(int lb,int ub) " << endl;
134  ad_exit (1);
135  }
136 
137  if ((ub<t.indexmin()) || (ub>t.indexmax()))
138  {
139  cerr << " upper index out of bounds in dvar_vector::"
140  " operator(int lb,int ub) " << endl;
141  ad_exit (1);
142  }
143 #endif
144 
145  index_min=lb;
146  index_max=ub;
147  shape=t.shape;
148  link_ptr=t.link_ptr;
149  (shape->ncopies)++;
150  va = t.va;
151 #if defined(DIAG)
152  cout << " Making copy for dvar_vector with ptr_address\n "
153  << &va << " pointing at " << (va+indexmin()) << "\n";
154 #endif
155  }
156 */
157 
Description not yet available.
Definition: fvar.hpp:1918
dvar_vector()
Default constructor.
Definition: fvar_arr.cpp:150
void * trueptr
Address of first element in the vector.
Definition: vector_shapex.h:82
void allocate(void)
Does not allocate, but initializes dvar_vector to empty.
Definition: fvar_arr.cpp:216
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
Holds the data for the prevariable class.
Definition: fvar.hpp:191
void arr_free(double_and_int *varr)
Description not yet available.
Definition: newdar.cpp:227
prnstream & endl(prnstream &)
dvar_vector * p
Definition: fvar.hpp:1920
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
arr_link * link_ptr
Definition: fvar.hpp:2178
static _THREAD gradient_structure * _instance
unsigned int ncopies
Copy counter to enable shallow copies.
Definition: vector_shapex.h:79
~dvar_vector()
Destructor.
Definition: fvar_ar1.cpp:10
int indexmin() const
Definition: fvar.hpp:2287
int index_min
Definition: fvar.hpp:2176
void shallow_copy(const dvar_vector &)
Shallow copy other data structure pointers.
Definition: fvar_ar1.cpp:59
void deallocate()
Deallocate dvar_vector memory.
Definition: fvar_ar1.cpp:15
double_and_int * va
Definition: fvar.hpp:2175
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
int indexmax() const
Definition: fvar.hpp:2292
vector_shapex * shape
Definition: fvar.hpp:2179
int index_max
Definition: fvar.hpp:2177