1use thiserror::Error;
2
3pub type Result<T> = ::std::result::Result<T, Error>;
4
5#[derive(Error, Debug)]
6pub enum Error {
7 #[error(
8 "Invalid value for LAPACK subroutine {}-th argument",
9 -return_code
10 )]
11 LapackInvalidValue { return_code: i32 },
12
13 #[error(
14 "Computational failure in LAPACK subroutine: return_code = {}",
15 return_code
16 )]
17 LapackComputationalFailure { return_code: i32 },
18
19 #[error("Invalid shape")]
21 InvalidShape,
22}
23
24pub trait AsLapackResult {
25 fn as_lapack_result(self) -> Result<()>;
26}
27
28impl AsLapackResult for i32 {
29 fn as_lapack_result(self) -> Result<()> {
30 if self > 0 {
31 return Err(Error::LapackComputationalFailure { return_code: self });
32 }
33 if self < 0 {
34 return Err(Error::LapackInvalidValue { return_code: self });
35 }
36 Ok(())
37 }
38}