Skip to content

Commit 23109f0

Browse files
committed
Scipy: implemented maxiter and verbose option, returned the proper values in the minimizer as well.
1 parent 592c6f1 commit 23109f0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

math/scipy/src/ScipyMinimizer.cxx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ bool ScipyMinimizer::Minimize()
208208
PyDict_SetItemString(pyoptions, key.c_str(), PyFloat_FromDouble(value));
209209
}
210210
}
211-
211+
PyDict_SetItemString(pyoptions, "maxiter", PyLong_FromLong(MaxIterations()));
212+
if(PrintLevel()>0)
213+
{
214+
PyDict_SetItemString(pyoptions, "disp", Py_True);
215+
}
212216
std::cout << "=== Scipy Minimization" << std::endl;
213217
std::cout << "=== Method: " << method << std::endl;
214218
std::cout << "=== Initial value: (";
@@ -270,9 +274,14 @@ bool ScipyMinimizer::Minimize()
270274

271275
// if the minimization works
272276
PyObject *pstatus = PyObject_GetAttrString(result, "status");
273-
bool status = PyBool_Check(pstatus);
277+
int status = PyLong_AsLong(pstatus);
274278
Py_DECREF(pstatus);
275279

280+
PyObject *psuccess = PyObject_GetAttrString(result, "success");
281+
bool success = PyLong_AsLong(psuccess);
282+
Py_DECREF(psuccess);
283+
284+
276285
// the x values for the minimum
277286
PyArrayObject *pyx = (PyArrayObject *)PyObject_GetAttrString(result, "x");
278287
const double *x = (const double *)PyArray_DATA(pyx);
@@ -292,10 +301,11 @@ bool ScipyMinimizer::Minimize()
292301
SetMinValue(obj_value);
293302
fCalls = nfev; //number of function evaluations
294303

304+
std::cout << "=== Success: " << success << std::endl;
295305
std::cout << "=== Status: " << status << std::endl;
296306
std::cout << "=== Message: " << message << std::endl;
297307
std::cout << "=== Function calls: " << nfev << std::endl;
298-
return status;
308+
return success;
299309
}
300310

301311
//_______________________________________________________________________

0 commit comments

Comments
 (0)