chiark / gitweb /
make internal nlopt_opt.work field a void* rather than double*
authorstevenj <stevenj@alum.mit.edu>
Wed, 8 Aug 2012 15:51:36 +0000 (11:51 -0400)
committerstevenj <stevenj@alum.mit.edu>
Wed, 8 Aug 2012 15:51:36 +0000 (11:51 -0400)
Ignore-this: b4982d664cb36d41394eb11846fdcbdb

darcs-hash:20120808155136-c8de0-52cb9e5a263de6efabfb58a9cffcd8f8bfa7ea05.gz

api/nlopt-internal.h
api/optimize.c

index f205cbe04f74777960a408cc6bd52c06d9bf6974..d1e49c3a403533aad0ecd2159230db139212ef91 100644 (file)
@@ -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 */
 };
 
 /*********************************************************************/
index af0886fb4a93c3ecb66747b3c5a8c6eef751bb7c..6522c5149e6c37a2f5b3f67e1d22f2af6daf9c9a 100644 (file)
@@ -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,