ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_a20.cpp
Go to the documentation of this file.
1 
8 #include "fvar.hpp"
9 #if defined(__TURBOC__)
10  #pragma hdrstop
11  #include <alloc.h>
12 #endif
13 
14 #include <stdlib.h>
15 
16 void dv_assign(void);
17 
18 #ifdef _MSC_VER
19  #include <memory.h>
20 #endif
21 
22 #ifdef DEBUG
23  #include <cassert>
24 #endif
25 
32  {
33  if (!(*this))
34  {
35  allocatec(t);
36  }
37 #if defined (AD_FAST_ASSIGN)
38  else if (!(shape->ncopies))
39  {
40  deallocate();
41  allocatec(t);
42  }
43 #endif
44  else
45  {
46  int mmin=indexmin();
47  int mmax=indexmax();
48 #ifndef OPT_LIB
49  if (mmin != t.indexmin() || mmax != t.indexmax())
50  {
51  cerr << " Incompatible bounds in dvar_vector& dvar_vector::operator ="
52  " (const dvar_vector& t)\n";
53  ad_exit(21);
54  }
55 #endif
56  if (va != t.va)
57  {
58  constexpr size_t sizeofdouble = sizeof(double);
59  size_t size = (size_t)(mmax - mmin + 1);
60  memcpy(va + mmin, t.va + mmin, size * sizeofdouble);
61 
64  // The derivative list considerations
65  //save_identifier_string("bbbb");
67  fp->save_dvar_vector_position(*this);
68  //save_identifier_string("aaaa");
69  GRAD_STACK1->set_gradient_stack(dv_assign);
70  }
71  }
72  return (*this);
73  }
74 
75 void dv_eqprev(void);
76 
83  {
84  int mmin=indexmin();
85  int mmax=indexmax();
86  double valuet = value(t);
87  double_and_int* pvai = va + mmin;
88  for (int i=mmin; i<=mmax; i++)
89  {
90  pvai->x = valuet;
91  ++pvai;
92  }
93 
96  // The derivative list considerations
97  save_identifier_string("dddd");
99  fp->save_dvar_vector_position(*this);
100  save_identifier_string("ssss");
101  GRAD_STACK1->set_gradient_stack(dv_eqprev);
102  return (*this);
103  }
104 
105 void dv_eqdoub(void);
106 
113  {
114  int mmin=indexmin();
115  int mmax=indexmax();
116  double_and_int* pvai = va + mmin;
117  for (int i=mmin; i<=mmax; i++)
118  {
119  pvai->x = t;
120  ++pvai;
121  }
124  // The derivative list considerations
125  save_identifier_string("trut");
126  fp->save_dvar_vector_position(*this);
127  save_identifier_string("ssss");
128  GRAD_STACK1->set_gradient_stack(dv_eqdoub);
129  return (*this);
130  }
134 void dv_eqdoub(void)
135 {
137  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
138  verify_identifier_string("ssss");
141  verify_identifier_string("trut");
142 }
146 void dv_eqprev(void)
147 {
149 
150  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
151  verify_identifier_string("ssss");
155  verify_identifier_string("dddd");
156  double dft = 0.0;
157  int min = dftmp.indexmin();
158  int max = dftmp.indexmax();
159  double* pdftmpi = dftmp.get_v() + min;
160  for (int i = min; i <= max; ++i)
161  {
162  //vtmp.elem(i)=t;
163  dft += *pdftmpi;
164 
165  ++pdftmpi;
166  }
167  save_double_derivative(dft,t_pos);
168 }
172 void dv_assign(void)
173 {
175 
176  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
177  //verify_identifier_string("aaaa");
181  //verify_identifier_string("bbbb");
182 
183  int mmin=dftmp.indexmin();
184  int mmax=dftmp.indexmax();
185 
186 #ifdef DEBUG
187  assert(mmax >= mmin);
188 #endif
189 
190  dvector dft(mmin, mmax);
191 
192  constexpr size_t sizeofdouble = sizeof(double);
193  size_t size = (size_t)(mmax - mmin + 1);
194  memcpy(dft.get_v() + mmin, dftmp.get_v() + mmin, size * sizeofdouble);
195 
196  dft.save_dvector_derivatives(t_pos);
197 }
Description not yet available.
Definition: fvar.hpp:920
Base class for dvariable.
Definition: fvar.hpp:1315
void memcpy(test_smartlist &dest, void *source, const size_t nsize)
memcpy for test_smartlist
Definition: df1b2f10.cpp:367
Description not yet available.
Definition: fvar.hpp:4440
void allocatec(const dvar_vector &)
Description not yet available.
Definition: fvar_arr.cpp:243
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
friend dvector value(const dvar_vector &v1)
Description not yet available.
Definition: fvar_ar3.cpp:43
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
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
unsigned int size() const
Definition: fvar.hpp:2297
Holds the data for the prevariable class.
Definition: fvar.hpp:191
void set_gradient_stack(void(*func)(void), double *dep_addr, double *ind_addr1=NULL, double mult1=0, double *ind_addr2=NULL, double mult2=0)
Description not yet available.
Definition: fvar.hpp:1045
prevariable_position restore_prevariable_position()
Definition: cmpdif8.cpp:43
void save_prevariable_position(const prevariable &v)
Definition: cmpdif8.cpp:60
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
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void dv_assign(void)
Adjoint to compute gradients for dvar_vector::operator=(const dvar_vector&amp;)
Definition: fvar_a20.cpp:172
unsigned int ncopies
Copy counter to enable shallow copies.
Definition: vector_shapex.h:79
int save_identifier_string(const char *)
Writes a gradient stack verification string.
Definition: cmpdif2.cpp:315
int indexmin() const
Definition: fvar.hpp:2287
void save_dvar_vector_position(const dvar_vector &v)
Definition: cmpdif3.cpp:214
static _THREAD DF_FILE * fp
void dv_eqdoub(void)
Adjoint to compute gradient for dvar_vector::operator=(const double).
Definition: fvar_a20.cpp:134
Stores the adjoint gradient data that will be processed by gradcalc.
dvector restore_dvar_vector_derivatives(const dvar_vector_position &tmp)
Description not yet available.
Definition: cmpdif5.cpp:150
void deallocate()
Deallocate dvar_vector memory.
Definition: fvar_ar1.cpp:15
dvar_vector & operator=(const dvar_vector &t)
Assign values from other t to dvar_vector.
Definition: fvar_a20.cpp:31
double_and_int * va
Definition: fvar.hpp:2175
void save_double_derivative(const double x, const prevariable_position &_pos)
Description not yet available.
Definition: cmpdif8.cpp:28
static _THREAD grad_stack * GRAD_STACK1
#define max(a, b)
Definition: cbivnorm.cpp:189
void dv_eqprev(void)
Adjoint to compute gradient for dvar_vector::operator=(const prevariable&amp;).
Definition: fvar_a20.cpp:146
double *& get_v(void)
Definition: dvector.h:148
int indexmax() const
Definition: fvar.hpp:2292
vector_shapex * shape
Definition: fvar.hpp:2179
double x
&lt; value of the variable
Definition: fvar.hpp:195