#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ContractMismatch {
feature: &'static str,
expected: String,
actual: String,
}
impl ContractMismatch {
#[inline(always)]
pub const fn new(feature: &'static str, expected: String, actual: String) -> Self {
Self {
feature,
expected,
actual,
}
}
#[inline(always)]
pub const fn feature(&self) -> &'static str {
self.feature
}
#[inline(always)]
pub fn expected(&self) -> &str {
&self.expected
}
#[inline(always)]
pub fn actual(&self) -> &str {
&self.actual
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum ModelError {
#[error("failed to load model: {0}")]
Load(#[from] crate::LoadError),
#[error(
"model contract mismatch on `{}`: expected {}, got {}",
.0.feature(),
.0.expected(),
.0.actual()
)]
ContractMismatch(ContractMismatch),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChunkTooLong {
got: usize,
max: usize,
}
impl ChunkTooLong {
#[inline(always)]
pub const fn new(got: usize, max: usize) -> Self {
Self { got, max }
}
#[inline(always)]
pub const fn got(&self) -> usize {
self.got
}
#[inline(always)]
pub const fn max(&self) -> usize {
self.max
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OutputShape {
feature: &'static str,
got: Vec<usize>,
expected: Vec<usize>,
}
impl OutputShape {
#[inline(always)]
pub const fn new(feature: &'static str, got: Vec<usize>, expected: Vec<usize>) -> Self {
Self {
feature,
got,
expected,
}
}
#[inline(always)]
pub const fn feature(&self) -> &'static str {
self.feature
}
#[inline(always)]
pub fn got(&self) -> &[usize] {
&self.got
}
#[inline(always)]
pub fn expected(&self) -> &[usize] {
&self.expected
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NonFiniteOutput {
feature: &'static str,
index: usize,
}
impl NonFiniteOutput {
#[inline(always)]
pub const fn new(feature: &'static str, index: usize) -> Self {
Self { feature, index }
}
#[inline(always)]
pub const fn feature(&self) -> &'static str {
self.feature
}
#[inline(always)]
pub const fn index(&self) -> usize {
self.index
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum InferError {
#[error("prediction failed: {0}")]
Prediction(#[from] crate::PredictionError),
#[error("tensor failed: {0}")]
Tensor(#[from] crate::TensorError),
#[error("chunk length {} exceeds one model chunk ({})", .0.got(), .0.max())]
ChunkTooLong(ChunkTooLong),
#[error("input contains a non-finite value at index {0}")]
NonFiniteInput(usize),
#[error(
"output `{}` shape mismatch: expected {:?}, got {:?}",
.0.feature(),
.0.expected(),
.0.got()
)]
OutputShape(OutputShape),
#[error(
"output `{}` contains a non-finite value at index {}",
.0.feature(),
.0.index()
)]
NonFiniteOutput(NonFiniteOutput),
}
#[cfg(test)]
mod tests;