@@ -82,6 +82,8 @@ pub struct IterState<P, G, J, H, R, F> {
82
82
pub max_iters : u64 ,
83
83
/// Evaluation counts
84
84
pub counts : HashMap < String , u64 > ,
85
+ /// Update evaluation counts?
86
+ pub counting_enabled : bool ,
85
87
/// Time required so far
86
88
pub time : Option < instant:: Duration > ,
87
89
/// Status of optimization execution
@@ -1040,6 +1042,7 @@ where
1040
1042
last_best_iter : 0 ,
1041
1043
max_iters : std:: u64:: MAX ,
1042
1044
counts : HashMap :: new ( ) ,
1045
+ counting_enabled : false ,
1043
1046
time : Some ( instant:: Duration :: new ( 0 , 0 ) ) ,
1044
1047
termination_status : TerminationStatus :: NotTerminated ,
1045
1048
}
@@ -1339,7 +1342,7 @@ where
1339
1342
/// ```
1340
1343
/// # use std::collections::HashMap;
1341
1344
/// # use argmin::core::{Problem, IterState, State, ArgminFloat};
1342
- /// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
1345
+ /// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new().set_counting(true) ;
1343
1346
/// # assert_eq!(state.counts, HashMap::new());
1344
1347
/// # state.counts.insert("test2".to_string(), 10u64);
1345
1348
/// #
@@ -1356,9 +1359,11 @@ where
1356
1359
/// # assert_eq!(state.counts, hm);
1357
1360
/// ```
1358
1361
fn func_counts < O > ( & mut self , problem : & Problem < O > ) {
1359
- for ( k, & v) in problem. counts . iter ( ) {
1360
- let count = self . counts . entry ( k. to_string ( ) ) . or_insert ( 0 ) ;
1361
- * count = v
1362
+ if self . counting_enabled {
1363
+ for ( k, & v) in problem. counts . iter ( ) {
1364
+ let count = self . counts . entry ( k. to_string ( ) ) . or_insert ( 0 ) ;
1365
+ * count = v
1366
+ }
1362
1367
}
1363
1368
}
1364
1369
@@ -1401,6 +1406,13 @@ where
1401
1406
fn is_best ( & self ) -> bool {
1402
1407
self . last_best_iter == self . iter
1403
1408
}
1409
+
1410
+ /// Overrides state of counting function executions, by default - only if needed
1411
+ #[ must_use]
1412
+ fn set_counting ( mut self , mode : bool ) -> Self {
1413
+ self . counting_enabled = mode;
1414
+ self
1415
+ }
1404
1416
}
1405
1417
1406
1418
#[ cfg( test) ]
0 commit comments