Enum ParamValue
pub enum ParamValue {
F64(f64),
I64(i64),
Cat(u32),
Bool(bool),
}Expand description
One parameter’s value, typed.
This is the explicit fix for Optuna’s f64 union, in which a boolean and
the integer 1 are the same stored value and True == 1 collapses
categorical choices (the four kinds of
parameter). Here a
ParamValue::Bool never compares equal to a ParamValue::I64, and
round-tripping through storage cannot change a parameter’s type.
ParamValue::Cat holds an index into the owning distribution’s
CatChoices, not a label: labels live once, in the schema, so renaming a
choice does not rewrite history and comparisons stay cheap.
§Ordering
PartialEq is derived, so F64(f64::NAN) != F64(f64::NAN) exactly as for
f64. Eq and Ord are deliberately not implemented: they would have
to lie about NaN. Use ParamValue::total_cmp where a total order is
required (sorting, deduplication, grid enumeration); it orders by variant
first and uses f64::total_cmp within F64.
Variants§
F64(f64)
A floating-point value.
I64(i64)
An integer value.
Cat(u32)
A categorical choice, as an index into the distribution’s
CatChoices.
Bool(bool)
A boolean value.
Implementations§
§impl ParamValue
impl ParamValue
pub const fn as_f64(&self) -> Option<f64>
pub const fn as_f64(&self) -> Option<f64>
The payload if this is an F64, else None.
Deliberately not a lossy accessor: an I64 value does not answer
as_f64, because silent numeric erasure is what this type exists to
prevent. Use the transform layer
(Distribution::to_unit) when a
sampler wants numbers.
pub const fn is_finite(&self) -> bool
pub const fn is_finite(&self) -> bool
true if this is a float payload that is NaN or infinite.
Non-finite parameter values are never produced by atune; the check
exists so that values arriving from storage or user code can be
rejected at the boundary.
pub fn total_cmp(&self, other: &Self) -> Ordering
pub fn total_cmp(&self, other: &Self) -> Ordering
A total order over all values, NaN included.
Values of different kinds are ordered by kind
(F64 < I64 < Cat < Bool); within F64 the IEEE total order
(f64::total_cmp) is used, so -0.0 < 0.0 and NaN sorts to an end
rather than making comparisons non-transitive.
use atune_core::space::ParamValue;
let mut v = vec![
ParamValue::Bool(false),
ParamValue::F64(1.0),
ParamValue::F64(f64::NAN),
ParamValue::I64(-3),
];
v.sort_by(ParamValue::total_cmp);
assert_eq!(v[0], ParamValue::F64(1.0));
assert_eq!(v[2], ParamValue::I64(-3));
assert_eq!(v[3], ParamValue::Bool(false));Trait Implementations§
§impl Clone for ParamValue
impl Clone for ParamValue
§fn clone(&self) -> ParamValue
fn clone(&self) -> ParamValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more