ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmpdif5.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 #include <string.h>
13 
14 #ifdef DEBUG
15  #include <cassert>
16 #endif
17 
23 {
25 }
27 {
28  // saves the size, address, and value information for a dvar_matrix
29  //int ierr;
30  int min = m.rowmin();
31  int max = m.rowmax();
32  const dvector* pmi = &m(min);
33  for (int i = min; i <= max; ++i)
34  {
35  save_dvector_value(*pmi);
37 
38  ++pmi;
39  }
40 }
41 
47 {
49 }
51 {
52  // saves the size, address, and value information for a dvar_matrix
53  //int ierr;
54  int min = a.indexmin();
55  int max = a.indexmax();
56  const dmatrix* pai = &a(min);
57  for (int i = min; i <= max; ++i)
58  {
59  save_dmatrix_value(*pai);
61 
62  ++pai;
63  }
64 }
65 
71 {
73 }
75 {
76  // restores the size, address, and value information for a dvar_matrix
77  dmatrix out((const dvar_matrix_position&)mpos);
78  //int ierr;
79  int min = out.rowmin();
80  int max = out.rowmax();
81  dvector* pouti = &out(max);
82  for (int i = max;i >= min; --i)
83  {
85  *pouti = restore_dvar_vector_value(vpos);
86 
87  --pouti;
88  }
89  return out;
90 }
91 
97 {
99 }
101 {
102  // restores the size, address, and value information for a dvar_matrix
103  // the size, address, and value information for a dvar_matrix
104  dmatrix out((const dmatrix_position&)mpos);
105  //int ierr;
106  int min=out.rowmin();
107  int max=out.rowmax();
108  dvector* pouti = &out(max);
109  for (int i = max; i >= min; --i)
110  {
112  *pouti = restore_dvector_value(vpos);
113 
114  --pouti;
115  }
116  return out;
117 }
118 
124 {
126 }
128 {
129  // restores the size, address, and value information for a dvar_matrix
130  // the size, address, and value information for a dvar_matrix
131  d3_array out((const d3_array_position&) mpos);
132  //int ierr;
133  int min = out.indexmin();
134  int max = out.indexmax();
135  dmatrix* pouti = &out(max);
136  for (int i = max; i >= min; --i)
137  {
139  *pouti = restore_dmatrix_value(vpos);
140 
141  --pouti;
142  }
143  return out;
144 }
145 
151 {
152  int min = tmp.indexmin();
153  int max = tmp.indexmax();
154 
155  // puts the derivative values from a dvar_vector's guts into a dvector
156  dvector tempvec(min, max);
157  double_and_int* va = tmp.va + min;
158 
159  double* ptmpvec = tempvec.get_v() + min;
160  for (int i = min; i <= max; ++i)
161  {
162  //tempvec(i)=va[i].xvalue();
163  //va[i].xvalue()=0.;
164  *ptmpvec = va->x;
165  va->x = 0.0;
166  ++va;
167  ++ptmpvec;
168  }
169 
170 // _dp_vector_add
171 // _dp_vector_elem_div
172 // _dp_dotproduct
173 // _dp_vector_elem_prod
174 // _dp_scalar_product
175 // _dp_vector_sub
176 // _dw_block_move
177 
178  return tempvec;
179 }
180 
186 {
187  // puts the derivative values from a dvar_vector's guts into a dvector
188  int min = tmp.min;
189  int max = tmp.max;
190  dvector tempvec(min, max);
191  double_and_int* va = tmp.va + min;
192 
193 #ifdef USE_ASSEMBLER
194  int min=tmp.indexmin();
195  int n=tmp.indexmax()-min+1;
196  dw_block_move(&(tempvec.elem(min)),&(va[min].xvalue()),n);
197 #else
198  double* ptempvec = tempvec.get_v() + min;
199  for (int i = min; i <= max; ++i)
200  {
201  *ptempvec = va->x;
202  ++va;
203  ++ptempvec;
204  }
205 #endif
206  return tempvec;
207 }
208 
213 {
214  const int min = pos.indexmin();
215  const int max = pos.indexmax();
216 
217 #ifdef DEBUG
218  //Check for incompatible array sizes
219  assert(min == indexmin() && max == indexmax());
220 #endif
221 
222  double_and_int* dest = pos.va + min;
223  double* source = v + min;
224  for (int i = min; i <= max; ++i)
225  {
226  dest->x += *source;
227  ++source;
228  ++dest;
229  }
230 }
231 
237 {
238  // puts the derivative values in a dvector into a dvar_vector's guts
239  int min = pos.indexmin();
240  int max = pos.indexmax();
241 
242 #ifndef OPT_LIB
243  if (min != indexmin() || max != indexmax())
244  {
245  cerr << "Incompatible array sizes in " <<
246  "void dvector::save_dvector_derivatives_na(const dvar_vector_position& pos)"
247  << endl;
248  }
249 #endif
250 
251  double_and_int* dest = pos.va + min;
252  double* source = v + min;
253  for (int i = min; i <= max; ++i)
254  {
255  dest->x = *source;
256  ++dest;
257  ++source;
258  }
259 }
260 
265 void save_dmatrix_derivatives(const dvar_matrix_position& _pos, const double x,
266  const int& i, int& j)
267 {
269  if ( i<pos.rowmin()||i>pos.rowmax() ||
270  j<(pos.colmin())(i) || j>(pos.colmax())(i) )
271  {
272  cerr << "Error -- Index out of bounds in routine\n"
273  " void save_dmatrix_derivatives(const dvar_matrix_position& pos"
274  " , const double& x, const int& i, const int& j)" << endl;
275  ad_exit(1);
276  }
277  // puts the derivative values in a dvector into a dvar_vector's guts
278  pos(i)(j)+=x;
279 }
280 
286 {
288  // puts the derivative values in a dvector into a dvar_vector's guts
289  int min=rowmin();
290  int max=rowmax();
291 #ifndef OPT_LIB
292  if (min != pos.row_min || max != pos.row_max)
293  {
294  cerr << "Incompatible array sizes in " <<
295  "void dmatrix::save_dmatrix__derivatives(const dvar_matrix_position& pos)"
296  << endl;
297  }
298 #endif
299  dvector* pmi = m + min;
300  for (int i=min;i<=max;i++)
301  {
302  if (allocated(*pmi))
303  pmi->save_dvector_derivatives(pos(i));
304  ++pmi;
305  }
306 }
307 
313  const
314 {
316  // puts the derivative values in a dvector into a dvar_vector's guts
317  int min=rowmin();
318  int max=rowmax();
319 #ifndef OPT_LIB
320  if (min!=pos.row_min||max!=pos.row_max)
321  {
322  cerr << "Incompatible array sizes in " <<
323  "void dmatrix::save_dmatrix__derivatives(const dvar_matrix_position& pos)"
324  << endl;
325  }
326 #endif
327 
328  dvector* pmi = m + min;
329  for (int i = min; i <= max; ++i)
330  {
331  if (allocated(*pmi))
333  ++pmi;
334  }
335 }
336 
342 {
344 }
346 {
347  // saves the size and address information for a dvar_vector
348  dvar_matrix_position tmp(m,1);
349  constexpr size_t wsize=sizeof(int);
350  constexpr size_t wsize1=sizeof(void*);
351 
352  int min=m.rowmin();
353  int max=m.rowmax();
354  int* ptmplbi = tmp.lb.get_v() + min;
355  int* ptmpubi = tmp.ub.get_v() + min;
356  for (int i=min;i<=max;++i)
357  {
358  fwrite(ptmplbi, wsize);
359  fwrite(ptmpubi, wsize);
360  fwrite(&(tmp.ptr(i)), wsize1);
361 
362  ++ptmplbi;
363  ++ptmpubi;
364  }
365  fwrite(&(tmp.row_min), wsize);
366  fwrite(&(tmp.row_max), wsize);
367 }
Description not yet available.
Definition: fvar.hpp:4883
void save_d3_array_value(const d3_array &a)
Definition: cmpdif5.cpp:50
d3_array restore_d3_array_value(const d3_array_position &mpos)
Definition: cmpdif5.cpp:127
double * v
pointer to the data
Definition: dvector.h:53
int rowmax(void) const
Definition: fvar.hpp:2564
int & rowmin(void)
Definition: fvar.hpp:4855
double & elem(int i)
Definition: dvector.h:152
void save_dvector_derivatives_na(const dvar_vector_position &pos) const
Description not yet available.
Definition: cmpdif5.cpp:236
int indexmax() const
Definition: fvar.hpp:3822
#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
void save_dmatrix_position(const dmatrix &m)
Definition: cmpdif6.cpp:31
void save_dvector_derivatives(const dvar_vector_position &pos) const
Puts the derivative values in a dvector into a dvar_vector&#39;s guts.
Definition: cmpdif5.cpp:212
Description not yet available.
Definition: fvar.hpp:4814
friend double min(const dvector &)
Returns the minimum value of vector vec.
Definition: dvect7.cpp:107
int indexmin() const
Definition: fvar.hpp:4827
exitptr ad_exit
Definition: gradstrc.cpp:53
dmatrix_position restore_dmatrix_position()
Definition: cmpdif6.cpp:147
ivector & colmax(void)
Definition: fvar.hpp:4867
Description not yet available.
Definition: fvar.hpp:4923
void save_dmatrix_value(const dmatrix &m)
Definition: cmpdif5.cpp:26
void save_dvector_derivatives(void) const
d3_array restore_d3_array_value(const d3_array_position &mpos)
Description not yet available.
Definition: cmpdif5.cpp:123
void save_dmatrix_value() const
Description not yet available.
Definition: cmpdif5.cpp:22
dvector restore_dvector_value(const dvector_position &tmp)
Definition: cmpdif4.cpp:178
dmatrix restore_dmatrix_value(const dmatrix_position &mpos)
Definition: cmpdif5.cpp:100
Holds the data for the prevariable class.
Definition: fvar.hpp:191
void save_dvar_matrix_position() const
Description not yet available.
Definition: cmpdif5.cpp:341
friend double max(const dvector &)
Returns the maximum value of vector vec.
Definition: dvect7.cpp:85
dmatrix restore_dvar_matrix_value(const dvar_matrix_position &mpos)
Definition: cmpdif5.cpp:74
int * get_v() const
Definition: ivector.h:114
void save_dvector_position(const dvector &v)
Definition: cmpdif4.cpp:32
prnstream & endl(prnstream &)
dmatrix restore_dmatrix_value(const dmatrix_position &mpos)
Description not yet available.
Definition: cmpdif5.cpp:96
Description not yet available.
Definition: fvar.hpp:4902
int rowmax() const
Definition: fvar.hpp:2929
void save_dvector_value(const dvector &v)
Definition: cmpdif4.cpp:130
dvector restore_dvar_vector_value(const dvar_vector_position &tmp)
Definition: cmpdif4.cpp:231
int indexmax() const
Definition: fvar.hpp:4831
dvar_vector_position restore_dvar_vector_position()
Definition: cmpdif4.cpp:69
#define min(a, b)
Definition: cbivnorm.cpp:188
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
ivector & colmin(void)
Definition: fvar.hpp:4863
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void save_dmatrix_derivatives_na(const dvar_matrix_position &pos) const
Description not yet available.
Definition: cmpdif5.cpp:312
void save_dmatrix_derivatives(const dvar_matrix_position &pos) const
Description not yet available.
Definition: cmpdif5.cpp:285
dvector * m
Definition: fvar.hpp:2824
ptr_vector ptr
Definition: fvar.hpp:4850
dmatrix restore_dvar_matrix_value(const dvar_matrix_position &mpos)
Description not yet available.
Definition: cmpdif5.cpp:70
int rowmin(void) const
Definition: fvar.hpp:2560
Description not yet available.
Definition: fvar.hpp:2819
dvector restore_dvar_vector_der_nozero(const dvar_vector_position &tmp)
Description not yet available.
Definition: cmpdif5.cpp:185
dvector_position restore_dvector_position()
Definition: cmpdif4.cpp:88
static _THREAD DF_FILE * fp
void save_dvar_matrix_position(const dvar_matrix &m)
Definition: cmpdif5.cpp:345
size_t pos(const adstring &substr, const adstring &s)
Definition: string3.cpp:56
int & rowmax(void)
Definition: fvar.hpp:4859
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
dvector restore_dvar_vector_derivatives(const dvar_vector_position &tmp)
Description not yet available.
Definition: cmpdif5.cpp:150
void save_d3_array_value() const
Description not yet available.
Definition: cmpdif5.cpp:46
void fwrite(const void *s, const size_t num_bytes)
Reads num_bytes from s and writes to buffer.
Definition: df_file.cpp:296
int indexmin() const
Definition: fvar.hpp:3818
#define max(a, b)
Definition: cbivnorm.cpp:189
Description not yet available.
Definition: fvar.hpp:3727
void save_dmatrix_derivatives(const dvar_matrix_position &_pos, const double x, const int &i, int &j)
Description not yet available.
Definition: cmpdif5.cpp:265
double_and_int * va
Definition: fvar.hpp:4825
double *& get_v(void)
Definition: dvector.h:148
int rowmin() const
Definition: fvar.hpp:2925
double x
&lt; value of the variable
Definition: fvar.hpp:195
Description not yet available.
Definition: fvar.hpp:4843