Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
add StepArg::from_splice
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Aug 17, 2024
1 parent 6934722 commit 5964107
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod svob;
mod toktree;

pub use svob::{SimpleVob, SimpleVobIter};
pub use toktree::{Recognizer, SpecialToken, TokRxInfo, TokTrie, TokenId, TokenizerEnv, TokEnv};
pub use toktree::{Recognizer, SpecialToken, TokEnv, TokRxInfo, TokTrie, TokenId, TokenizerEnv};

/// Defines what is allowed in Branch
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
Expand All @@ -23,13 +23,12 @@ pub struct InferenceCapabilities {
/// Backtracking is allowed.
#[serde(default)]
pub backtrack: bool,

/// More than one branch is allowed.
#[serde(default)]
pub fork: bool,
}


#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct StepArg {
/// Sampling result for the previous iteration.
Expand Down Expand Up @@ -60,6 +59,14 @@ impl StepArg {
acc_tokens.truncate(acc_tokens.len() - bt);
acc_tokens.extend_from_slice(&self.tokens);
}

pub fn from_splice(s: &Splice, sampled: Option<TokenId>) -> Self {
StepArg {
backtrack: s.backtrack,
tokens: s.ff_tokens.clone(),
sampled,
}
}
}

/*
Expand Down Expand Up @@ -137,13 +144,13 @@ impl<S> Branch<S> {
}

pub fn spliced(&self, sampled: TokenId) -> Splice {
self.find_splice(sampled).cloned().unwrap_or_else(|| {
Splice {
self.find_splice(sampled)
.cloned()
.unwrap_or_else(|| Splice {
when_sampled: vec![],
backtrack: 0,
ff_tokens: vec![sampled],
}
})
})
}

pub fn unconditional_splice(&self) -> Option<&Splice> {
Expand Down

0 comments on commit 5964107

Please sign in to comment.