Struct CatChoices
pub struct CatChoices { /* private fields */ }Expand description
The labels and typed scalar payloads of a categorical parameter, in a fixed order.
ParamValue::Cat stores an index into this list, so the list is part of
a study’s durable schema: choice sets may not change across the trials
of a study (see
Distribution::is_compatible_with),
because an index that meant "adam" yesterday must not mean "sgd" today.
Construction is fallible and rejects an empty list, duplicate labels,
non-finite float payloads, and lists longer than u32::MAX.
use atune_core::space::CatChoices;
let choices = CatChoices::new(["adam", "sgd"]).unwrap();
assert_eq!(choices.len(), 2);
assert_eq!(choices.label(1), Some("sgd"));
assert_eq!(choices.index_of("adam"), Some(0));
assert!(CatChoices::new(["a", "a"]).is_err());
assert!(CatChoices::new(Vec::<String>::new()).is_err());Implementations§
§impl CatChoices
impl CatChoices
pub fn new<I, S>(labels: I) -> Result<Self>
pub fn new<I, S>(labels: I) -> Result<Self>
Builds a choice set from labels.
§Errors
Error::InvalidSpace if the list is empty, contains duplicates, or
holds more than u32::MAX entries.
pub fn from_typed<I, S>(choices: I) -> Result<Self>
pub fn from_typed<I, S>(choices: I) -> Result<Self>
Builds a choice set from stable labels and exact scalar payloads.
This is the path language bindings use. CatChoices::new remains the
ordinary all-string path.
§Errors
Error::InvalidSpace if the list is empty, contains duplicate labels,
contains a non-finite float, or holds more than u32::MAX entries.
pub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Always false — a choice set cannot be empty by construction.
Present because len without is_empty is a lint, and because callers
writing generic code should not have to know the invariant.
pub fn label(&self, index: u32) -> Option<&str>
pub fn label(&self, index: u32) -> Option<&str>
The label at index, or None if the index is out of range.
pub fn value(&self, index: u32) -> Option<&CatChoiceValue>
pub fn value(&self, index: u32) -> Option<&CatChoiceValue>
The exact scalar payload at index, or None if out of range.
pub fn index_of(&self, label: &str) -> Option<u32>
pub fn index_of(&self, label: &str) -> Option<u32>
The index of label, or None if it is not a choice.
pub fn index_of_typed(&self, label: &str, value: &CatChoiceValue) -> Option<u32>
pub fn index_of_typed(&self, label: &str, value: &CatChoiceValue) -> Option<u32>
The index whose stable label and typed payload both match.
Language bindings use this for enqueue/readback paths so an integer 1
cannot be reinterpreted as the string choice "1" merely because their
labels coincide.
pub fn values(&self) -> &[CatChoiceValue]
pub fn values(&self) -> &[CatChoiceValue]
The exact scalar payloads, in label order.
Trait Implementations§
§impl Clone for CatChoices
impl Clone for CatChoices
§fn clone(&self) -> CatChoices
fn clone(&self) -> CatChoices
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more