From: stevenj Date: Thu, 8 Jul 2010 20:26:02 +0000 (-0400) Subject: use 2-dimensional array for grad arg of python mconstraint X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=44de5da75899598e78e6727dfed8e04a7d62a0cb;p=nlopt.git use 2-dimensional array for grad arg of python mconstraint darcs-hash:20100708202602-c8de0-815718d964a5c6e92ca5e254ba519a65c0f921e2.gz --- diff --git a/swig/nlopt-python.i b/swig/nlopt-python.i index 83df76f..e82f286 100644 --- a/swig/nlopt-python.i +++ b/swig/nlopt-python.i @@ -155,14 +155,15 @@ static double func_python(unsigned n, const double *x, double *grad, void *f) static void mfunc_python(unsigned m, double *result, unsigned n, const double *x, double *grad, void *f) { - npy_intp nsz = npy_intp(n), msz = npy_intp(m), mnsz = npy_intp(m * n); + npy_intp nsz = npy_intp(n), msz = npy_intp(m); + npy_intp mnsz[2] = {msz, nsz}; npy_intp sz0 = 0, stride1 = sizeof(double); PyObject *xpy = PyArray_New(&PyArray_Type, 1, &nsz, NPY_DOUBLE, &stride1, const_cast(x), // not NPY_WRITEABLE 0, NPY_C_CONTIGUOUS | NPY_ALIGNED, NULL); PyObject *rpy = PyArray_SimpleNewFromData(1, &msz, NPY_DOUBLE, result); PyObject *gradpy = grad - ? PyArray_SimpleNewFromData(1, &mnsz, NPY_DOUBLE, grad) + ? PyArray_SimpleNewFromData(2, mnsz, NPY_DOUBLE, grad) : PyArray_SimpleNew(1, &sz0, NPY_DOUBLE); PyObject *arglist = Py_BuildValue("OOO", rpy, xpy, gradpy);