Skip to content

Commit 41c88a6

Browse files
authored
Fix FPE in templated networks (#1600)
Also document `autodiff::detail::isDual` for checking templated types. I'm leaving this as a quiet NaN so it will show up in outputs if it ever gets used by accident, but won't immediately trigger a floating-point exception.
1 parent 3ff348f commit 41c88a6

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

screening/screen.H

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,12 @@ void actual_screen(const plasma_state_t<dual_t>& state,
645645
{
646646
dual_t scor_dual;
647647
scor_dual = actual_screen(state, scn_fac);
648-
if constexpr (std::is_same_v<dual_t, amrex::Real>) {
649-
scor = scor_dual;
650-
scordt = std::numeric_limits<amrex::Real>::signaling_NaN();
651-
} else {
648+
if constexpr (autodiff::detail::isDual<dual_t>) {
652649
scor = autodiff::val(scor_dual);
653650
scordt = autodiff::derivative(scor_dual);
651+
} else {
652+
scor = scor_dual;
653+
scordt = std::numeric_limits<amrex::Real>::quiet_NaN();
654654
}
655655
}
656656

sphinx_docs/source/autodiff.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ replaced with ones in the ``admath`` namespace. This namespace also
2121
exports the original functions, so they work fine on normal numeric
2222
types too.
2323

24+
To manually check whether a type is a dual number or not, use
25+
``autodiff::detail::isDual<dual_t>``.
26+
2427
Derivatives of single-variable functions
2528
========================================
2629

0 commit comments

Comments
 (0)