19 #include <iostream.hpp>
31 int min(
const int a,
const int b)
33 return a <= b ? a : b;
46 #if !defined(OPT_LIB) && (__cplusplus >= 201103L)
47 int n = [](
unsigned int colsize) ->
int
49 assert(colsize <= INT_MAX);
50 return static_cast<int>(colsize);
53 int n =
static_cast<int>(aa.
colsize());
62 cerr <<
"Error in matrix inverse -- matrix singular in inv(dmatrix)\n";
67 vc(lb,lb)=1.0/aa(lb,lb);
75 double big,dum,
sum,temp;
82 double* pvvi = vv.
get_v() + lb;
83 for (
int i=lb;i<=ub;i++)
86 double* pbbij = pbbi->
get_v() + lb;
87 for (
int j=lb;j<=ub;j++)
98 cerr <<
"Error in matrix inverse -- matrix singular in inv(dmatrix)\n";
107 for (
int j=lb;j<=ub;j++)
110 for (
int i=lb;i<j;i++)
112 sum = *(pbbi->
get_v() +j);
114 double* pbbik = pbbi->
get_v() + lb;
116 for (
int k=lb;k<i;k++)
118 sum = sum - *pbbik * *(pbbk->
get_v() + j);
123 *(pbbi->
get_v() +j) = sum;
129 for (
int i=j;i<=ub;i++)
131 sum = *(pbbi->
get_v() + j);
133 double* pbbik = pbbi->
get_v() + lb;
135 for (
int k=lb;k<j;k++)
137 sum = sum - *pbbik * *(pbbk->
get_v() + j);
153 double* pbbimaxk = bb.
elem(imax).
get_v() + lb;
155 for (
int k=lb;k<=ub;k++)
169 int itemp=indx.
elem(imax);
176 if (bb.
elem(j,j) == 0.0)
183 dum=1.0/bb.
elem(j,j);
184 pbbi = &bb.
elem(j + 1);
185 for (
int i=j+1;i<=ub;i++)
187 *(pbbi->
get_v() + j) *= dum;
202 int* pindx = indx.
get_v() + lb;
203 int* pindxinv = indxinv.
get_v();
204 for (
int i=lb;i<=ub;i++)
206 *(pindxinv + *pindx)=i;
210 pindxinv = indxinv.
get_v() + lb;
211 for (
int ii=lb;ii<=ub;ii++)
214 const int indxinvii = *pindxinv;
218 double* pyi = y.
get_v() + indxinvii;
219 for (
int i=indxinvii;i<=ub;i++)
230 double* pbij = pbi->
get_v() + indxinvii;
231 double* pyj = y.
get_v() + indxinvii;
232 for (
int j=indxinvii;j<=i-1;j++)
244 pyi = y.
get_v() + ub;
245 double* pxi = x.
get_v() + ub;
247 for (
int i=ub;i>=lb;i--)
250 double* pxj = x.
get_v() + i + 1;
251 double* pbij = pbi->
get_v() + i + 1;
252 for (
int j=i+1;j<=ub;j++)
259 *pxi = sum / *(pbi->
get_v() + i);
306 int* pindx = indx.
get_v() + lb;
307 int* pindxinv = indxinv.
get_v();
308 for (
int i=lb;i<=ub;i++)
310 *(pindxinv + *pindx) = i;
316 #ifndef SAFE_INITIALIZE
320 for (
int ii=ub;ii>=lb;ii--)
328 double* pdfxi = dfx.
get_v() + lb;
329 double* pxi = x.
get_v() + lb;
332 for (
int i=lb;i<=ub;i++)
335 dfsum+= *pdfxi / b.
elem(i,i);
336 *(pdfbi->
get_v() + i) -= *pdfxi * *pxi / b.
elem(i,i);
339 double* pdfxj = dfx.
get_v() + ub;
340 double* pxj = x.
get_v() + ub;
341 double* pdfbij = pdfbi->
get_v() + ub;
342 double* pbij = pbi->
get_v() + ub;
343 for (
int j=ub;j>=i+1;j--)
346 *pdfbij -= dfsum * *pxj;
347 *pdfxj -= dfsum * *pbij;
365 int indxinvii = indxinv(ii);
366 double* pdfyi2 = dfy.
get_v() + ub;
367 for (
int i2=ub;i2>=indxinvii;i2--)
373 double* pyj = y.
get_v() + i2 - 1;
374 double* pdfyj = dfy.
get_v() + i2 - 1;
375 for (
int j=i2-1;j>=indxinvii;j--)
378 dfb.
elem(i2,j) -= dfsum * *pyj;
379 *pdfyj -= dfsum*b.
elem(i2,j);
396 for (
int j=ub;j>=lb;j--)
398 double bjj = b.
elem(j, j);
400 int* pindxi = indx.
get_v() + ub;
401 for (
int i=ub;i>=lb;i--)
403 double* pdfbij = pdfbi->
get_v() + j;
413 dfsum += *pdfbij / bjj;
414 dfb.
elem(j,j) -= *pdfbij * b.
elem(i,j) / bjj;
418 for (
int k=
min(i-1,j-1);k>=lb;k--)
Description not yet available.
dvector restore_dvar_matrix_derivative_column(const dvar_matrix_position &_pos, const int &ii)
Description not yet available.
void save_ivector_position(const ivector &v)
void dfinvpret(void)
Adjoint code for dvar_matrix inv(const dvar_matrix& aa).
Vector of double precision numbers.
ivector_position restore_ivector_position()
void save_dmatrix_position(const dmatrix &m)
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
df1_two_variable fabs(const df1_two_variable &x)
dmatrix_position restore_dmatrix_position()
Description not yet available.
void save_dmatrix_value(const dmatrix &m)
void verify_identifier_string(const char *)
Verifies gradient stack string.
void fill_seqadd(int, int)
Fills ivector elements with values starting from base and incremented by offset.
dvector restore_dvector_value(const dvector_position &tmp)
dmatrix restore_dmatrix_value(const dmatrix_position &mpos)
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.
void save_dvector_position(const dvector &v)
Array of integers(int) with indexes from index_min to indexmax.
void save_dvector_value(const dvector &v)
Description not yet available.
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static _THREAD gradient_structure * _instance
Description not yet available.
void initialize(void)
Initialze all elements of dvector to zero.
int save_identifier_string(const char *)
Writes a gradient stack verification string.
dvector_position restore_dvector_position()
dvar_matrix_position restore_dvar_matrix_position()
static _THREAD DF_FILE * fp
void save_dvar_matrix_position(const dvar_matrix &m)
ivector restore_ivector_value(const ivector_position &tmp)
Description not yet available.
Class definition of matrix with derivitive information .
Stores the adjoint gradient data that will be processed by gradcalc.
void nograd_assign_column(const dvar_matrix &m, const dvector &v, const int &ii)
Description not yet available.
dvector value(const df1_one_vector &v)
static _THREAD grad_stack * GRAD_STACK1
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
void save_dmatrix_derivatives(const dvar_matrix_position &_pos, const double x, const int &i, int &j)
Description not yet available.
void initialize(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
df1_one_variable inv(const df1_one_variable &x)
void save_ivector_value(const ivector &v)
Description not yet available.
unsigned int colsize() const