use std::fmt;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Error {
ZeroK,
BadBox,
Empty,
BufferSize,
Overflow,
MaskLen,
TooManyCells,
BadCutoff,
TooManyImages,
Partial,
Device,
Padded,
NonFinite,
BadPartition,
BadGraph,
NoDevice,
DeviceMismatch,
ScotchDisabled,
ScotchFailed,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::ZeroK => write!(f, "k must be at least 1"),
Error::BadBox => write!(f, "singular or non-positive cell"),
Error::Empty => write!(f, "no points"),
Error::BufferSize => write!(f, "out buffer length must be n * k"),
Error::Overflow => write!(f, "n * k overflows"),
Error::MaskLen => write!(f, "mask length must be n"),
Error::TooManyCells => write!(f, "linked-cell mesh is too fine"),
Error::BadCutoff => write!(f, "cutoff must be finite and positive"),
Error::TooManyImages => write!(f, "periodic image count exceeds 2^24"),
Error::Partial => write!(
f,
"partial periodicity needs libvesin.so on the loader path"
),
Error::Device => write!(f, "this device needs libvesin.so on the loader path"),
Error::Padded => write!(f, "a point has more neighbours than padded_to"),
Error::NonFinite => write!(f, "a coordinate is not finite"),
Error::BadPartition => {
write!(f, "part count must be positive and balance at least 1")
}
Error::BadGraph => write!(f, "cell graph is not a square CSR"),
Error::NoDevice => write!(f, "CUDA curve split is not available"),
Error::DeviceMismatch => {
write!(f, "device curve split disagreed with the host weights")
}
Error::ScotchDisabled => write!(f, "Scotch support is compiled out"),
Error::ScotchFailed => write!(f, "Scotch returned an error"),
}
}
}
impl std::error::Error for Error {}
impl From<minimage::Error> for Error {
fn from(err: minimage::Error) -> Self {
match err {
minimage::Error::BadBox => Error::BadBox,
minimage::Error::BufferSize => Error::BufferSize,
minimage::Error::Empty => Error::Empty,
}
}
}