1use noisy_float::types::N64;
3use std::error::Error;
4use std::fmt;
5
6#[derive(Clone, Debug, Eq, PartialEq)]
8pub struct EmptyInput;
9
10impl fmt::Display for EmptyInput {
11 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12 write!(f, "Empty input.")
13 }
14}
15
16impl Error for EmptyInput {}
17
18#[derive(Clone, Debug, Eq, PartialEq)]
20pub enum MinMaxError {
21 EmptyInput,
23 UndefinedOrder,
25}
26
27impl fmt::Display for MinMaxError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 MinMaxError::EmptyInput => write!(f, "Empty input."),
31 MinMaxError::UndefinedOrder => {
32 write!(f, "Undefined ordering between a tested pair of values.")
33 }
34 }
35 }
36}
37
38impl Error for MinMaxError {}
39
40impl From<EmptyInput> for MinMaxError {
41 fn from(_: EmptyInput) -> MinMaxError {
42 MinMaxError::EmptyInput
43 }
44}
45
46#[derive(Clone, Debug, PartialEq)]
50pub struct ShapeMismatch {
51 pub first_shape: Vec<usize>,
52 pub second_shape: Vec<usize>,
53}
54
55impl fmt::Display for ShapeMismatch {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 write!(
58 f,
59 "Array shapes do not match: {:?} and {:?}.",
60 self.first_shape, self.second_shape
61 )
62 }
63}
64
65impl Error for ShapeMismatch {}
66
67#[derive(Clone, Debug, PartialEq)]
69pub enum MultiInputError {
70 EmptyInput,
72 ShapeMismatch(ShapeMismatch),
74}
75
76impl MultiInputError {
77 pub fn is_empty_input(&self) -> bool {
79 match self {
80 MultiInputError::EmptyInput => true,
81 _ => false,
82 }
83 }
84
85 pub fn is_shape_mismatch(&self) -> bool {
87 match self {
88 MultiInputError::ShapeMismatch(_) => true,
89 _ => false,
90 }
91 }
92}
93
94impl fmt::Display for MultiInputError {
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96 match self {
97 MultiInputError::EmptyInput => write!(f, "Empty input."),
98 MultiInputError::ShapeMismatch(e) => write!(f, "Shape mismatch: {}", e),
99 }
100 }
101}
102
103impl Error for MultiInputError {}
104
105impl From<EmptyInput> for MultiInputError {
106 fn from(_: EmptyInput) -> Self {
107 MultiInputError::EmptyInput
108 }
109}
110
111impl From<ShapeMismatch> for MultiInputError {
112 fn from(err: ShapeMismatch) -> Self {
113 MultiInputError::ShapeMismatch(err)
114 }
115}
116
117#[derive(Debug, Clone, Eq, PartialEq)]
119pub enum QuantileError {
120 EmptyInput,
122 InvalidQuantile(N64),
124}
125
126impl fmt::Display for QuantileError {
127 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
128 match self {
129 QuantileError::EmptyInput => write!(f, "Empty input."),
130 QuantileError::InvalidQuantile(q) => {
131 write!(f, "{:} is not between 0. and 1. (inclusive).", q)
132 }
133 }
134 }
135}
136
137impl Error for QuantileError {}
138
139impl From<EmptyInput> for QuantileError {
140 fn from(_: EmptyInput) -> QuantileError {
141 QuantileError::EmptyInput
142 }
143}