@@ -63,7 +63,7 @@ pub use lapack_traits::{Pivot, UPLO};
6363/// If you plan to solve many equations with the same Hermitian (or real
6464/// symmetric) coefficient matrix `A` but different `b` vectors, it's faster to
6565/// factor the `A` matrix once using the `FactorizeH` trait, and then solve
66- /// using the `FactorizedH ` struct.
66+ /// using the `BKFactorized ` struct.
6767pub trait SolveH < A : Scalar > {
6868 /// Solves a system of linear equations `A * x = b` with Hermitian (or real
6969 /// symmetric) matrix `A`, where `A` is `self`, `b` is the argument, and
@@ -89,12 +89,12 @@ pub trait SolveH<A: Scalar> {
8989
9090/// Represents the Bunch–Kaufman factorization of a Hermitian (or real
9191/// symmetric) matrix as `A = P * U * D * U^H * P^T`.
92- pub struct FactorizedH < S : Data > {
92+ pub struct BKFactorized < S : Data > {
9393 pub a : ArrayBase < S , Ix2 > ,
9494 pub ipiv : Pivot ,
9595}
9696
97- impl < A , S > SolveH < A > for FactorizedH < S >
97+ impl < A , S > SolveH < A > for BKFactorized < S >
9898where
9999 A : Scalar ,
100100 S : Data < Elem = A > ,
@@ -131,54 +131,30 @@ where
131131}
132132
133133
134- impl < A , S > FactorizedH < S >
135- where
136- A : Scalar ,
137- S : DataMut < Elem = A > ,
138- {
139- /// Computes the inverse of the factorized matrix.
140- ///
141- /// **Warning: The inverse is stored only in the upper triangular portion
142- /// of the result matrix!** If you want the lower triangular portion to be
143- /// correct, you must fill it in according to the results in the upper
144- /// triangular portion.
145- pub fn into_inverseh ( mut self ) -> Result < ArrayBase < S , Ix2 > > {
146- unsafe {
147- A :: invh (
148- self . a . square_layout ( ) ?,
149- UPLO :: Upper ,
150- self . a . as_allocated_mut ( ) ?,
151- & self . ipiv ,
152- ) ?
153- } ;
154- Ok ( self . a )
155- }
156- }
157-
158134/// An interface for computing the Bunch–Kaufman factorization of Hermitian (or
159135/// real symmetric) matrix refs.
160136pub trait FactorizeH < S : Data > {
161137 /// Computes the Bunch–Kaufman factorization of a Hermitian (or real
162138 /// symmetric) matrix.
163- fn factorizeh ( & self ) -> Result < FactorizedH < S > > ;
139+ fn factorizeh ( & self ) -> Result < BKFactorized < S > > ;
164140}
165141
166142/// An interface for computing the Bunch–Kaufman factorization of Hermitian (or
167143/// real symmetric) matrices.
168144pub trait FactorizeHInto < S : Data > {
169145 /// Computes the Bunch–Kaufman factorization of a Hermitian (or real
170146 /// symmetric) matrix.
171- fn factorizeh_into ( self ) -> Result < FactorizedH < S > > ;
147+ fn factorizeh_into ( self ) -> Result < BKFactorized < S > > ;
172148}
173149
174150impl < A , S > FactorizeHInto < S > for ArrayBase < S , Ix2 >
175151where
176152 A : Scalar ,
177153 S : DataMut < Elem = A > ,
178154{
179- fn factorizeh_into ( mut self ) -> Result < FactorizedH < S > > {
155+ fn factorizeh_into ( mut self ) -> Result < BKFactorized < S > > {
180156 let ipiv = unsafe { A :: bk ( self . layout ( ) ?, UPLO :: Upper , self . as_allocated_mut ( ) ?) ? } ;
181- Ok ( FactorizedH {
157+ Ok ( BKFactorized {
182158 a : self ,
183159 ipiv : ipiv,
184160 } )
@@ -190,10 +166,10 @@ where
190166 A : Scalar ,
191167 Si : Data < Elem = A > ,
192168{
193- fn factorizeh ( & self ) -> Result < FactorizedH < OwnedRepr < A > > > {
169+ fn factorizeh ( & self ) -> Result < BKFactorized < OwnedRepr < A > > > {
194170 let mut a: Array2 < A > = replicate ( self ) ;
195171 let ipiv = unsafe { A :: bk ( a. layout ( ) ?, UPLO :: Upper , a. as_allocated_mut ( ) ?) ? } ;
196- Ok ( FactorizedH { a : a, ipiv : ipiv } )
172+ Ok ( BKFactorized { a : a, ipiv : ipiv } )
197173 }
198174}
199175
@@ -221,6 +197,42 @@ pub trait InverseHInto {
221197 fn invh_into ( self ) -> Result < Self :: Output > ;
222198}
223199
200+ impl < A , S > InverseHInto for BKFactorized < S >
201+ where
202+ A : Scalar ,
203+ S : DataMut < Elem = A > ,
204+ {
205+ type Output = ArrayBase < S , Ix2 > ;
206+
207+ fn invh_into ( mut self ) -> Result < ArrayBase < S , Ix2 > > {
208+ unsafe {
209+ A :: invh (
210+ self . a . square_layout ( ) ?,
211+ UPLO :: Upper ,
212+ self . a . as_allocated_mut ( ) ?,
213+ & self . ipiv ,
214+ ) ?
215+ } ;
216+ Ok ( self . a )
217+ }
218+ }
219+
220+ impl < A , S > InverseH for BKFactorized < S >
221+ where
222+ A : Scalar ,
223+ S : Data < Elem = A > ,
224+ {
225+ type Output = Array2 < A > ;
226+
227+ fn invh ( & self ) -> Result < Self :: Output > {
228+ let f = BKFactorized {
229+ a : replicate ( & self . a ) ,
230+ ipiv : self . ipiv . clone ( ) ,
231+ } ;
232+ f. invh_into ( )
233+ }
234+ }
235+
224236impl < A , S > InverseHInto for ArrayBase < S , Ix2 >
225237where
226238 A : Scalar ,
@@ -230,7 +242,7 @@ where
230242
231243 fn invh_into ( self ) -> Result < Self :: Output > {
232244 let f = self . factorizeh_into ( ) ?;
233- f. into_inverseh ( )
245+ f. invh_into ( )
234246 }
235247}
236248
@@ -243,6 +255,6 @@ where
243255
244256 fn invh ( & self ) -> Result < Self :: Output > {
245257 let f = self . factorizeh ( ) ?;
246- f. into_inverseh ( )
258+ f. invh_into ( )
247259 }
248260}
0 commit comments