use std::ffi::NulError;
use std::path::PathBuf;
use thiserror::Error;
use crate::ffi::{TfLiteStatus, TfLiteType};
#[derive(Debug, Error)]
pub enum Error {
#[error("could not load TensorFlow Lite shared library (tried {paths:?})")]
LoadFailed {
#[source]
source: libloading::Error,
paths: Vec<String>,
},
#[error("symbol `{name}` not found in TensorFlow Lite shared library")]
SymbolNotFound {
name: &'static str,
#[source]
source: libloading::Error,
},
#[error("failed to load model from {path:?}")]
ModelLoadFailed {
path: PathBuf,
},
#[error("path could not be passed to the C API: {0}")]
InvalidPath(#[source] NulError),
#[error("delegate option key or value contained an embedded NUL byte: {0}")]
InvalidOption(#[source] NulError),
#[error("failed to create TensorFlow Lite interpreter")]
InterpreterCreateFailed,
#[error("interpreter failed to allocate tensors")]
AllocateTensorsFailed,
#[error("interpreter invocation failed with status {status:?}")]
InvokeFailed {
status: TfLiteStatus,
},
#[error("tensor index {index} out of bounds (count is {count})")]
TensorIndexOutOfBounds {
index: usize,
count: usize,
},
#[error("tensor dtype mismatch: expected {expected:?}, got {actual:?}")]
DtypeMismatch {
expected: TfLiteType,
actual: TfLiteType,
},
#[error("tensor handle was NULL")]
NullTensor,
#[error("tensor data pointer was NULL")]
NullData,
#[error("failed to create external delegate")]
DelegateCreateFailed,
#[error("setting external delegate option failed with status {status:?}")]
DelegateOptionRejected {
status: TfLiteStatus,
},
#[error("loaded TFLite library does not export the TfLiteExternalDelegate* symbol group")]
ExternalDelegateApiUnavailable,
}
pub type Result<T> = std::result::Result<T, Error>;