The R Project SVN R

Rev

Rev 6615 | Rev 6628 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6615 Rev 6623
Line 237... Line 237...
237
static int have_gradient;
237
static int have_gradient;
238
static int have_hessian;
238
static int have_hessian;
239
 
239
 
240
#define FT_SIZE 5		/* size of table to store computed
240
#define FT_SIZE 5		/* size of table to store computed
241
				   function values */
241
				   function values */
242
static int xdim;		/* length of the parameter (x) vector */
-
 
243
static int FT_last;		/* Newest entry in the table */
242
static int FT_last;		/* Newest entry in the table */
-
 
243
/*static int xdim;		-* length of the parameter (x) vector */
244
 
244
 
245
static struct {
245
static struct {
246
    double   fval;
246
    double   fval;
247
    double  *x;
247
    double  *x;
248
    double  *grad;
248
    double  *grad;
Line 252... Line 252...
252
/* Initialize the storage in the table of computed function values */
252
/* Initialize the storage in the table of computed function values */
253
 
253
 
254
static void FT_init(int n)
254
static void FT_init(int n)
255
{
255
{
256
    int i, j;
256
    int i, j;
257
    
257
 
258
    for (i = 0; i < FT_SIZE; i++) {
258
    for (i = 0; i < FT_SIZE; i++) {
259
	Ftable[i].x =  Calloc(n, double);
259
	Ftable[i].x =  Calloc(n, double);
260
				/* initialize to unlikely parameter values */
260
				/* initialize to unlikely parameter values */
261
	for (j = 0; j < n; j++) {
261
	for (j = 0; j < n; j++) {
262
	    Ftable[i].x[j] = DBL_MAX;
262
	    Ftable[i].x[j] = DBL_MAX;
Line 288... Line 288...
288
    FT_last = -1;
288
    FT_last = -1;
289
}
289
}
290
 
290
 
291
/* Store an entry in the table of computed function values */
291
/* Store an entry in the table of computed function values */
292
 
292
 
293
static int FT_store(int n, double f, double *x, double *grad, double *hess)
293
static void FT_store(int n, double f, double *x, double *grad, double *hess)
294
{
294
{
295
    int ind, i;
295
    int ind;
296
 
296
 
297
    ind = (++FT_last) % FT_SIZE;
297
    ind = (++FT_last) % FT_SIZE;
298
    Ftable[ind].fval = f;
298
    Ftable[ind].fval = f;
299
    Memcpy(Ftable[ind].x, x, n);
299
    Memcpy(Ftable[ind].x, x, n);
300
    if (grad) {
300
    if (grad) {
Line 337... Line 337...
337
static int F77_SYMBOL(fcn)(int *n, double *x, double *f)
337
static int F77_SYMBOL(fcn)(int *n, double *x, double *f)
338
{
338
{
339
    SEXP s;
339
    SEXP s;
340
    double *g = (double *) 0, *h = (double *) 0;
340
    double *g = (double *) 0, *h = (double *) 0;
341
    int i;
341
    int i;
342
    
342
 
343
    if ((i = FT_lookup(*n, x)) >= 0) {
343
    if ((i = FT_lookup(*n, x)) >= 0) {
344
	*f = Ftable[i].fval;
344
	*f = Ftable[i].fval;
345
	return 0;
345
	return 0;
346
    }
346
    }
347
				/* calculate for a new value of x */
347
				/* calculate for a new value of x */