chiark / gitweb /
when adding mconstraints, allow tol==NULL as synonym for zero tolerances
authorstevenj <stevenj@alum.mit.edu>
Tue, 15 Nov 2011 20:41:17 +0000 (15:41 -0500)
committerstevenj <stevenj@alum.mit.edu>
Tue, 15 Nov 2011 20:41:17 +0000 (15:41 -0500)
Ignore-this: db03978604ff683b95100eb50764dab9

darcs-hash:20111115204117-c8de0-f16c8f5ab44f1aa3ade48b350675d4a094c25e03.gz

api/options.c

index be9ef7276c3feac3e24c07a7ef8e419c8fdd7de9..1722fc9e35804ad5d30a7d01148c0310f99f5b10 100644 (file)
@@ -342,13 +342,17 @@ static nlopt_result add_constraint(unsigned *m, unsigned *m_alloc,
      double *tolcopy;
      unsigned i;
 
-     if ((fc && mfc) || (fc && fm != 1) || (!fc && !mfc) || !tol)
+     if ((fc && mfc) || (fc && fm != 1) || (!fc && !mfc))
          return NLOPT_INVALID_ARGS;
-     for (i = 0; i < fm; ++i) if (tol[i] < 0) return NLOPT_INVALID_ARGS;
+     if (tol) 
+         for (i = 0; i < fm; ++i) if (tol[i] < 0) return NLOPT_INVALID_ARGS;
      
      tolcopy = (double *) malloc(sizeof(double) * fm);
      if (fm && !tolcopy) return NLOPT_OUT_OF_MEMORY;
-     memcpy(tolcopy, tol, sizeof(double) * fm);
+     if (tol)
+         memcpy(tolcopy, tol, sizeof(double) * fm);
+     else
+         for (i = 0; i < fm; ++i) tolcopy[i] = 0;
 
      *m += 1;
      if (*m > *m_alloc) {