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
//! Error types in Linfa
//!

use thiserror::Error;

use ndarray::ShapeError;
#[cfg(feature = "serde")]
use serde_crate::{Deserialize, Serialize};

pub type Result<T> = std::result::Result<T, Error>;

#[cfg_attr(
    feature = "serde",
    derive(Serialize, Deserialize),
    serde(crate = "serde_crate")
)]
#[derive(Error, Debug, Clone)]
pub enum Error {
    #[error("invalid parameter {0}")]
    Parameters(String),
    #[error("invalid prior {0}")]
    Priors(String),
    #[error("algorithm not converged {0}")]
    NotConverged(String),
    // ShapeError doesn't implement serde traits, and deriving them remotely on a complex error
    // type isn't really feasible, so we skip this variant.
    #[cfg_attr(feature = "serde", serde(skip))]
    #[error("invalid ndarray shape {0}")]
    NdShape(#[from] ShapeError),
    #[error("not enough samples")]
    NotEnoughSamples,
    #[error("The number of samples do not match: {0} - {1}")]
    MismatchedShapes(usize, usize),
}