@@ -75,10 +75,9 @@ ScipyMinimizer::ScipyMinimizer() : BasicMinimizer()
7575 fOptions .SetMinimizerAlgorithm (" L-BFGS-B" );
7676 PyInitialize ();
7777 fHessianFunc = nullptr ;
78- // set extra options
79- SetAlgoExtraOptions ();
8078 fConstraintsList = PyList_New (0 );
8179 fConstN = 0 ;
80+ fExtraOpts = nullptr ;
8281}
8382
8483// _______________________________________________________________________
@@ -89,16 +88,9 @@ ScipyMinimizer::ScipyMinimizer(const char *type)
8988 fOptions .SetMinimizerAlgorithm (type);
9089 PyInitialize ();
9190 fHessianFunc = nullptr ;
92- // set extra options
93- SetAlgoExtraOptions ();
9491 fConstraintsList = PyList_New (0 );
9592 fConstN = 0 ;
96- }
97-
98- // _______________________________________________________________________
99- void ScipyMinimizer::SetAlgoExtraOptions ()
100- {
101- SetExtraOptions (fExtraOpts );
93+ fExtraOpts = nullptr ;
10294}
10395
10496// _______________________________________________________________________
@@ -191,6 +183,13 @@ ScipyMinimizer::~ScipyMinimizer()
191183 Py_DECREF (fBoundsMod );
192184}
193185
186+ // _______________________________________________________________________
187+ void ScipyMinimizer::SetExtraOptions ()
188+ {
189+ auto constExtraOpts = dynamic_cast <const GenAlgoOptions *>(fOptions .ExtraOptions ());
190+ fExtraOpts = const_cast <GenAlgoOptions *>(constExtraOpts);
191+ }
192+
194193// _______________________________________________________________________
195194bool ScipyMinimizer::Minimize ()
196195{
@@ -205,12 +204,23 @@ bool ScipyMinimizer::Minimize()
205204 }
206205 auto method = fOptions .MinimizerAlgorithm ();
207206 PyObject *pyoptions = PyDict_New ();
208- if (method == " L-BFGS-B" ) {
209- for (std::string key : fExtraOpts .GetAllRealKeys ()) {
207+ SetExtraOptions ();
208+ if (fExtraOpts ) {
209+ for (std::string key : fExtraOpts ->GetAllRealKeys ()) {
210210 double value = 0 ;
211- fExtraOpts . GetRealValue (key.c_str (), value);
211+ fExtraOpts -> GetRealValue (key.c_str (), value);
212212 PyDict_SetItemString (pyoptions, key.c_str (), PyFloat_FromDouble (value));
213213 }
214+ for (std::string key : fExtraOpts ->GetAllIntKeys ()) {
215+ int value = 0 ;
216+ fExtraOpts ->GetIntValue (key.c_str (), value);
217+ PyDict_SetItemString (pyoptions, key.c_str (), PyLong_FromLong (value));
218+ }
219+ for (std::string key : fExtraOpts ->GetAllNamedKeys ()) {
220+ std::string value = " " ;
221+ fExtraOpts ->GetNamedValue (key.c_str (), value);
222+ PyDict_SetItemString (pyoptions, key.c_str (), PyUnicode_FromString (value.c_str ()));
223+ }
214224 }
215225 PyDict_SetItemString (pyoptions, " maxiter" , PyLong_FromLong (MaxIterations ()));
216226 if (PrintLevel () > 0 ) {
0 commit comments