@@ -63,7 +63,7 @@ pub use lapack_traits::{Pivot, UPLO};
63
63
/// If you plan to solve many equations with the same Hermitian (or real
64
64
/// symmetric) coefficient matrix `A` but different `b` vectors, it's faster to
65
65
/// factor the `A` matrix once using the `FactorizeH` trait, and then solve
66
- /// using the `FactorizedH ` struct.
66
+ /// using the `BKFactorized ` struct.
67
67
pub trait SolveH < A : Scalar > {
68
68
/// Solves a system of linear equations `A * x = b` with Hermitian (or real
69
69
/// symmetric) matrix `A`, where `A` is `self`, `b` is the argument, and
@@ -89,12 +89,12 @@ pub trait SolveH<A: Scalar> {
89
89
90
90
/// Represents the Bunch–Kaufman factorization of a Hermitian (or real
91
91
/// symmetric) matrix as `A = P * U * D * U^H * P^T`.
92
- pub struct FactorizedH < S : Data > {
92
+ pub struct BKFactorized < S : Data > {
93
93
pub a : ArrayBase < S , Ix2 > ,
94
94
pub ipiv : Pivot ,
95
95
}
96
96
97
- impl < A , S > SolveH < A > for FactorizedH < S >
97
+ impl < A , S > SolveH < A > for BKFactorized < S >
98
98
where
99
99
A : Scalar ,
100
100
S : Data < Elem = A > ,
@@ -131,54 +131,30 @@ where
131
131
}
132
132
133
133
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
-
158
134
/// An interface for computing the Bunch–Kaufman factorization of Hermitian (or
159
135
/// real symmetric) matrix refs.
160
136
pub trait FactorizeH < S : Data > {
161
137
/// Computes the Bunch–Kaufman factorization of a Hermitian (or real
162
138
/// symmetric) matrix.
163
- fn factorizeh ( & self ) -> Result < FactorizedH < S > > ;
139
+ fn factorizeh ( & self ) -> Result < BKFactorized < S > > ;
164
140
}
165
141
166
142
/// An interface for computing the Bunch–Kaufman factorization of Hermitian (or
167
143
/// real symmetric) matrices.
168
144
pub trait FactorizeHInto < S : Data > {
169
145
/// Computes the Bunch–Kaufman factorization of a Hermitian (or real
170
146
/// symmetric) matrix.
171
- fn factorizeh_into ( self ) -> Result < FactorizedH < S > > ;
147
+ fn factorizeh_into ( self ) -> Result < BKFactorized < S > > ;
172
148
}
173
149
174
150
impl < A , S > FactorizeHInto < S > for ArrayBase < S , Ix2 >
175
151
where
176
152
A : Scalar ,
177
153
S : DataMut < Elem = A > ,
178
154
{
179
- fn factorizeh_into ( mut self ) -> Result < FactorizedH < S > > {
155
+ fn factorizeh_into ( mut self ) -> Result < BKFactorized < S > > {
180
156
let ipiv = unsafe { A :: bk ( self . layout ( ) ?, UPLO :: Upper , self . as_allocated_mut ( ) ?) ? } ;
181
- Ok ( FactorizedH {
157
+ Ok ( BKFactorized {
182
158
a : self ,
183
159
ipiv : ipiv,
184
160
} )
@@ -190,10 +166,10 @@ where
190
166
A : Scalar ,
191
167
Si : Data < Elem = A > ,
192
168
{
193
- fn factorizeh ( & self ) -> Result < FactorizedH < OwnedRepr < A > > > {
169
+ fn factorizeh ( & self ) -> Result < BKFactorized < OwnedRepr < A > > > {
194
170
let mut a: Array2 < A > = replicate ( self ) ;
195
171
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 } )
197
173
}
198
174
}
199
175
@@ -221,6 +197,42 @@ pub trait InverseHInto {
221
197
fn invh_into ( self ) -> Result < Self :: Output > ;
222
198
}
223
199
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
+
224
236
impl < A , S > InverseHInto for ArrayBase < S , Ix2 >
225
237
where
226
238
A : Scalar ,
@@ -230,7 +242,7 @@ where
230
242
231
243
fn invh_into ( self ) -> Result < Self :: Output > {
232
244
let f = self . factorizeh_into ( ) ?;
233
- f. into_inverseh ( )
245
+ f. invh_into ( )
234
246
}
235
247
}
236
248
@@ -243,6 +255,6 @@ where
243
255
244
256
fn invh ( & self ) -> Result < Self :: Output > {
245
257
let f = self . factorizeh ( ) ?;
246
- f. into_inverseh ( )
258
+ f. invh_into ( )
247
259
}
248
260
}
0 commit comments