pub struct Bitmask { /* private fields */ }Expand description
A dense allowed-token bitmask over vocab_size tokens, packed into little-endian u32 words.
Implementations§
Source§impl Bitmask
impl Bitmask
Sourcepub fn zeros(vocab_size: usize) -> Self
pub fn zeros(vocab_size: usize) -> Self
Allocates an all-zero mask sized for vocab_size tokens (ceil(vocab_size/32) words).
Sourcepub fn from_words(words: &[u32], vocab_size: usize) -> Self
pub fn from_words(words: &[u32], vocab_size: usize) -> Self
Builds a mask from packed words, clearing unused high bits.
Sourcepub fn set(&mut self, id: TokenId) -> Result<(), CompileError>
pub fn set(&mut self, id: TokenId) -> Result<(), CompileError>
Sets the bit for id. Fails (never truncates) when id is outside 0..vocab_size.
Sourcepub fn get(&self, id: TokenId) -> bool
pub fn get(&self, id: TokenId) -> bool
Returns whether the bit for id is set (false for out-of-range ids).
Sourcepub fn as_words(&self) -> &[u32]
pub fn as_words(&self) -> &[u32]
The packed words (the wire format): ceil(vocab_size/32) little-endian u32s.
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
The number of tokens this mask covers.
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Returns the number of set token bits.
Trait Implementations§
impl Eq for Bitmask
impl StructuralPartialEq for Bitmask
Auto Trait Implementations§
impl Freeze for Bitmask
impl RefUnwindSafe for Bitmask
impl Send for Bitmask
impl Sync for Bitmask
impl Unpin for Bitmask
impl UnsafeUnpin for Bitmask
impl UnwindSafe for Bitmask
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