@@ -77,59 +77,103 @@ pub use lax::{Pivot, Transpose};
77
77
pub trait Solve < A : Scalar > {
78
78
/// Solves a system of linear equations `A * x = b` where `A` is `self`, `b`
79
79
/// is the argument, and `x` is the successful result.
80
+ ///
81
+ /// # Panics
82
+ ///
83
+ /// Panics if the length of `b` is not the equal to the number of columns
84
+ /// of `A`.
80
85
fn solve < S : Data < Elem = A > > ( & self , b : & ArrayBase < S , Ix1 > ) -> Result < Array1 < A > > {
81
86
let mut b = replicate ( b) ;
82
87
self . solve_inplace ( & mut b) ?;
83
88
Ok ( b)
84
89
}
90
+
85
91
/// Solves a system of linear equations `A * x = b` where `A` is `self`, `b`
86
92
/// is the argument, and `x` is the successful result.
93
+ ///
94
+ /// # Panics
95
+ ///
96
+ /// Panics if the length of `b` is not the equal to the number of columns
97
+ /// of `A`.
87
98
fn solve_into < S : DataMut < Elem = A > > (
88
99
& self ,
89
100
mut b : ArrayBase < S , Ix1 > ,
90
101
) -> Result < ArrayBase < S , Ix1 > > {
91
102
self . solve_inplace ( & mut b) ?;
92
103
Ok ( b)
93
104
}
105
+
94
106
/// Solves a system of linear equations `A * x = b` where `A` is `self`, `b`
95
107
/// is the argument, and `x` is the successful result.
108
+ ///
109
+ /// # Panics
110
+ ///
111
+ /// Panics if the length of `b` is not the equal to the number of columns
112
+ /// of `A`.
96
113
fn solve_inplace < ' a , S : DataMut < Elem = A > > (
97
114
& self ,
98
115
b : & ' a mut ArrayBase < S , Ix1 > ,
99
116
) -> Result < & ' a mut ArrayBase < S , Ix1 > > ;
100
117
101
118
/// Solves a system of linear equations `A^T * x = b` where `A` is `self`, `b`
102
119
/// is the argument, and `x` is the successful result.
120
+ ///
121
+ /// # Panics
122
+ ///
123
+ /// Panics if the length of `b` is not the equal to the number of rows of
124
+ /// `A`.
103
125
fn solve_t < S : Data < Elem = A > > ( & self , b : & ArrayBase < S , Ix1 > ) -> Result < Array1 < A > > {
104
126
let mut b = replicate ( b) ;
105
127
self . solve_t_inplace ( & mut b) ?;
106
128
Ok ( b)
107
129
}
130
+
108
131
/// Solves a system of linear equations `A^T * x = b` where `A` is `self`, `b`
109
132
/// is the argument, and `x` is the successful result.
133
+ ///
134
+ /// # Panics
135
+ ///
136
+ /// Panics if the length of `b` is not the equal to the number of rows of
137
+ /// `A`.
110
138
fn solve_t_into < S : DataMut < Elem = A > > (
111
139
& self ,
112
140
mut b : ArrayBase < S , Ix1 > ,
113
141
) -> Result < ArrayBase < S , Ix1 > > {
114
142
self . solve_t_inplace ( & mut b) ?;
115
143
Ok ( b)
116
144
}
145
+
117
146
/// Solves a system of linear equations `A^T * x = b` where `A` is `self`, `b`
118
147
/// is the argument, and `x` is the successful result.
148
+ ///
149
+ /// # Panics
150
+ ///
151
+ /// Panics if the length of `b` is not the equal to the number of rows of
152
+ /// `A`.
119
153
fn solve_t_inplace < ' a , S : DataMut < Elem = A > > (
120
154
& self ,
121
155
b : & ' a mut ArrayBase < S , Ix1 > ,
122
156
) -> Result < & ' a mut ArrayBase < S , Ix1 > > ;
123
157
124
158
/// Solves a system of linear equations `A^H * x = b` where `A` is `self`, `b`
125
159
/// is the argument, and `x` is the successful result.
160
+ ///
161
+ /// # Panics
162
+ ///
163
+ /// Panics if the length of `b` is not the equal to the number of rows of
164
+ /// `A`.
126
165
fn solve_h < S : Data < Elem = A > > ( & self , b : & ArrayBase < S , Ix1 > ) -> Result < Array1 < A > > {
127
166
let mut b = replicate ( b) ;
128
167
self . solve_h_inplace ( & mut b) ?;
129
168
Ok ( b)
130
169
}
131
170
/// Solves a system of linear equations `A^H * x = b` where `A` is `self`, `b`
132
171
/// is the argument, and `x` is the successful result.
172
+ ///
173
+ /// # Panics
174
+ ///
175
+ /// Panics if the length of `b` is not the equal to the number of rows of
176
+ /// `A`.
133
177
fn solve_h_into < S : DataMut < Elem = A > > (
134
178
& self ,
135
179
mut b : ArrayBase < S , Ix1 > ,
@@ -139,6 +183,11 @@ pub trait Solve<A: Scalar> {
139
183
}
140
184
/// Solves a system of linear equations `A^H * x = b` where `A` is `self`, `b`
141
185
/// is the argument, and `x` is the successful result.
186
+ ///
187
+ /// # Panics
188
+ ///
189
+ /// Panics if the length of `b` is not the equal to the number of rows of
190
+ /// `A`.
142
191
fn solve_h_inplace < ' a , S : DataMut < Elem = A > > (
143
192
& self ,
144
193
b : & ' a mut ArrayBase < S , Ix1 > ,
@@ -167,6 +216,11 @@ where
167
216
where
168
217
Sb : DataMut < Elem = A > ,
169
218
{
219
+ assert_eq ! (
220
+ rhs. len( ) ,
221
+ self . a. len_of( Axis ( 1 ) ) ,
222
+ "The length of `rhs` must be compatible with the shape of the factored matrix." ,
223
+ ) ;
170
224
A :: solve (
171
225
self . a . square_layout ( ) ?,
172
226
Transpose :: No ,
@@ -183,6 +237,11 @@ where
183
237
where
184
238
Sb : DataMut < Elem = A > ,
185
239
{
240
+ assert_eq ! (
241
+ rhs. len( ) ,
242
+ self . a. len_of( Axis ( 0 ) ) ,
243
+ "The length of `rhs` must be compatible with the shape of the factored matrix." ,
244
+ ) ;
186
245
A :: solve (
187
246
self . a . square_layout ( ) ?,
188
247
Transpose :: Transpose ,
@@ -199,6 +258,11 @@ where
199
258
where
200
259
Sb : DataMut < Elem = A > ,
201
260
{
261
+ assert_eq ! (
262
+ rhs. len( ) ,
263
+ self . a. len_of( Axis ( 0 ) ) ,
264
+ "The length of `rhs` must be compatible with the shape of the factored matrix." ,
265
+ ) ;
202
266
A :: solve (
203
267
self . a . square_layout ( ) ?,
204
268
Transpose :: Hermite ,
0 commit comments