Struct Assignment
pub struct Assignment(/* private fields */);Expand description
The parameters of one trial: names to typed values.
Backed by a BTreeMap, so iteration is sorted by parameter name —
not a style preference but a determinism
requirement:
a sampler that walks an assignment, a
journal that serializes one, and a hash computed over one must all see the
same order on every machine and every run.
use atune_core::space::{Assignment, ParamValue};
let mut params = Assignment::new();
params.insert("lr", ParamValue::F64(0.01));
params.insert("batch", ParamValue::I64(64));
params.insert("amp", ParamValue::Bool(true));
let names: Vec<_> = params.iter().map(|(name, _)| name.as_str()).collect();
assert_eq!(names, ["amp", "batch", "lr"]); // sorted, always
assert_eq!(params.get("lr"), Some(&ParamValue::F64(0.01)));Implementations§
§impl Assignment
impl Assignment
pub fn new() -> Self
pub fn new() -> Self
An empty assignment.
pub fn get(&self, name: &str) -> Option<&ParamValue>
pub fn get(&self, name: &str) -> Option<&ParamValue>
The value bound to name, if any.
pub fn insert(
&mut self,
name: impl Into<String>,
value: ParamValue,
) -> Option<ParamValue>
pub fn insert( &mut self, name: impl Into<String>, value: ParamValue, ) -> Option<ParamValue>
Binds name to value, returning the previous binding if there was
one.
pub fn remove(&mut self, name: &str) -> Option<ParamValue>
pub fn remove(&mut self, name: &str) -> Option<ParamValue>
Removes name, returning its value if it was bound.
pub fn iter(&self) -> Iter<'_, String, ParamValue> ⓘ
pub fn iter(&self) -> Iter<'_, String, ParamValue> ⓘ
Iterates over (name, value) pairs, sorted by name.
pub fn names(&self) -> Keys<'_, String, ParamValue> ⓘ
pub fn names(&self) -> Keys<'_, String, ParamValue> ⓘ
Iterates over the names, sorted.
pub fn values(&self) -> Values<'_, String, ParamValue> ⓘ
pub fn values(&self) -> Values<'_, String, ParamValue> ⓘ
Iterates over the values, in name order.
pub fn merge_from(&mut self, other: &Self)
pub fn merge_from(&mut self, other: &Self)
Inserts every binding of other, overwriting on conflict.
Trait Implementations§
§impl Clone for Assignment
impl Clone for Assignment
§fn clone(&self) -> Assignment
fn clone(&self) -> Assignment
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more§impl Debug for Assignment
impl Debug for Assignment
§impl Default for Assignment
impl Default for Assignment
§fn default() -> Assignment
fn default() -> Assignment
Returns the “default value” for a type. Read more
§impl<'de> Deserialize<'de> for Assignment
impl<'de> Deserialize<'de> for Assignment
§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl<K> FromIterator<(K, ParamValue)> for Assignment
impl<K> FromIterator<(K, ParamValue)> for Assignment
§fn from_iter<I: IntoIterator<Item = (K, ParamValue)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (K, ParamValue)>>(iter: I) -> Self
Creates a value from an iterator. Read more
§impl<'a> IntoIterator for &'a Assignment
impl<'a> IntoIterator for &'a Assignment
§impl IntoIterator for Assignment
impl IntoIterator for Assignment
§impl PartialEq for Assignment
impl PartialEq for Assignment
§impl Serialize for Assignment
impl Serialize for Assignment
impl StructuralPartialEq for Assignment
Auto Trait Implementations§
impl Freeze for Assignment
impl RefUnwindSafe for Assignment
impl Send for Assignment
impl Sync for Assignment
impl Unpin for Assignment
impl UnsafeUnpin for Assignment
impl UnwindSafe for Assignment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more