ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmpdif4.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 
13 #ifdef __TURBOC__
14  #pragma hdrstop
15  #include <iostream.h>
16 #endif
17 
18 #ifdef __ZTC__
19  #include <iostream.hpp>
20 #endif
21 
22 #include <string.h>
23 
29 {
31 }
33 {
34  // saves the size and address information for a dvar_vector
35  constexpr size_t wsize=sizeof(dvector_position);
36  dvector_position tmp(v);
37  //int num_rec;
38  fwrite(&tmp, wsize);
39 }
40 
46 {
48 }
50 {
51  // reads back the size and address information for a ivector
52  // Back up the stream and read the number of bytes written in the
53  // ``write function'' corresponding to this ``read function''
54  constexpr size_t wsize = sizeof(dvector_position);
55  ivector_position tmp;
56  //int ierr;
57  fread(&tmp, wsize);
58  return tmp;
59 }
60 
66 {
68 }
70 {
71  // reads back the size and address information for a dvar_vector
72  // Back up the stream and read the number of bytes written in the
73  // ``write function'' corresponding to this ``read function''
74  constexpr size_t wsize = sizeof(dvar_vector_position);
76  fread(&tmp, wsize);
77  return tmp;
78 }
79 
85 {
87 }
89 {
90  // reads back the size and address information for a dvar_vector
91  // Back up the stream and read the number of bytes written in the
92  // ``write function'' corresponding to this ``read function''
93  constexpr size_t wsize = sizeof(dvector_position);
94  dvector_position tmp;
95  fread(&tmp, wsize);
96  return tmp;
97 }
98 
103 {
105 }
107 {
108  //int ierr=save_dvar_vector_position();
109  //const unsigned wsize=sizeof(double);
110  //int num_rec;
111  int min=v.indexmin();
112  int max=v.indexmax();
113  const double_and_int* pvi = v.va + min;
114  for (int i=min;i<=max;++i)
115  {
116  //double tmp=value((*this)(i));
117  //gradient_structure::get_fp()->fwrite(&tmp,wsize);
118  fwrite(pvi->x);
119  ++pvi;
120  }
121 }
122 
127 {
129 }
131 {
132  // int ierr=save_dvector_position();
133  //int wsize=sizeof(double);
134  //int num_rec;
135  int min = v.indexmin();
136  int max = v.indexmax();
137  double* pv = v.get_v() + min;
138  for (int i = min; i <= max; ++i)
139  {
140  fwrite(*pv);
141  ++pv;
142  }
143 }
144 
149 {
151 }
153 {
154  // int ierr=save_ivector_position();
155  constexpr size_t wsize=sizeof(int);
156  int min=v.indexmin();
157  int max=v.indexmax();
158  const int* pvi = v.get_v() + min;
159  for (int i=min;i<=max;i++)
160  {
161  fwrite(pvi, wsize);
162  ++pvi;
163  }
164 }
165 
175 {
177 }
179 {
180  // restores the size, address, and value information for a dvar_vector
181  int min = tmp.indexmin();
182  int max = tmp.indexmax();
183  dvector temp_vec(min, max);
184  constexpr size_t size = sizeof(double);
185  double* ptemp_vec = temp_vec.get_v() + max;
186  for (int i = max; i >= min; --i)
187  {
188  fread(ptemp_vec, size);
189  --ptemp_vec;
190  }
191  return temp_vec;
192 }
193 
199 {
201 }
203 {
204  // restores the size, address, and value information for a ivector
205  // Back up the stream and read the number of bytes written in the
206  // ``write function'' corresponding to this ``read function''
207  constexpr size_t sizeofint = sizeof(int);
208  int min = tmp.indexmin();
209  int max = tmp.indexmax();
210  ivector temp_vec(min, max);
211  int* ptemp_veci = temp_vec.get_v() + max;
212  for (int i = max; i >= min; --i)
213  {
214  fread(ptemp_veci, sizeofint);
215  --ptemp_veci;
216  }
217  return temp_vec;
218  // Back up the stream again for the next function
219 }
220 
228 {
230 }
232 {
233  int min = tmp.indexmin();
234  int max = tmp.indexmax();
235  dvector temp_vec(min, max);
236  double* ptemp_veci = temp_vec.get_v() + max;
237  for (int i = max; i >= min; --i)
238  {
239  //gradient_structure::get_fp()->fread(&ttmp,sizeof(double));
240  fread(*ptemp_veci);
241  --ptemp_veci;
242  }
243  return temp_vec;
244 }
249 {
251 }
253 {
254  int min=m.rowmin();
255  int max=m.rowmax();
256  const dvar_vector* pmi = &m(min);
257  for (int i=min;i<=max;++i)
258  {
261  ++pmi;
262  }
263 }
int indexmax() const
Definition: fvar.hpp:4936
void save_dvar_matrix_value() const
Saves the size, address, and value information for a dvar_matrix.
Definition: cmpdif4.cpp:248
int rowmax(void) const
Definition: fvar.hpp:2564
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
ivector_position restore_ivector_position()
Definition: cmpdif4.cpp:49
Description not yet available.
Definition: fvar.hpp:4814
int indexmin() const
Definition: fvar.hpp:4827
int indexmax() const
Definition: fvar.hpp:4960
Description not yet available.
Definition: fvar.hpp:4923
ADMB variable vector.
Definition: fvar.hpp:2172
dvector restore_dvector_value(const dvector_position &tmp)
Definition: cmpdif4.cpp:178
Holds the data for the prevariable class.
Definition: fvar.hpp:191
dvector_position restore_dvector_position()
Description not yet available.
Definition: cmpdif4.cpp:84
int * get_v() const
Definition: ivector.h:114
void save_dvector_position(const dvector &v)
Definition: cmpdif4.cpp:32
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
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
void save_dvar_vector_value(const dvar_vector &v)
Definition: cmpdif4.cpp:106
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
void save_dvar_vector_value() const
Saves the size, address, and value information for a dvar_vector.
Definition: cmpdif4.cpp:102
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
int indexmax() const
Definition: ivector.h:104
int rowmin(void) const
Definition: fvar.hpp:2560
dvector restore_dvar_vector_value(const dvar_vector_position &tmp)
Restores the size, address, and value information for a dvar_vector.
Definition: cmpdif4.cpp:227
dvector_position restore_dvector_position()
Definition: cmpdif4.cpp:88
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
int indexmin() const
Definition: fvar.hpp:4932
ivector restore_ivector_value(const ivector_position &tmp)
Description not yet available.
Definition: cmpdif4.cpp:198
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
ivector restore_ivector_value(const ivector_position &tmp)
Definition: cmpdif4.cpp:202
void fwrite(const void *s, const size_t num_bytes)
Reads num_bytes from s and writes to buffer.
Definition: df_file.cpp:296
void save_dvar_matrix_value(const dvar_matrix &m)
Definition: cmpdif4.cpp:252
void fread(void *s, const size_t num_bytes)
Reads num_bytes from buffer and copies to s.
Definition: df_file.cpp:270
ivector_position restore_ivector_position()
Description not yet available.
Definition: cmpdif4.cpp:45
double_and_int * va
Definition: fvar.hpp:2175
int indexmin() const
Definition: fvar.hpp:4956
dvar_vector_position restore_dvar_vector_position()
Description not yet available.
Definition: cmpdif4.cpp:65
void save_ivector_value() const
Saves the size, address, and value information for a ivector.
Definition: cmpdif4.cpp:148
#define max(a, b)
Definition: cbivnorm.cpp:189
double *& get_v(void)
Definition: dvector.h:148
int indexmax() const
Definition: fvar.hpp:2292
dvector restore_dvector_value(const dvector_position &tmp)
Restores the size, address, and value information for a dvector.
Definition: cmpdif4.cpp:174
void save_ivector_value(const ivector &v)
Definition: cmpdif4.cpp:152
double x
&lt; value of the variable
Definition: fvar.hpp:195
void save_dvector_position() const
Description not yet available.
Definition: cmpdif4.cpp:28
void save_dvector_value() const
Saves the size, address, and value information for a dvector.
Definition: cmpdif4.cpp:126