From c307dc6b5c5fe79a74b44cdeffd1601c062cf06e Mon Sep 17 00:00:00 2001 From: stevenj Date: Tue, 6 Jul 2010 17:14:18 -0400 Subject: [PATCH] fix python mconstraint, change C++ mconstraint to infer m from tol.size() darcs-hash:20100706211418-c8de0-cd6dc26c140e257683b533f02d497ffa132db1e1.gz --- api/nlopt-in.hpp | 24 ++++++++---------------- swig/nlopt-python.i | 4 ++-- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/api/nlopt-in.hpp b/api/nlopt-in.hpp index f82e3f7..ee76d97 100644 --- a/api/nlopt-in.hpp +++ b/api/nlopt-in.hpp @@ -344,15 +344,13 @@ namespace nlopt { mythrow(nlopt_add_inequality_constraint(o, myvfunc, d, tol)); alloc_tmp(); } - void add_inequality_mconstraint(unsigned m, mfunc mf, void *f_data, + void add_inequality_mconstraint(mfunc mf, void *f_data, const std::vector &tol) { - if (o && nlopt_get_dimension(o) != tol.size()) - throw std::invalid_argument("dimension mismatch"); myfunc_data *d = new myfunc_data; if (!d) throw std::bad_alloc(); d->o = this; d->mf = mf; d->f_data = f_data; d->f = NULL; d->vf = NULL; d->munge_destroy = d->munge_copy = NULL; - mythrow(nlopt_add_inequality_mconstraint(o, m, mymfunc, d, + mythrow(nlopt_add_inequality_mconstraint(o, tol.size(), mymfunc, d, tol.empty() ? NULL : &tol[0])); } @@ -375,15 +373,13 @@ namespace nlopt { mythrow(nlopt_add_equality_constraint(o, myvfunc, d, tol)); alloc_tmp(); } - void add_equality_mconstraint(unsigned m, mfunc mf, void *f_data, + void add_equality_mconstraint(mfunc mf, void *f_data, const std::vector &tol) { - if (o && nlopt_get_dimension(o) != tol.size()) - throw std::invalid_argument("dimension mismatch"); myfunc_data *d = new myfunc_data; if (!d) throw std::bad_alloc(); d->o = this; d->mf = mf; d->f_data = f_data; d->f = NULL; d->vf = NULL; d->munge_destroy = d->munge_copy = NULL; - mythrow(nlopt_add_equality_mconstraint(o, m, mymfunc, d, + mythrow(nlopt_add_equality_mconstraint(o, tol.size(), mymfunc, d, tol.empty() ? NULL : &tol[0])); } @@ -406,28 +402,24 @@ namespace nlopt { d->munge_destroy = md; d->munge_copy = mc; mythrow(nlopt_add_equality_constraint(o, myfunc, d, tol)); } - void add_inequality_mconstraint(unsigned m, mfunc mf, void *f_data, + void add_inequality_mconstraint(mfunc mf, void *f_data, nlopt_munge md, nlopt_munge mc, const std::vector &tol) { - if (o && nlopt_get_dimension(o) != tol.size()) - throw std::invalid_argument("dimension mismatch"); myfunc_data *d = new myfunc_data; if (!d) throw std::bad_alloc(); d->o = this; d->mf = mf; d->f_data = f_data; d->f = NULL; d->vf = NULL; d->munge_destroy = md; d->munge_copy = mc; - mythrow(nlopt_add_inequality_mconstraint(o, m, mymfunc, d, + mythrow(nlopt_add_inequality_mconstraint(o, tol.size(), mymfunc, d, tol.empty() ? NULL : &tol[0])); } - void add_equality_mconstraint(unsigned m, mfunc mf, void *f_data, + void add_equality_mconstraint(mfunc mf, void *f_data, nlopt_munge md, nlopt_munge mc, const std::vector &tol) { - if (o && nlopt_get_dimension(o) != tol.size()) - throw std::invalid_argument("dimension mismatch"); myfunc_data *d = new myfunc_data; if (!d) throw std::bad_alloc(); d->o = this; d->mf = mf; d->f_data = f_data; d->f = NULL; d->vf = NULL; d->munge_destroy = md; d->munge_copy = mc; - mythrow(nlopt_add_equality_mconstraint(o, m, mymfunc, d, + mythrow(nlopt_add_equality_mconstraint(o, tol.size(), mymfunc, d, tol.empty() ? NULL : &tol[0])); } diff --git a/swig/nlopt-python.i b/swig/nlopt-python.i index ed58b69..db1967a 100644 --- a/swig/nlopt-python.i +++ b/swig/nlopt-python.i @@ -189,12 +189,12 @@ static void mfunc_python(unsigned m, double *result, $1 = PyCallable_Check($input); } -%typemap(in)(nlopt::mfunc f, void *f_data, nlopt_munge md, nlopt_munge mc) { +%typemap(in)(nlopt::mfunc mf, void *f_data, nlopt_munge md, nlopt_munge mc) { $1 = mfunc_python; $2 = dup_pyfunc((void*) $input); $3 = free_pyfunc; $4 = dup_pyfunc; } -%typecheck(SWIG_TYPECHECK_POINTER)(nlopt::mfunc f, void *f_data, nlopt_munge md, nlopt_munge mc) { +%typecheck(SWIG_TYPECHECK_POINTER)(nlopt::mfunc mf, void *f_data, nlopt_munge md, nlopt_munge mc) { $1 = PyCallable_Check($input); } -- 2.30.2