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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#![doc="Defines errors related to SciRust library
"]
use std::fmt;
#[derive(Debug, Copy, Clone)]
pub enum SRError{
EmptyMatrix,
DimensionsMismatch,
RowsMismatch,
ColsMismatch,
IsNotSquareMatrix,
IsNotAVector,
IsNotAColVector,
IsNotARowVector,
IsNotFullRankMatrix,
IsFullRankMatrix,
IsSingular,
IsNonSingular,
IsPositiveDefinite,
IsPositiveSemiDefinite,
IsNegativeDefinite,
IsNegativeSemiDefinite,
IsNonDefinite,
LRDimensionMismatch,
NoSolution,
InfiniteSolutions,
DivideByZero,
IsNotPowerOfTwo,
}
pub type SRResult<T> = Result<T, SRError>;
impl SRError{
pub fn to_string(&self) -> String {
match *self{
SRError::EmptyMatrix => format!("Matrix is empty"),
SRError::DimensionsMismatch => format!("Dimensions don't match"),
SRError::RowsMismatch => format!("Number of rows don't match"),
SRError::ColsMismatch => format!("Number of columns don't match"),
SRError::IsNotSquareMatrix => format!("Matrix is not square"),
SRError::IsNotAVector => format!("Matrix is not a vector"),
SRError::IsNotAColVector => format!("Matrix is not a column vector"),
SRError::IsNotARowVector => format!("Matrix is not a row vector"),
SRError::IsNotFullRankMatrix => format!("Matrix is not full rank"),
SRError::IsFullRankMatrix => format!("Matrix is full rank"),
SRError::IsSingular => format!("Matrix is singular"),
SRError::IsNonSingular => format!("Matrix is not singular"),
SRError::IsPositiveDefinite => format!("Matrix is positive definite"),
SRError::IsPositiveSemiDefinite => format!("Matrix is positive semi-definite"),
SRError::IsNegativeDefinite => format!("Matrix is negative definite"),
SRError::IsNegativeSemiDefinite => format!("Matrix is negative semi-definite"),
SRError::IsNonDefinite => format!("Matrix is non-definite"),
SRError::LRDimensionMismatch => format!("The dimensions of LHS and RHS don't match"),
SRError::NoSolution => format!("No solution"),
SRError::InfiniteSolutions => format!("Infinite solutions"),
SRError::DivideByZero => format!("Attempt to divide by zero"),
SRError::IsNotPowerOfTwo => format!("Number is not power of two"),
}
}
}
impl fmt::Display for SRError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self, f)
}
}