1
1
use crate :: cobyla:: cobyla_context_t;
2
2
/// Implementation of `argmin::IterState` for Cobyla optimizer
3
3
use argmin:: core:: { Problem , State , TerminationReason , TerminationStatus } ;
4
+ #[ cfg( feature = "serde1" ) ]
4
5
use serde:: { Deserialize , Serialize } ;
5
6
use std:: collections:: HashMap ;
6
7
use std:: mem:: ManuallyDrop ;
@@ -24,7 +25,8 @@ use std::mem::ManuallyDrop;
24
25
/// * termination status
25
26
/// * COBYLA specific parameters: rhobeg, rhoend, iprint, maxfun
26
27
///
27
- #[ derive( Clone , Debug , Default , Serialize , Deserialize ) ]
28
+ #[ derive( Clone , Debug , Default ) ]
29
+ #[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
28
30
pub struct CobylaState {
29
31
/// Current parameter vector
30
32
pub param : Option < Vec < f64 > > ,
@@ -68,7 +70,7 @@ pub struct CobylaState {
68
70
/// Cost function calls budget
69
71
pub maxfun : i32 ,
70
72
71
- #[ serde( skip) ]
73
+ #[ cfg_attr ( feature = "serde1" , serde( skip) ) ]
72
74
pub cobyla_context : Option < ManuallyDrop < * mut cobyla_context_t > > ,
73
75
}
74
76
83
85
///
84
86
/// ```
85
87
/// # use argmin::core::{IterState, State};
86
- /// # let state: IterState<Vec<f64>, (), (), (), f64> = IterState::new();
88
+ /// # let state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
87
89
/// # let param_old = vec![1.0f64, 2.0f64];
88
90
/// # let state = state.param(param_old);
89
91
/// # assert!(state.prev_param.is_none());
@@ -529,7 +531,7 @@ impl State for CobylaState {
529
531
///
530
532
/// ```
531
533
/// # use argmin::core::{IterState, State, ArgminFloat, TerminationStatus};
532
- /// # let mut state: IterState<Vec<f64>, (), (), (), f64> = IterState::new();
534
+ /// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
533
535
/// let termination_status = state.get_termination_status();
534
536
/// # assert_eq!(*termination_status, TerminationStatus::NotTerminated);
535
537
/// ```
@@ -543,7 +545,7 @@ impl State for CobylaState {
543
545
///
544
546
/// ```
545
547
/// # use argmin::core::{IterState, State, ArgminFloat, TerminationReason};
546
- /// # let mut state: IterState<Vec<f64>, (), (), (), f64> = IterState::new();
548
+ /// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
547
549
/// let termination_reason = state.get_termination_reason();
548
550
/// # assert_eq!(termination_reason, None);
549
551
/// ```
0 commit comments