Skip to main content

CatChoices

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

pub fn new<I, S>(labels: I) -> Result<Self>
where I: IntoIterator<Item = S>, S: Into<String>,

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>
where I: IntoIterator<Item = (S, CatChoiceValue)>, S: Into<String>,

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 fn len(&self) -> usize

The number of choices; never zero.

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>

The label at index, or None if the index is out of range.

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>

The index of label, or None if it is not a choice.

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 as_slice(&self) -> &[String]

The labels, in order.

pub fn values(&self) -> &[CatChoiceValue]

The exact scalar payloads, in label order.

pub fn iter(&self) -> Iter<'_, String> ⓘ

Iterates over the labels, in order.

pub fn count(&self) -> u32

The number of choices as a u32.

Cannot overflow: the constructor caps the length at u32::MAX.

Trait Implementations§

§

impl Clone for CatChoices

§

fn clone(&self) -> CatChoices

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for CatChoices

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for CatChoices

§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Eq for CatChoices

§

impl From<CatChoices> for Vec<String>

§

fn from(choices: CatChoices) -> Self

Converts to this type from the input type.
§

impl Hash for CatChoices

§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<'a> IntoIterator for &'a CatChoices

§

type Item = &'a String

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, String>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
§

impl PartialEq for CatChoices

§

fn eq(&self, other: &CatChoices) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl Serialize for CatChoices

§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl StructuralPartialEq for CatChoices

§

impl TryFrom<Vec<String>> for CatChoices

§

type Error = Error

The type returned in the event of a conversion error.
§

fn try_from(labels: Vec<String>) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more