17 #if defined (__WAT32__)
23 #include <iostream.hpp>
65 #if !defined(OPT_LIB) && (__cplusplus >= 201103L)
66 int n = [](
unsigned int colsize) ->
int
68 assert(colsize <= INT_MAX);
69 return static_cast<int>(colsize);
72 int n =
static_cast<int>(aa.
colsize());
78 cerr <<
"Error matrix not square in solve()"<<
endl;
85 double big,dum,
sum,temp;
93 double* pvv = vv.
get_v() + lb;
95 for (
int i=lb;i<=ub;i++)
98 double* pbbij = pbbi->
get_v() + lb;
99 for (
int j=lb;j<=ub;j++)
110 cerr <<
"Error in matrix inverse -- matrix singular in "
111 "solve(dvar_dmatrix)\n";
119 for (
int j=lb;j<=ub;j++)
122 for (
int i = lb; i < j; ++i)
124 double* pbbij = pbbi->
get_v() + j;
127 double* pbbik = pbbi->
get_v() + lb;
129 for (
int k=lb;k<i;k++)
131 sum -= *pbbik * *(pbbk->
get_v() + j);
144 pvv = vv.
get_v() + j;
147 for (
int i=j;i<=ub;i++)
149 double* pbbij = pbbi->
get_v() + j;
152 double* pbbik = pbbi->
get_v() + lb;
154 for (
int k=lb;k<j;k++)
156 sum -= *pbbik * *(pbbk->
get_v() + j);
161 dum = *pvv *
fabs(sum);
173 double* pbbimaxk = bb.
elem(imax).
get_v() + lb;
174 double* pbbjk = pbbj->
get_v() + lb;
175 for (
int k=lb;k<=ub;k++)
189 int* pindximax = indx.
get_v() + imax;
190 int* pindxj = indx.
get_v() + j;
192 int itemp = *pindximax;
193 *pindximax = *pindxj;
199 double* pbbjj = pbbj->
get_v() + j;
209 for (
int i=j+1;i<=ub;i++)
211 double* pbbij = pbbi->
get_v() + j;
212 *pbbij = *pbbij * dum;
224 part_prod(lb)=
log(
fabs(bb(lb,lb)));
225 if (bb(lb,lb)<0) sign=-
sign;
226 for (
int j=lb+1;j<=ub;j++)
228 double bbjj = bb(j, j);
229 if (bbjj < 0) sign=-
sign;
230 part_prod(j)=part_prod(j-1)+
log(
fabs(bbjj));
232 ln_unsigned_det=part_prod(ub);
241 int* pindx = indx.
get_v() + lb;
242 int* pindxinv = indxinv.
get_v();
243 for (
int i = lb; i <= ub; ++i)
245 *(pindxinv + *pindx) = i;
250 pindxinv = indxinv.
get_v() + lb;
251 double* py = y.
get_v();
252 for (
int i = lb; i <= ub; ++i)
254 *(py + *pindxinv) = pz->
x;
262 for (
int i=lb;i<=ub;i++)
266 double* pyj = y.
get_v() + lb;
267 double* pbij = pbi->
get_v() + lb;
268 for (
int j=lb;j<=i-1;j++)
283 double* px = x.
get_v() + ub;
285 for (
int i=ub;i>=lb;i--)
289 double* pxj = x.
get_v() + i + 1;
290 double* pbij = pbi->
get_v() + i + 1;
291 for (
int j=i+1;j<=ub;j++)
298 *px = sum / *(pbi->
get_v() + i);
378 int* pindx = indx.
get_v() + lb;
379 int* pindxinv = indxinv.
get_v();
380 for (
int i = lb; i <= ub; ++i)
382 *(pindxinv + *pindx) = i;
387 #ifndef SAFE_INITIALIZE
394 double* pdfxi = dfx.
get_v() + lb;
395 double* pdfyi = dfy.
get_v() + lb;
396 double* pxi = x.
get_v() + lb;
399 for (
int i = lb; i <= ub; ++i)
401 double* pbii = pbi->
get_v() + i;
404 dfsum += *pdfxi / *pbii;
405 *(pdfbi->
get_v() + i) -= *pdfxi * *pxi / *pbii;
408 double* pxj = x.
get_v() + ub;
409 double* pdfxj = dfx.
get_v() + ub;
410 double* pbij = pbi->
get_v() + ub;
411 double* pdfbij = pdfbi->
get_v() + ub;
412 for (
int j = ub; j >= i + 1; --j)
415 *pdfbij -= dfsum* *pxj;
416 *pdfxj -= dfsum * *pbij;
434 pdfyi = dfy.
get_v() + ub;
435 pdfbi = &dfb.
elem(ub);
437 for (
int i=ub;i>=lb;i--)
443 double* pdfyj = dfy.
get_v() + i - 1;
444 double* pyj = y.
get_v() + i - 1;
445 double* pdfbij = pdfbi->
get_v() + i - 1;
446 double* pbij = pbi->
get_v() + i - 1;
447 for (
int j=i-1;j>=lb;j--)
450 *pdfbij -= dfsum * *pyj;
451 *pdfyj -= dfsum * *pbij;
467 double* pdfz = dfz.
get_v() + ub;
468 double* pdfy = dfy.
get_v();
469 pindxinv = indxinv.
get_v() + ub;
470 for (
int i=ub;i>=lb;i--)
473 *pdfz = *(pdfy + *pindxinv);
480 double* pdfpart_prod = dfpart_prod.
get_v() + ub;
482 *pdfpart_prod += df_ln_det;
487 for (
int j=ub;j>=lb+1;j--)
489 double* pdfpart_prod2 = pdfpart_prod - 1;
491 *pdfpart_prod2 += *pdfpart_prod;
492 *(pdfbj->
get_v() + j) += *pdfpart_prod / *(pbj->
get_v() + j);
501 *(pdfbj->
get_v() + lb) += *pdfpart_prod / *(pbj->
get_v() + lb);
505 for (
int j = ub; j >= lb; --j)
507 double bjj = b(j, j);
508 double* pdfbjj = pdfbj->
get_v() + j;
510 int* pindxi = indx.
get_v() + ub;
514 for (
int i = ub; i >= lb; --i)
516 double* pdfbij = pdfbi->
get_v() + j;
517 double* pbij = pbi->
get_v() + j;
527 dfsum+= *pdfbij / bjj;
528 *pdfbjj -= *pdfbij * *pbij / bjj;
532 int kmax =
min(i - 1, j - 1);
535 double* pdfbik = pdfbi->
get_v() + kmax;
537 double* pbik = pbi->
get_v() + kmax;
539 for (
int k = kmax; k >= lb; --k)
542 *pdfbik -= dfsum * *(pbk->
get_v() + j);
543 *(pdfbk->
get_v() + j) -= dfsum * *pbik;
Description not yet available.
Base class for dvariable.
void dmdv_solve(void)
Adjoint code for dvar_vector solve(const dvar_matrix& aa, const dvar_vector& z,.
double restore_prevariable_derivative()
void save_ivector_position(const ivector &v)
Vector of double precision numbers.
ivector_position restore_ivector_position()
void save_dmatrix_position(const dmatrix &m)
double_and_int * get_va()
dvar_vector nograd_assign(dvector tmp)
Description not yet available.
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void save_dvector_derivatives(const dvar_vector_position &pos) const
Puts the derivative values in a dvector into a dvar_vector's guts.
Description not yet available.
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)
Null class to allow specialized function overloads.
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)
Holds the data for the prevariable class.
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.
dvector solve(const dmatrix &aa, const dvector &z)
Solve a linear system using LU decomposition.
void save_dvector_position(const dvector &v)
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
void save_prevariable_position(const prevariable &v)
void save_dvector_value(const dvector &v)
dvar_vector_position restore_dvar_vector_position()
void RETURN_ARRAYS_INCREMENT()
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()
void save_dvar_vector_position(const dvar_vector &v)
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.
dvector restore_dvar_vector_derivatives(const dvar_vector_position &tmp)
Description not yet available.
double sign(const double x)
The sign of a number.
void RETURN_ARRAYS_DECREMENT()
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.
Fundamental data type for reverse mode automatic differentiation.
void save_ivector_value(const ivector &v)
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
double x
< value of the variable
Description not yet available.
unsigned int colsize() const