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 #[error("Uniform distribution error: {source} at {location}")]
121 Uniform {
122 source: rand_distr::uniform::Error,
124 location: &'static Location<'static>,
126 },
127}
128
129impl From<BetaError> for TensorError {
130 #[track_caller]
131 fn from(source: BetaError) -> Self {
132 Self::Random(RandomError::Beta {
133 source,
134 location: Location::caller(),
135 })
136 }
137}
138
139impl From<NormalError> for TensorError {
140 #[track_caller]
141 fn from(source: NormalError) -> Self {
142 Self::Random(RandomError::Normal {
143 source,
144 location: Location::caller(),
145 })
146 }
147}
148
149impl From<ChiSquaredError> for TensorError {
150 #[track_caller]
151 fn from(source: ChiSquaredError) -> Self {
152 Self::Random(RandomError::ChiSquare {
153 source,
154 location: Location::caller(),
155 })
156 }
157}
158
159impl From<ExpError> for TensorError {
160 #[track_caller]
161 fn from(source: ExpError) -> Self {
162 Self::Random(RandomError::Exp {
163 source,
164 location: Location::caller(),
165 })
166 }
167}
168
169impl From<GammaError> for TensorError {
170 #[track_caller]
171 fn from(source: GammaError) -> Self {
172 Self::Random(RandomError::Gamma {
173 source,
174 location: Location::caller(),
175 })
176 }
177}
178
179impl From<GumbelError> for TensorError {
180 #[track_caller]
181 fn from(source: GumbelError) -> Self {
182 Self::Random(RandomError::Gumbel {
183 source,
184 location: Location::caller(),
185 })
186 }
187}
188
189impl From<NormalInverseGaussianError> for TensorError {
190 #[track_caller]
191 fn from(source: NormalInverseGaussianError) -> Self {
192 Self::Random(RandomError::NormalInverseGaussian {
193 source,
194 location: Location::caller(),
195 })
196 }
197}
198
199impl From<ParetoError> for TensorError {
200 #[track_caller]
201 fn from(source: ParetoError) -> Self {
202 Self::Random(RandomError::Pareto {
203 source,
204 location: Location::caller(),
205 })
206 }
207}
208
209impl From<PoissonError> for TensorError {
210 #[track_caller]
211 fn from(source: PoissonError) -> Self {
212 Self::Random(RandomError::Poisson {
213 source,
214 location: Location::caller(),
215 })
216 }
217}
218
219impl From<WeibullError> for TensorError {
220 #[track_caller]
221 fn from(source: WeibullError) -> Self {
222 Self::Random(RandomError::Weibull {
223 source,
224 location: Location::caller(),
225 })
226 }
227}
228
229impl From<ZipfError> for TensorError {
230 #[track_caller]
231 fn from(source: ZipfError) -> Self {
232 Self::Random(RandomError::Zipf {
233 source,
234 location: Location::caller(),
235 })
236 }
237}
238
239impl From<TriangularError> for TensorError {
240 #[track_caller]
241 fn from(source: TriangularError) -> Self {
242 Self::Random(RandomError::Triangular {
243 source,
244 location: Location::caller(),
245 })
246 }
247}
248
249impl From<BernoulliError> for TensorError {
250 #[track_caller]
251 fn from(source: BernoulliError) -> Self {
252 Self::Random(RandomError::Bernoulli {
253 source,
254 location: Location::caller(),
255 })
256 }
257}
258
259impl From<rand_distr::uniform::Error> for TensorError {
260 #[track_caller]
261 fn from(source: rand_distr::uniform::Error) -> Self {
262 Self::Random(RandomError::Uniform {
263 source,
264 location: Location::caller(),
265 })
266 }
267}