ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmpdif2.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 #ifdef __TURBOC__
13  #pragma hdrstop
14 #endif
15 
16 #include <string.h>
17 int save_identifier_string(const char*);
18 void verify_identifier_string(const char*);
19 
20 //struct dvar_matrix_position;
21 //struct dvector_position;
22 long int reset_gs_stack(void);
23 void reset_gs_stack(long int);
24 
25 #ifndef OPT_LIB
26  #define CHK_ID_STRING
27 #endif
28 
33  min(0),
34  max(-1),
35  va(nullptr)
36 {
37 }
42  min(dvp.min),
43  max(dvp.max),
44  va(dvp.va)
45 {
46 }
53  min(v.indexmin()),
54  max(v.indexmax()),
55  va(v.get_va())
56 {
57 }
62 double& dvar_vector_position::operator()(const int& i)
63 {
64  if (i < min || i > max)
65  {
66  cerr << "Error -- Index out of bounds in "
67  "double& dvar_vector_position::operator()(const int& i)\n";
68  ad_exit(1);
69  }
70  return va[i].x;
71 }
78 {
79  min=vv.indexmin();
80  max=vv.indexmax();
81  v=vv.get_v();
82 }
87 {
88  min=dvp.min;
89  max=dvp.max;
90  v=dvp.v;
91 }
96 {
97  min=0;
98  max=-1;
99  v=0;
100 }
101 
107 {
108  min=iv.indexmin();
109  max=iv.indexmax();
110  v=iv.get_v();
111 }
116 {
117  min=dvp.min;
118  max=dvp.max;
119  v=dvp.v;
120 }
125 {
126  min=0;
127  max=-1;
128  v=0;
129 }
135 {
136 #ifndef OPT_LIB
137  if (i<row_min||i>row_max)
138  {
139  cerr << "Index out of range in\n"
140  " dvar_vector_position dvar_matrix_position::operator () (int i)"
141  << endl;
142  }
143 #endif
145  tmp.min = *(lb.get_v() + i);
146  tmp.max = *(ub.get_v() + i);
147  tmp.va=(double_and_int *) ptr(i);
148  return tmp;
149 }
150 
156 {
157 #ifndef OPT_LIB
158  if (i<row_min||i>row_max)
159  {
160  cerr << "Index out of range in\n"
161  " dvector_position dmatrix_position::operator () (int i)"
162  << endl;
163  }
164 #endif
165  dvector_position tmp;
166  tmp.min = *(lb.get_v() + i);
167  tmp.max = *(ub.get_v() + i);
168  tmp.v=(double *) ptr(i);
169  return tmp;
170 }
171 
177  lb(m.rowmin(),m.rowmax()),
178  ub(m.rowmin(),m.rowmax()),
179  ptr(m.rowmin(),m.rowmax())
180 {
181  row_min=m.rowmin();
182  row_max=m.rowmax();
183 
184  if (row_min <= row_max)
185  {
186  const dvar_vector* pm = &m(row_min);
187  int* plb = lb.get_v() + row_min;
188  int* pub = ub.get_v() + row_min;
189  for (int i=row_min;i<=row_max;i++)
190  {
191  if (allocated(*pm))
192  {
193  *plb = pm->indexmin();
194  *pub = pm->indexmax();
195  ptr(i) = pm->get_va();
196  }
197  else
198  {
199  *plb = 0;
200  *pub = -1;
201  ptr(i) = 0;
202  }
203  ++pm;
204  ++plb;
205  ++pub;
206  }
207  }
208 }
209 
215  : lb(m.rowmin(),m.rowmax()), ub(m.rowmin(),m.rowmax()),
216  ptr(m.rowmin(),m.rowmax())
217 {
218  row_min=m.rowmin();
219  row_max=m.rowmax();
220  const dvector* pmi = &m(row_min);
221  int* plbi = lb.get_v() + row_min;
222  int* pubi = ub.get_v() + row_min;
223  for (int i = row_min; i <= row_max; ++i)
224  {
225  *plbi = pmi->indexmin();
226  *pubi = pmi->indexmax();
227  ptr(i) = pmi->get_v();
228 
229  ++pmi;
230  ++plbi;
231  ++pubi;
232  }
233 }
234 
240  : lb(min,max), ub(min,max), ptr(min,max)
241 {
242  row_min=min;
243  row_max=max;
244  int* plbi = lb.get_v() + row_min;
245  int* pubi = ub.get_v() + row_min;
246  for (int i=row_min;i<=row_max;i++)
247  {
248  *plbi = 0;
249  *pubi = -1;
250  ptr(i)=0;
251 
252  ++plbi;
253  ++pubi;
254  }
255 }
256 
262  : lb(min,max), ub(min,max), ptr(min,max)
263 {
264  row_min=min;
265  row_max=max;
266  int* plbi = lb.get_v() + row_min;
267  int* pubi = ub.get_v() + row_min;
268  for (int i=row_min;i<=row_max;i++)
269  {
270  *plbi = 0;
271  *pubi = -1;
272  ptr(i)=0;
273 
274  ++plbi;
275  ++pubi;
276  }
277 }
278 
284  : lb(p.row_min,p.row_max), ub(p.row_min,p.row_max),
285  ptr(p.row_min,p.row_max)
286 {
287  row_min=p.row_min;
288  row_max=p.row_max;
289  lb=p.lb;
290  ub=p.ub;
291  ptr=p.ptr;
292  // cout << "ptr= " << ptr ;
293 }
298  : lb(p.row_min,p.row_max), ub(p.row_min,p.row_max),
299  ptr(p.row_min,p.row_max)
300 {
301  row_min=p.row_min;
302  row_max=p.row_max;
303  lb=p.lb;
304  ub=p.ub;
305  ptr=p.ptr;
306 }
315 int save_identifier_string(const char* str)
316 {
317 #if defined(CHK_ID_STRING)
318  //int wsize=sizeof(char);
319  size_t length=strlen(str);
320  gradient_structure::fp->fwrite(str,length);
321 #endif
322  return 0;
323 }
Description not yet available.
Definition: fvar.hpp:4883
int rowmax(void) const
Definition: fvar.hpp:2564
dvar_vector_position operator()(int i)
Description not yet available.
Definition: cmpdif2.cpp:134
double * v
Definition: fvar.hpp:4927
ptr_vector ptr
Definition: fvar.hpp:4890
dvar_matrix_position(const dvar_matrix &, int)
Description not yet available.
Definition: cmpdif2.cpp:176
#define x
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_a59.cpp:13
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
double_and_int * get_va()
Definition: fvar.hpp:2231
Description not yet available.
Definition: fvar.hpp:4814
exitptr ad_exit
Definition: gradstrc.cpp:53
Description not yet available.
Definition: fvar.hpp:4923
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
ivector_position(void)
Default constructor.
Definition: cmpdif2.cpp:124
Holds the data for the prevariable class.
Definition: fvar.hpp:191
dvar_vector_position()
Default constructor.
Definition: cmpdif2.cpp:32
int * get_v() const
Definition: ivector.h:114
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
int rowmax() const
Definition: fvar.hpp:2929
#define min(a, b)
Definition: cbivnorm.cpp:188
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Description not yet available.
Definition: fvar.hpp:4947
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int indexmin() const
Definition: ivector.h:99
ptr_vector ptr
Definition: fvar.hpp:4850
int indexmax() const
Definition: ivector.h:104
int rowmin(void) const
Definition: fvar.hpp:2560
Description not yet available.
Definition: fvar.hpp:2819
ivector lb
Definition: fvar.hpp:4888
int save_identifier_string(const char *)
Writes a gradient stack verification string.
Definition: cmpdif2.cpp:315
adstring str(double x, int minwidth=17, int decplaces=-1)
Convert x to adstring with minimum width and total number of decimal places.
Definition: str.cpp:25
double & operator()(const int &i)
Get element i from dvar_vector_position.
Definition: cmpdif2.cpp:62
int indexmin() const
Definition: fvar.hpp:2287
dvector_position(void)
Default constructor.
Definition: cmpdif2.cpp:95
static _THREAD DF_FILE * fp
ivector ub
Definition: fvar.hpp:4889
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
void fwrite(const void *s, const size_t num_bytes)
Reads num_bytes from s and writes to buffer.
Definition: df_file.cpp:296
#define max(a, b)
Definition: cbivnorm.cpp:189
double_and_int * va
Definition: fvar.hpp:4825
double *& get_v(void)
Definition: dvector.h:148
dvector_position operator()(int i)
Description not yet available.
Definition: cmpdif2.cpp:155
dmatrix_position(const dmatrix &)
Description not yet available.
Definition: cmpdif2.cpp:214
size_t length(const adstring &t)
Returns the size of adstr.
Definition: string1.cpp:228
int indexmax() const
Definition: fvar.hpp:2292
int rowmin() const
Definition: fvar.hpp:2925
double x
&lt; value of the variable
Definition: fvar.hpp:195
long int reset_gs_stack(void)
Description not yet available.
Definition: fvar.hpp:4843