Skip to content

Commit

Permalink
Refine serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlovinger committed Sep 24, 2023
1 parent e5956e7 commit a0bafc5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions optimal-pbil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct Config {
/// PBIL state.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct State<B>(DynState<B>);

/// PBIL state kind.
Expand Down
2 changes: 2 additions & 0 deletions optimal-pbil/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ impl Ord for Probability {
/// or below the inverse.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(into = "Probability"))]
#[cfg_attr(feature = "serde", serde(try_from = "Probability"))]
pub struct ProbabilityThreshold {
ub: Probability,
lb: Probability,
Expand Down
1 change: 1 addition & 0 deletions optimal-steepest/src/backtracking_steepest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub struct Config<A> {
/// Backtracking steepest descent state.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct State<A>(DynState<A>);

/// Backtracking steepest descent state kind.
Expand Down
10 changes: 10 additions & 0 deletions optimal-steepest/src/backtracking_steepest/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ pub use optimal_core::prelude::*;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

// `#[serde(into = "A")]` and `#[serde(try_from = "A")]` makes more sense
// than `#[serde(transparent)]`,
// but as of 2023-09-24,
// but we cannot `impl<A> From<Foo<A>> for A`
// and manually implementing `Serialize` and `Deserialize`
// is not worth the effort.

/// The sufficient decrease parameter,
/// `c_1`.
#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct SufficientDecreaseParameter<A>(A);

derive_new_from_bounded_partial_ord!(SufficientDecreaseParameter<A: Real>);
Expand Down Expand Up @@ -58,6 +66,7 @@ where
/// Rate to decrease step size while line searching.
#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct BacktrackingRate<A>(A);

derive_new_from_bounded_partial_ord!(BacktrackingRate<A: Real>);
Expand Down Expand Up @@ -94,6 +103,7 @@ where
/// Rate to increase step size before starting each line search.
#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct IncrRate<A>(A);

derive_new_from_lower_bounded_partial_ord!(IncrRate<A: Real>);
Expand Down
1 change: 1 addition & 0 deletions optimal-steepest/src/fixed_step_steepest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct Config<A> {
/// Fixed-step-size steepest descent state.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct State<A>(DynState<A>);

/// Fixed-step-size steepest descent state kind.
Expand Down

0 comments on commit a0bafc5

Please sign in to comment.