@@ -213,23 +213,6 @@ where
213213 }
214214}
215215
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- }
233216
234217/// An interface for computing LU factorizations of matrix refs.
235218pub trait Factorize < S : Data > {
@@ -285,6 +268,41 @@ pub trait InverseInto {
285268 fn inv_into ( self ) -> Result < Self :: Output > ;
286269}
287270
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+
288306impl < A , S > InverseInto for ArrayBase < S , Ix2 >
289307where
290308 A : Scalar ,
@@ -294,7 +312,7 @@ where
294312
295313 fn inv_into ( self ) -> Result < Self :: Output > {
296314 let f = self . factorize_into ( ) ?;
297- f. into_inverse ( )
315+ f. inv_into ( )
298316 }
299317}
300318
@@ -307,6 +325,6 @@ where
307325
308326 fn inv ( & self ) -> Result < Self :: Output > {
309327 let f = self . factorize ( ) ?;
310- f. into_inverse ( )
328+ f. inv_into ( )
311329 }
312330}
0 commit comments