@@ -51,6 +51,7 @@ def runTest(self):
5151 self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x0 ), 'Wrong xopt after initialisation' )
5252 self .assertTrue (array_compare (model .ropt (), rosenbrock (x0 )), 'Wrong ropt after initialisation' )
5353 self .assertAlmostEqual (model .objopt (), sumsq (rosenbrock (x0 )), 'Wrong fopt after initialisation' )
54+ self .assertTrue (array_compare (model .eval_num , np .array ([1 ,0 ,0 ], dtype = int )), 'Wrong eval_num after initialisation' )
5455 # Now add better point
5556 x1 = np .array ([1.0 , 0.9 ])
5657 rvec = rosenbrock (x1 )
@@ -59,6 +60,7 @@ def runTest(self):
5960 self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x1 ), 'Wrong xopt after x1' )
6061 self .assertTrue (array_compare (model .ropt (), rosenbrock (x1 )), 'Wrong ropt after x1' )
6162 self .assertAlmostEqual (model .objopt (), sumsq (rosenbrock (x1 )), 'Wrong fopt after x1' )
63+ self .assertTrue (array_compare (model .eval_num , np .array ([1 ,2 ,0 ], dtype = int )), 'Wrong eval_num after x1' )
6264 # Now add worse point
6365 x2 = np .array ([2.0 , 0.9 ])
6466 rvec = rosenbrock (x2 )
@@ -70,6 +72,7 @@ def runTest(self):
7072 self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x1 ), 'Wrong xopt after x2' )
7173 self .assertTrue (array_compare (model .ropt (), rosenbrock (x1 )), 'Wrong ropt after x2' )
7274 self .assertAlmostEqual (model .objopt (), sumsq (rosenbrock (x1 )), 'Wrong fopt after x2' )
75+ self .assertTrue (array_compare (model .eval_num , np .array ([1 ,2 ,3 ], dtype = int )), 'Wrong eval_num after x2' )
7376 # Now add best point (but don't update kopt)
7477 x3 = np .array ([1.0 , 1.0 ])
7578 rvec = rosenbrock (x3 )
@@ -80,6 +83,7 @@ def runTest(self):
8083 self .assertAlmostEqual (model .objopt (), sumsq (rosenbrock (x1 )), 'Wrong fopt after x3' )
8184 self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), model .as_absolute_coordinates (model .xopt ())),
8285 'Comparison wrong after x3' )
86+ self .assertTrue (array_compare (model .eval_num , np .array ([4 ,2 ,3 ], dtype = int )), 'Wrong eval_num after x3' )
8387 dirns = model .xpt_directions (include_kopt = True )
8488 self .assertTrue (array_compare (x3 - x1 , dirns [0 , :]), 'Wrong dirn 0' )
8589 self .assertTrue (array_compare (x1 - x1 , dirns [1 , :]), 'Wrong dirn 1' )
@@ -111,11 +115,13 @@ def runTest(self):
111115 self .assertTrue (array_compare (model .xpt (1 , abs_coordinates = True ), x1 ), 'Wrong xpt(1) after swap 1' )
112116 self .assertTrue (array_compare (model .xpt (2 , abs_coordinates = True ), x0 ), 'Wrong xpt(2) after swap 1' )
113117 self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x1 ), 'Wrong xopt after swap 1' )
118+ self .assertTrue (array_compare (model .eval_num , np .array ([3 ,2 ,1 ], dtype = int )), 'Wrong eval_num after swap 1' )
114119 model .swap_points (1 , 2 )
115120 self .assertTrue (array_compare (model .xpt (0 , abs_coordinates = True ), x2 ), 'Wrong xpt(0) after swap 2' )
116121 self .assertTrue (array_compare (model .xpt (1 , abs_coordinates = True ), x0 ), 'Wrong xpt(1) after swap 2' )
117122 self .assertTrue (array_compare (model .xpt (2 , abs_coordinates = True ), x1 ), 'Wrong xpt(2) after swap 2' )
118123 self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x1 ), 'Wrong xopt after swap 2' )
124+ self .assertTrue (array_compare (model .eval_num , np .array ([3 ,1 ,2 ], dtype = int )), 'Wrong eval_num after swap 2' )
119125
120126class TestBasicManipulation (unittest .TestCase ):
121127 def runTest (self ):
@@ -170,31 +176,43 @@ def runTest(self):
170176 self .assertIsNone (model .rsave , 'rsave not none after initialisation' )
171177 self .assertIsNone (model .objsave , 'fsave not none after initialisation' )
172178 self .assertIsNone (model .nsamples_save , 'nsamples_save not none after initialisation' )
179+ self .assertIsNone (model .eval_num_save , 'eval_num_save not none after initialisation' )
180+ self .assertIsNone (model .jacsave_eval_nums , 'jacsave_eval_nums not none after initialisation' )
173181 model .save_point (x0 , rosenbrock (x0 ), 1 , 6 , x_in_abs_coords = True )
174182 self .assertTrue (array_compare (model .xsave , x0 ), 'Wrong xsave after saving' )
175183 self .assertTrue (array_compare (model .rsave , rosenbrock (x0 )), 'Wrong rsave after saving' )
176184 self .assertAlmostEqual (model .objsave , sumsq (rosenbrock (x0 )), 'Wrong fsave after saving' )
177185 self .assertEqual (model .nsamples_save , 1 , 'Wrong nsamples_save after saving' )
186+ self .assertEqual (model .eval_num_save , 6 , 'Wrong eval_num_save after saving' )
187+ self .assertIsNone (model .jacsave_eval_nums , 'jacsave_eval_nums not none after saving' )
178188 x , rvec , f , jacmin , nsamples , x_eval_num , jacmin_eval_nums = model .get_final_results ()
179189 self .assertTrue (array_compare (x , x1 ), 'Wrong final x after saving' )
180190 self .assertTrue (array_compare (rvec , rosenbrock (x1 )), 'Wrong final rvec after saving' )
181191 self .assertAlmostEqual (sumsq (rosenbrock (x1 )), f , 'Wrong final f after saving' )
182192 self .assertEqual (1 , nsamples , 'Wrong final nsamples after saving' )
193+ self .assertEqual (x_eval_num , 5 , 'Wrong final x_eval_num after saving' )
194+ self .assertIsNone (jacmin_eval_nums , 'Final jacmin_eval_nums not none after saving' )
183195 model .save_point (x2 - model .xbase , np .array ([0.0 , 0.0 ]), 2 , 7 , x_in_abs_coords = False )
184196 self .assertTrue (array_compare (model .xsave , x2 ), 'Wrong xsave after saving 2' )
185197 self .assertTrue (array_compare (model .rsave , np .array ([0.0 , 0.0 ])), 'Wrong rsave after saving 2' )
186198 self .assertAlmostEqual (model .objsave , 0.0 , 'Wrong fsave after saving 2' )
187199 self .assertEqual (model .nsamples_save , 2 , 'Wrong nsamples_save after saving 2' )
200+ self .assertEqual (model .eval_num_save , 7 , 'Wrong eval_num_save after saving 2' )
201+ self .assertIsNone (model .jacsave_eval_nums , 'jacsave_eval_nums not none after saving 2' )
188202 x , rvec , f , jacmin , nsamples , x_eval_num , jacmin_eval_nums = model .get_final_results ()
189203 self .assertTrue (array_compare (x , x2 ), 'Wrong final x after saving 2' )
190204 self .assertTrue (array_compare (rvec , np .array ([0.0 , 0.0 ])), 'Wrong final rvec after saving 2' )
191205 self .assertAlmostEqual (f , 0.0 , 'Wrong final f after saving 2' )
192206 self .assertEqual (2 , nsamples , 'Wrong final nsamples after saving 2' )
207+ self .assertEqual (x_eval_num , 7 , 'Wrong final x_eval_num after saving 2' )
208+ self .assertIsNone (jacmin_eval_nums , 'Final jacmin_eval_nums not none after saving 2' )
193209 model .save_point (x0 , rosenbrock (x0 ), 3 , 8 , x_in_abs_coords = True ) # try to re-save a worse value
194210 self .assertTrue (array_compare (model .xsave , x2 ), 'Wrong xsave after saving 3' )
195211 self .assertTrue (array_compare (model .rsave , np .array ([0.0 , 0.0 ])), 'Wrong rsave after saving 3' )
196212 self .assertAlmostEqual (model .objsave , 0.0 , 'Wrong fsave after saving 3' )
197213 self .assertEqual (model .nsamples_save , 2 , 'Wrong nsamples_save after saving 3' )
214+ self .assertEqual (model .eval_num_save , 7 , 'Wrong eval_num_save after saving 2' )
215+ self .assertIsNone (model .jacsave_eval_nums , 'jacsave_eval_nums not none after saving 2' )
198216
199217
200218class TestAveraging (unittest .TestCase ):
0 commit comments