@@ -213,23 +213,6 @@ where
213
213
}
214
214
}
215
215
216
- impl < A , S > Factorized < S >
217
- where
218
- A : Scalar ,
219
- S : DataMut < Elem = A > ,
220
- {
221
- /// Computes the inverse of the factorized matrix.
222
- pub fn into_inverse ( mut self ) -> Result < ArrayBase < S , Ix2 > > {
223
- unsafe {
224
- A :: inv (
225
- self . a . square_layout ( ) ?,
226
- self . a . as_allocated_mut ( ) ?,
227
- & self . ipiv ,
228
- ) ?
229
- } ;
230
- Ok ( self . a )
231
- }
232
- }
233
216
234
217
/// An interface for computing LU factorizations of matrix refs.
235
218
pub trait Factorize < S : Data > {
@@ -285,6 +268,41 @@ pub trait InverseInto {
285
268
fn inv_into ( self ) -> Result < Self :: Output > ;
286
269
}
287
270
271
+ impl < A , S > InverseInto for Factorized < S >
272
+ where
273
+ A : Scalar ,
274
+ S : DataMut < Elem = A > ,
275
+ {
276
+ type Output = ArrayBase < S , Ix2 > ;
277
+
278
+ fn inv_into ( mut self ) -> Result < ArrayBase < S , Ix2 > > {
279
+ unsafe {
280
+ A :: inv (
281
+ self . a . square_layout ( ) ?,
282
+ self . a . as_allocated_mut ( ) ?,
283
+ & self . ipiv ,
284
+ ) ?
285
+ } ;
286
+ Ok ( self . a )
287
+ }
288
+ }
289
+
290
+ impl < A , S > Inverse for Factorized < S >
291
+ where
292
+ A : Scalar ,
293
+ S : Data < Elem = A > ,
294
+ {
295
+ type Output = Array2 < A > ;
296
+
297
+ fn inv ( & self ) -> Result < Array2 < A > > {
298
+ let f = Factorized {
299
+ a : replicate ( & self . a ) ,
300
+ ipiv : self . ipiv . clone ( ) ,
301
+ } ;
302
+ f. inv_into ( )
303
+ }
304
+ }
305
+
288
306
impl < A , S > InverseInto for ArrayBase < S , Ix2 >
289
307
where
290
308
A : Scalar ,
@@ -294,7 +312,7 @@ where
294
312
295
313
fn inv_into ( self ) -> Result < Self :: Output > {
296
314
let f = self . factorize_into ( ) ?;
297
- f. into_inverse ( )
315
+ f. inv_into ( )
298
316
}
299
317
}
300
318
@@ -307,6 +325,6 @@ where
307
325
308
326
fn inv ( & self ) -> Result < Self :: Output > {
309
327
let f = self . factorize ( ) ?;
310
- f. into_inverse ( )
328
+ f. inv_into ( )
311
329
}
312
330
}
0 commit comments