use core::fmt;
use crate::Real;
#[derive(Debug, Clone)]
pub enum CartanError {
CutLocus {
#[cfg(feature = "alloc")]
message: alloc::string::String,
#[cfg(not(feature = "alloc"))]
message: &'static str,
},
NumericalFailure {
#[cfg(feature = "alloc")]
operation: alloc::string::String,
#[cfg(feature = "alloc")]
message: alloc::string::String,
#[cfg(not(feature = "alloc"))]
operation: &'static str,
#[cfg(not(feature = "alloc"))]
message: &'static str,
},
NotOnManifold {
#[cfg(feature = "alloc")]
constraint: alloc::string::String,
#[cfg(not(feature = "alloc"))]
constraint: &'static str,
violation: Real,
},
NotInTangentSpace {
#[cfg(feature = "alloc")]
constraint: alloc::string::String,
#[cfg(not(feature = "alloc"))]
constraint: &'static str,
violation: Real,
},
LineSearchFailed { steps_tried: usize },
ConvergenceFailure {
iterations: usize,
gradient_norm: Real,
},
}
impl fmt::Display for CartanError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CartanError::CutLocus { message } => {
write!(f, "cut locus: {}", message)
}
CartanError::NumericalFailure { operation, message } => {
write!(f, "numerical failure in {}: {}", operation, message)
}
CartanError::NotOnManifold {
constraint,
violation,
} => {
write!(
f,
"point not on manifold: {} violated by {}",
constraint, violation
)
}
CartanError::NotInTangentSpace {
constraint,
violation,
} => {
write!(
f,
"tangent vector not in tangent space: {} violated by {}",
constraint, violation
)
}
CartanError::LineSearchFailed { steps_tried } => {
write!(f, "line search failed after {} steps", steps_tried)
}
CartanError::ConvergenceFailure {
iterations,
gradient_norm,
} => {
write!(
f,
"optimizer did not converge after {} iterations (gradient norm: {:.2e})",
iterations, gradient_norm
)
}
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for CartanError {}