1
1
use std:: collections:: VecDeque ;
2
+ use std:: iter:: repeat;
2
3
3
4
use faer:: { Col , ColRef , Mat , MatRef , Scale } ;
4
5
use itertools:: Itertools ;
@@ -127,15 +128,17 @@ impl Default for LowRankSettings {
127
128
Self {
128
129
store_mass_matrix : false ,
129
130
gamma : 1e-5 ,
130
- eigval_cutoff : 100f64 ,
131
+ eigval_cutoff : 2f64 ,
131
132
}
132
133
}
133
134
}
134
135
135
136
#[ derive( Debug , Storable ) ]
136
137
pub 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 > > ,
139
142
pub num_eigenvalues : u64 ,
140
143
}
141
144
@@ -145,14 +148,18 @@ impl<M: Math> SamplerStats<M> for LowRankMassMatrix<M> {
145
148
146
149
fn extract_stats ( & self , math : & mut M , _opt : Self :: StatsOptions ) -> Self :: Stats {
147
150
if self . settings . store_mass_matrix {
151
+ let stds = Some ( math. box_array ( & self . stds ) ) ;
148
152
let eigvals = self
149
153
. inner
150
154
. as_ref ( )
151
155
. 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
+ }
153
160
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 ( ) ) ,
156
163
num_eigenvalues : self
157
164
. inner
158
165
. as_ref ( )
@@ -161,9 +168,13 @@ impl<M: Math> SamplerStats<M> for LowRankMassMatrix<M> {
161
168
}
162
169
} else {
163
170
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 ) ,
167
178
}
168
179
}
169
180
}
0 commit comments