11use std:: collections:: VecDeque ;
2+ use std:: iter:: repeat;
23
34use faer:: { Col , ColRef , Mat , MatRef , Scale } ;
45use itertools:: Itertools ;
@@ -127,15 +128,17 @@ impl Default for LowRankSettings {
127128 Self {
128129 store_mass_matrix : false ,
129130 gamma : 1e-5 ,
130- eigval_cutoff : 100f64 ,
131+ eigval_cutoff : 2f64 ,
131132 }
132133 }
133134}
134135
135136#[ derive( Debug , Storable ) ]
136137pub struct MatrixStats {
137- pub eigvals : Option < Vec < f64 > > ,
138- pub stds : Option < Vec < f64 > > ,
138+ #[ storable( dims( "unconstrained_parameter" ) ) ]
139+ pub mass_matrix_eigvals : Option < Vec < f64 > > ,
140+ #[ storable( dims( "unconstrained_parameter" ) ) ]
141+ pub mass_matrix_stds : Option < Vec < f64 > > ,
139142 pub num_eigenvalues : u64 ,
140143}
141144
@@ -145,14 +148,18 @@ impl<M: Math> SamplerStats<M> for LowRankMassMatrix<M> {
145148
146149 fn extract_stats ( & self , math : & mut M , _opt : Self :: StatsOptions ) -> Self :: Stats {
147150 if self . settings . store_mass_matrix {
151+ let stds = Some ( math. box_array ( & self . stds ) ) ;
148152 let eigvals = self
149153 . inner
150154 . as_ref ( )
151155 . map ( |inner| math. eigs_as_array ( & inner. vals ) ) ;
152- let stds = Some ( math. box_array ( & self . stds ) ) ;
156+ let mut eigvals = eigvals. map ( |x| x. into_vec ( ) ) ;
157+ if let Some ( ref mut eigvals) = eigvals {
158+ eigvals. extend ( repeat ( f64:: NAN ) . take ( stds. as_ref ( ) . unwrap ( ) . len ( ) - eigvals. len ( ) ) ) ;
159+ }
153160 MatrixStats {
154- eigvals : eigvals. map ( |x| x . into_vec ( ) ) ,
155- stds : stds. map ( |x| x. into_vec ( ) ) ,
161+ mass_matrix_eigvals : eigvals,
162+ mass_matrix_stds : stds. map ( |x| x. into_vec ( ) ) ,
156163 num_eigenvalues : self
157164 . inner
158165 . as_ref ( )
@@ -161,9 +168,13 @@ impl<M: Math> SamplerStats<M> for LowRankMassMatrix<M> {
161168 }
162169 } else {
163170 MatrixStats {
164- eigvals : None ,
165- stds : None ,
166- num_eigenvalues : 0 ,
171+ mass_matrix_eigvals : None ,
172+ mass_matrix_stds : None ,
173+ num_eigenvalues : self
174+ . inner
175+ . as_ref ( )
176+ . map ( |inner| inner. num_eigenvalues )
177+ . unwrap_or ( 0 ) ,
167178 }
168179 }
169180 }
0 commit comments