Files
Strata/include/strata/program/adapt_decay.hpp
T
sergqwer 4a7e373da3 engine: --adapt-decay outside 0..1 falls back to 0.7 with a line on stderr (#1284)
--adapt-decay took any number. Above 1 the adaptive tier's usage counts grow without end (inf after a few hundred
adaptations) and the swap gains turn NaN, which breaks the sort that orders the swaps; a negative value flips the counts.
The value is now checked where it is parsed (include/strata/program/adapt_decay.hpp, also in sycl/): a finite value in 0..1
is used exactly as before (0 and 1 included, the range the calibration profile already allows); anything else, NaN and inf
too, runs with the default 0.7 and says so on stderr. A warning instead of the PR's exit 2: a risky pick is reported,
the engine still starts.

adapt_decay_test (25 checks) covers the range, the fallback and finite counts after 100000 adaptations.

Ported from PR #1284 (the check; the refusal became a fallback).
2026-10-26 18:35:58 +01:00

24 lines
1.1 KiB
C++

#pragma once
// --adapt-decay: the factor the adaptive tier's usage counts are multiplied by after each adaptation (#1284).
// Inside 0..1 it forgets old routing; above 1 the counts grow without end (inf after a few hundred adaptations) and the
// swap gains turn NaN, which breaks the sort that orders the swaps. An unusable value is not refused: the engine says
// so and runs with the default.
#include <cmath>
#include <cstdio>
namespace strata::program {
constexpr float kAdaptDecayDefault = 0.7f;
/// `v` itself when it is finite and in 0..1 (0 forgets everything at once, 1 never forgets: both work), else the default
/// with a line on stderr.
inline float adapt_decay_checked(double v, std::FILE* log = stderr) {
if (std::isfinite(v) && v >= 0.0 && v <= 1.0) return (float) v;
if (log != nullptr)
std::fprintf(log, "strata: --adapt-decay %g is not between 0 and 1; using %g (counts above 1 grow without end and the swap gains turn NaN)\n",
v, (double) kAdaptDecayDefault);
return kAdaptDecayDefault;
}
} // namespace strata::program