ffsvm/
errors.rs

1use std::num::{ParseFloatError, ParseIntError};
2
3/// Possible error types when classifying with one of the SVMs.
4#[derive(Debug)]
5pub enum Error {
6    /// This can be emitted when creating an SVM from a [`ModelFile`](crate::ModelFile). For models generated by
7    /// libSVM's `svm-train`, the most common reason this occurs is skipping attributes.
8    /// All attributes must be in sequential order 0, 1, 2, ..., n. If they are not, this
9    /// error will be emitted. For more details see the documentation provided in [`ModelFile`](crate::ModelFile).
10    AttributesUnordered {
11        /// The index process that was not a direct successor of the previous index. Can be used for
12        /// easier debugging the model file.
13        index: u32,
14
15        /// The value of the given index. Can be used for debugging in conjunction with `index`.
16        value: f32,
17
18        /// The last index processed. If everything were alright, then `index` should equal
19        /// `last_index + 1`.
20        last_index: u32,
21    },
22
23    /// This error can be emitted by [`Predict::predict_probability`](crate::Predict::predict_probability) in case the model loaded by
24    ///  [`ModelFile`](crate::ModelFile) was not trained with probability estimates (`svm-train -b 1`).
25    NoProbabilities,
26
27    /// Can be emitted by [`Predict::predict_probability`](crate::Predict::predict_probability) when predicting probabilities
28    /// and the internal iteration limit was exceeded.
29    IterationsExceeded,
30
31    /// If the model does not have a `gamma` set this error may be raised.
32    NoGamma,
33
34    /// If the model does not have a `coef0` set this error may be raised.
35    NoCoef0,
36
37    /// If the model does not have a `degree` set this error may be raised.
38    NoDegree,
39
40    /// Wrapper for internal parsing error when unifiying error handling.
41    Parsing(String),
42
43    /// A required attribute was not found.
44    MissingRequiredAttribute,
45}
46
47// impl<'a, T> From<Error<'a, T>> for Error {
48//     fn from(_: Error<'a, T>) -> Self {
49//         Error::ParsingError
50//     }
51// }
52
53impl From<ParseFloatError> for Error {
54    fn from(_e: ParseFloatError) -> Self {
55        Self::Parsing("ParseFloatError".to_owned())
56    }
57}
58
59impl From<ParseIntError> for Error {
60    fn from(_: ParseIntError) -> Self {
61        Self::Parsing("ParseIntError".to_owned())
62    }
63}