ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_dif.cpp
Go to the documentation of this file.
1 /*
2 Author: David Fournier
3 Copyright (c) 2008-2012 Regents of the University of California
4 */
5 
6 #include "fvar.hpp"
7 
8 void DF_first_diference(void);
9 
16 {
17  if (x.size() <= 1)
18  {
19  cerr << "Error -- vector size too small"
20  " in first_difference(const dvar_vector&)" << endl;
21  ad_exit(1);
22  }
23 
26 
28  int mmin=x.indexmin();
29  int mmax=x.indexmax()-1;
30  dvar_vector tmp(mmin,mmax);
31  for (int i=mmin; i<=mmax; i++)
32  {
33  tmp.elem_value(i)=x.elem_value(i+1)-x.elem_value(i);
34  }
41  return(tmp);
42 }
43 
49 {
51 
57  dvector dfx(x_pos.indexmin(),x_pos.indexmax());
58  dfx.initialize();
59  for (int i=dfx.indexmax()-1; i>=dfx.indexmin(); i--)
60  {
61  // tmp.elem_value(i)=x.elem_value(i+1)-x.elem_value(i);
62  dfx.elem(i+1)+=dftmp.elem(i);
63  dfx.elem(i)-=dftmp.elem(i);
64  }
65  dfx.save_dvector_derivatives(x_pos);
66 }
double & elem(int i)
Definition: dvector.h:152
double & elem_value(int i)
Definition: fvar.hpp:2226
#define x
Vector of double precision numbers.
Definition: dvector.h:50
Description not yet available.
Definition: fvar.hpp:4814
int indexmin() const
Definition: fvar.hpp:4827
exitptr ad_exit
Definition: gradstrc.cpp:53
void DF_first_diference(void)
Description not yet available.
Definition: fvar_dif.cpp:48
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
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
prnstream & endl(prnstream &)
int indexmax() const
Definition: fvar.hpp:4831
dvar_vector_position restore_dvar_vector_position()
Definition: cmpdif4.cpp:69
void RETURN_ARRAYS_INCREMENT()
Definition: gradstrc.cpp:478
dvector first_difference(const dvector &values)
Returns dvector containing the differences of an values(i) and values(i + 1) for i = 1 to values...
Definition: dvec_dif.cpp:17
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static _THREAD gradient_structure * _instance
void initialize(void)
Initialze all elements of dvector to zero.
Definition: dvect5.cpp:10
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
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 RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
static _THREAD grad_stack * GRAD_STACK1
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
int indexmax() const
Definition: fvar.hpp:2292