Skip to content

Commit 68e3fb7

Browse files
committed
bug fix: force reconstruction of Rademacher sampled matrix if number of mc samples differs between consecutive calls to edf()
1 parent 91a32cf commit 68e3fb7

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

fdaPDE/src/solvers/fe_ls_elliptic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ struct fe_ls_elliptic {
361361
// hutchinson approximation for Tr[S]
362362
double edf(int r = 100, int seed = random_seed) {
363363
fdapde_assert(lambda_saved_.has_value());
364-
if (!Ys_.has_value() || !Bs_.has_value()) {
364+
if (!Ys_.has_value() || !Bs_.has_value() || r != Us_->rows()) { // force reconstruction if r differs from old
365365
int seed_ = (seed == random_seed) ? std::random_device()() : seed;
366366
std::mt19937 rng(seed_);
367367
rademacher_distribution rademacher;
@@ -377,7 +377,7 @@ struct fe_ls_elliptic {
377377
} else {
378378
Bs_->topRows(n_dofs_) = -PsiNA().transpose() * D_ * internals::lmbQ(W_, X_, invXtWX_, *Us_);
379379
}
380-
// enforce Dirichlet BCs, if any
380+
// enforce Dirichlet BCs, if any
381381
for (size_t i = 0; i < dirichlet_dofs_.size(); ++i) {
382382
Bs_->row(dirichlet_dofs_[i]).setConstant(dirichlet_vals_[i]);
383383
}

fdaPDE/src/solvers/fe_ls_parabolic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class fe_ls_parabolic_mono {
413413
// hutchinson approximation for Tr[S]
414414
double edf(int r = 100, int seed = random_seed) {
415415
fdapde_assert(lambda_saved_.has_value());
416-
if (!Ys_.has_value() || !Bs_.has_value()) {
416+
if (!Ys_.has_value() || !Bs_.has_value() || r != Us_->rows()) { // force reconstruction if r differs from old
417417
int seed_ = (seed == random_seed) ? std::random_device()() : seed;
418418
std::mt19937 rng(seed_);
419419
rademacher_distribution rademacher;

fdaPDE/src/solvers/fe_ls_separable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class fe_ls_separable_mono {
413413
// hutchinson approximation for Tr[S]
414414
double edf(int r = 100, int seed = random_seed) {
415415
fdapde_assert(lambda_saved_.has_value());
416-
if (!Ys_.has_value() || !Bs_.has_value()) {
416+
if (!Ys_.has_value() || !Bs_.has_value() || r != Us_->rows()) { // force reconstruction if r differs from old
417417
int seed_ = (seed == random_seed) ? std::random_device()() : seed;
418418
std::mt19937 rng(seed_);
419419
rademacher_distribution rademacher;
@@ -938,7 +938,7 @@ class fe_ls_separable_cdti {
938938
// hutchinson approximation for Tr[S]
939939
double edf(int r = 100, int seed = random_seed) {
940940
fdapde_assert(lambda_saved_.has_value());
941-
if (!Us_.has_value()) {
941+
if (!Us_.has_value() || r != Us_->rows()) { // force reconstruction if r differs from old
942942
int seed_ = (seed == random_seed) ? std::random_device()() : seed;
943943
std::mt19937 rng(seed_);
944944
rademacher_distribution rademacher;

0 commit comments

Comments
 (0)