hpt_common/error/
random.rs1use std::panic::Location;
2
3use rand_distr::{
4 BernoulliError, BetaError, ChiSquaredError, ExpError, GammaError, GumbelError, NormalError,
5 NormalInverseGaussianError, ParetoError, PoissonError, TriangularError, WeibullError,
6 ZipfError,
7};
8use thiserror::Error;
9
10use super::base::TensorError;
11
12#[derive(Debug, Error)]
14pub enum RandomError {
15 #[error("Beta distribution error: {source} at {location}")]
17 Beta {
18 source: BetaError,
20 location: &'static Location<'static>,
22 },
23 #[error("Normal distribution error: {source} at {location}")]
25 Normal {
26 source: NormalError,
28 location: &'static Location<'static>,
30 },
31 #[error("Chi-square distribution error: {source} at {location}")]
33 ChiSquare {
34 source: ChiSquaredError,
36 location: &'static Location<'static>,
38 },
39 #[error("Exponential distribution error: {source} at {location}")]
41 Exp {
42 source: ExpError,
44 location: &'static Location<'static>,
46 },
47 #[error("Gamma distribution error: {source} at {location}")]
49 Gamma {
50 source: GammaError,
52 location: &'static Location<'static>,
54 },
55 #[error("Gumbel distribution error: {source} at {location}")]
57 Gumbel {
58 source: GumbelError,
60 location: &'static Location<'static>,
62 },
63 #[error("Inverse Gaussian distribution error: {source} at {location}")]
65 NormalInverseGaussian {
66 source: NormalInverseGaussianError,
68 location: &'static Location<'static>,
70 },
71 #[error("Pareto distribution error: {source} at {location}")]
73 Pareto {
74 source: ParetoError,
76 location: &'static Location<'static>,
78 },
79 #[error("Poisson distribution error: {source} at {location}")]
81 Poisson {
82 source: PoissonError,
84 location: &'static Location<'static>,
86 },
87 #[error("Weibull distribution error: {source} at {location}")]
89 Weibull {
90 source: WeibullError,
92 location: &'static Location<'static>,
94 },
95 #[error("Zipf distribution error: {source} at {location}")]
97 Zipf {
98 source: ZipfError,
100 location: &'static Location<'static>,
102 },
103 #[error("Triangular distribution error: {source} at {location}")]
105 Triangular {
106 source: TriangularError,
108 location: &'static Location<'static>,
110 },
111 #[error("Bernoulli distribution error: {source} at {location}")]
113 Bernoulli {
114 source: BernoulliError,
116 location: &'static Location<'static>,
118 },
119}
120
121impl From<BetaError> for TensorError {
122 #[track_caller]
123 fn from(source: BetaError) -> Self {
124 Self::Random(RandomError::Beta {
125 source,
126 location: Location::caller(),
127 })
128 }
129}
130
131impl From<NormalError> for TensorError {
132 #[track_caller]
133 fn from(source: NormalError) -> Self {
134 Self::Random(RandomError::Normal {
135 source,
136 location: Location::caller(),
137 })
138 }
139}
140
141impl From<ChiSquaredError> for TensorError {
142 #[track_caller]
143 fn from(source: ChiSquaredError) -> Self {
144 Self::Random(RandomError::ChiSquare {
145 source,
146 location: Location::caller(),
147 })
148 }
149}
150
151impl From<ExpError> for TensorError {
152 #[track_caller]
153 fn from(source: ExpError) -> Self {
154 Self::Random(RandomError::Exp {
155 source,
156 location: Location::caller(),
157 })
158 }
159}
160
161impl From<GammaError> for TensorError {
162 #[track_caller]
163 fn from(source: GammaError) -> Self {
164 Self::Random(RandomError::Gamma {
165 source,
166 location: Location::caller(),
167 })
168 }
169}
170
171impl From<GumbelError> for TensorError {
172 #[track_caller]
173 fn from(source: GumbelError) -> Self {
174 Self::Random(RandomError::Gumbel {
175 source,
176 location: Location::caller(),
177 })
178 }
179}
180
181impl From<NormalInverseGaussianError> for TensorError {
182 #[track_caller]
183 fn from(source: NormalInverseGaussianError) -> Self {
184 Self::Random(RandomError::NormalInverseGaussian {
185 source,
186 location: Location::caller(),
187 })
188 }
189}
190
191impl From<ParetoError> for TensorError {
192 #[track_caller]
193 fn from(source: ParetoError) -> Self {
194 Self::Random(RandomError::Pareto {
195 source,
196 location: Location::caller(),
197 })
198 }
199}
200
201impl From<PoissonError> for TensorError {
202 #[track_caller]
203 fn from(source: PoissonError) -> Self {
204 Self::Random(RandomError::Poisson {
205 source,
206 location: Location::caller(),
207 })
208 }
209}
210
211impl From<WeibullError> for TensorError {
212 #[track_caller]
213 fn from(source: WeibullError) -> Self {
214 Self::Random(RandomError::Weibull {
215 source,
216 location: Location::caller(),
217 })
218 }
219}
220
221impl From<ZipfError> for TensorError {
222 #[track_caller]
223 fn from(source: ZipfError) -> Self {
224 Self::Random(RandomError::Zipf {
225 source,
226 location: Location::caller(),
227 })
228 }
229}
230
231impl From<TriangularError> for TensorError {
232 #[track_caller]
233 fn from(source: TriangularError) -> Self {
234 Self::Random(RandomError::Triangular {
235 source,
236 location: Location::caller(),
237 })
238 }
239}
240
241impl From<BernoulliError> for TensorError {
242 #[track_caller]
243 fn from(source: BernoulliError) -> Self {
244 Self::Random(RandomError::Bernoulli {
245 source,
246 location: Location::caller(),
247 })
248 }
249}