forked from rust-ml/linfa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.rs
More file actions
36 lines (31 loc) · 1.07 KB
/
errors.rs
File metadata and controls
36 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use ndarray_linalg::error::LinalgError;
use std::error::Error;
use std::fmt::{self, Display};
pub type Result<T> = std::result::Result<T, PlsError>;
#[derive(Debug)]
pub enum PlsError {
NotEnoughSamplesError(String),
BadComponentNumberError(String),
PowerMethodNotConvergedError(String),
LinalgError(String),
}
impl Display for PlsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::NotEnoughSamplesError(message) => write!(f, "Not enough samples: {}", message),
Self::BadComponentNumberError(message) => {
write!(f, "Bad component number: {}", message)
}
Self::PowerMethodNotConvergedError(message) => {
write!(f, "Power method not converged: {}", message)
}
Self::LinalgError(message) => write!(f, "Linear algebra error: {}", message),
}
}
}
impl Error for PlsError {}
impl From<LinalgError> for PlsError {
fn from(error: LinalgError) -> PlsError {
PlsError::LinalgError(error.to_string())
}
}