ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_a17.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 _MSC_VER
13  #include <memory.h>
14 #endif
15 #ifdef DEBUG
16  #include <cassert>
17 #endif
18 
19 void dvdv_add(void);
20 
26 {
27  int mmin=v1.indexmin();
28  int mmax=v1.indexmax();
29 #ifdef OPT_LIB
30  if (mmin != v2.indexmin() || mmax != v2.indexmax())
31  {
32  cerr << "Incompatible bounds in "
33  "prevariable operator + (const dvar_vector& v1, const dvar_vector& v2)"
34  << endl;
35  ad_exit(1);
36  }
37 #endif
38  //dvector cv1=value(v1);
39  //dvector cv2=value(v2);
40  kkludge_object kkk;
41  dvar_vector vtmp(mmin, mmax, kkk);
42 
43 #ifdef USE_ASSEMBLER
44  int min=v1.indexmin();
45  int n=v1.indexmax()-min+1;
46  dp_vector_add(&(vtmp.elem_value(min)),&(v1.elem_value(min)),
47  &(v2.elem_value(min)),n);
48 #else
49  double_and_int* pvtmp = vtmp.va + mmin;
50  double_and_int* pv1 = v1.va + mmin;
51  double_and_int* pv2 = v2.va + mmin;
52  for (int i = mmin; i <= mmax; ++i)
53  {
54  //vtmp.elem_value(i)=v1.elem_value(i)+v2.elem_value(i);
55  pvtmp->x = pv1->x + pv2->x;
56  ++pvtmp;
57  ++pv1;
58  ++pv2;
59  }
60 #endif
61 
62  //dvar_vector vtmp=nograd_assign(tmp);
63 
66  // The derivative list considerations
67  save_identifier_string("bbbb");
70  fp->save_dvar_vector_position(vtmp);
71  save_identifier_string("aaaa");
72  GRAD_STACK1->set_gradient_stack(dvdv_add);
73 
74  return vtmp;
75 }
76 
81 void dvdv_add(void)
82 {
84 
85  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
92  int mmin=dftmp.indexmin();
93  int mmax=dftmp.indexmax();
94 #ifdef DEBUG
95  assert(mmax >= mmin);
96 #endif
97  dvector dfv1(mmin,mmax);
98  dvector dfv2(mmin,mmax);
99 #ifdef OPT_LIB
100  constexpr size_t sizeofdouble = sizeof(double);
101  size_t size = (size_t)(mmax - mmin + 1) * sizeofdouble;
102  memcpy(&dfv1.elem(mmin),&dftmp.elem(mmin), size);
103  memcpy(&dfv2.elem(mmin),&dftmp.elem(mmin), size);
104 #else
105  for (int i=dftmp.indexmin();i<=dftmp.indexmax();i++)
106  {
107  //vtmp.elem(i)=value(v1.elem(i))+value(v2.elem(i));
108  dfv1(i)=dftmp.elem(i);
109  dfv2(i)=dftmp.elem(i);
110  }
111 #endif
112  dfv1.save_dvector_derivatives(v1pos);
113  dfv2.save_dvector_derivatives(v2pos);
114  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
115 }
Description not yet available.
Definition: fvar.hpp:920
void memcpy(test_smartlist &dest, void *source, const size_t nsize)
memcpy for test_smartlist
Definition: df1b2f10.cpp:367
double & elem(int i)
Definition: dvector.h:152
double & elem_value(int i)
Definition: fvar.hpp:2226
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
void dvdv_add(void)
Description not yet available.
Definition: fvar_a17.cpp:81
d3_array operator+(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements addition of a(i, j, k) + b(i, j, k).
Definition: d3arr2a.cpp:132
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
Null class to allow specialized function overloads.
Definition: fvar.hpp:469
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
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
prnstream & endl(prnstream &)
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.
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
double_and_int * va
Definition: fvar.hpp:2175
static _THREAD grad_stack * GRAD_STACK1
int indexmax() const
Definition: fvar.hpp:2292
double x
&lt; value of the variable
Definition: fvar.hpp:195