From: stevenj Date: Wed, 8 Aug 2012 15:51:36 +0000 (-0400) Subject: make internal nlopt_opt.work field a void* rather than double* X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ecb4ceec3b168437d53ed0f153e5a3a029d0829d;p=nlopt.git make internal nlopt_opt.work field a void* rather than double* Ignore-this: b4982d664cb36d41394eb11846fdcbdb darcs-hash:20120808155136-c8de0-52cb9e5a263de6efabfb58a9cffcd8f8bfa7ea05.gz --- diff --git a/api/nlopt-internal.h b/api/nlopt-internal.h index f205cbe..d1e49c3 100644 --- a/api/nlopt-internal.h +++ b/api/nlopt-internal.h @@ -72,7 +72,7 @@ struct nlopt_opt_s { double *dx; /* initial step sizes (length n) for nonderivative algs */ unsigned vector_storage; /* max subspace dimension (0 for default) */ - double *work; /* algorithm-specific workspace during optimization */ + void *work; /* algorithm-specific workspace during optimization */ }; /*********************************************************************/ diff --git a/api/optimize.c b/api/optimize.c index af0886f..6522c51 100644 --- a/api/optimize.c +++ b/api/optimize.c @@ -89,16 +89,17 @@ static double f_noderiv(int n, const double *x, void *data_) static double f_direct(int n, const double *x, int *undefined, void *data_) { nlopt_opt data = (nlopt_opt) data_; + double *work = (double*) data->work; double f; unsigned i, j; f = data->f((unsigned) n, x, NULL, data->f_data); *undefined = isnan(f) || nlopt_isinf(f); if (nlopt_get_force_stop(data)) return f; for (i = 0; i < data->m && !*undefined; ++i) { - nlopt_eval_constraint(data->work, NULL, data->fc+i, (unsigned) n, x); + nlopt_eval_constraint(work, NULL, data->fc+i, (unsigned) n, x); if (nlopt_get_force_stop(data)) return f; for (j = 0; j < data->fc[i].m; ++j) - if (data->work[j] > 0) + if (work[j] > 0) *undefined = 1; } return f; @@ -442,9 +443,9 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf) case NLOPT_GN_ORIG_DIRECT_L: { direct_return_code dret; if (!finite_domain(n, lb, ub)) return NLOPT_INVALID_ARGS; - opt->work = (double*) malloc(sizeof(double) * - nlopt_max_constraint_dim(opt->m, - opt->fc)); + opt->work = malloc(sizeof(double) * + nlopt_max_constraint_dim(opt->m, + opt->fc)); if (!opt->work) return NLOPT_OUT_OF_MEMORY; dret = direct_optimize(f_direct, opt, ni, lb, ub, x, minf, stop.maxeval, -1,