diff --git a/scripts/08_combined_timeseries.py b/scripts/08_combined_timeseries.py index f09d52f..5cb9189 100644 --- a/scripts/08_combined_timeseries.py +++ b/scripts/08_combined_timeseries.py @@ -499,6 +499,16 @@ def make_combined_figure( # Report # --------------------------------------------------------------------------- +def _fv(v, fmt: str) -> str: + """Format a possibly-None float; returns 'N/A' when None/NaN.""" + if v is None: + return "N/A" + try: + return format(float(v), fmt) + except (TypeError, ValueError): + return "N/A" + + def write_combined_report( results: dict, sinusoid_fit: dict, @@ -536,9 +546,9 @@ Surrogates: {args.n_surrogates:,} per window | Window | p_global | σ_surrogate | peak lag | |---|---|---|---| -| In-sample (1976–2019) | {results.get('p_global_insample', float('nan')):.4f} | {results.get('sigma_insample', float('nan')):.2f} | {results.get('peak_lag_insample', '?')} d | -| Out-of-sample (2020–{args.study_end[:4]}) | {results.get('p_global_oos', float('nan')):.4f} | {results.get('sigma_oos', float('nan')):.2f} | {results.get('peak_lag_oos', '?')} d | -| Combined (1976–{args.study_end[:4]}) | {results.get('p_global_full', float('nan')):.4f} | {results.get('sigma_full', float('nan')):.2f} | {results.get('peak_lag_full', '?')} d | +| In-sample (1976–2019) | {_fv(results.get('p_global_insample'), '.4f')} | {_fv(results.get('sigma_insample'), '.2f')} | {results.get('peak_lag_insample', 'N/A')} d | +| Out-of-sample (2020–{args.study_end[:4]}) | {_fv(results.get('p_global_oos'), '.4f')} | {_fv(results.get('sigma_oos'), '.2f')} | {results.get('peak_lag_oos', 'N/A')} d | +| Combined (1976–{args.study_end[:4]}) | {_fv(results.get('p_global_full'), '.4f')} | {_fv(results.get('sigma_full'), '.2f')} | {results.get('peak_lag_full', 'N/A')} d | ## Sinusoidal envelope fit diff --git a/src/crq/stats/surrogates_gpu.py b/src/crq/stats/surrogates_gpu.py index 19c1c04..de5569a 100644 --- a/src/crq/stats/surrogates_gpu.py +++ b/src/crq/stats/surrogates_gpu.py @@ -119,12 +119,13 @@ def auto_batch_size( + T * 4 # int32 rank buffer ) else: - # Phase: tiled signal + sorted copy + rank buffer + rfft + # Phase: tiled signal + sorted copy + rank buffer + rfft + irfft output bytes_per_surrogate = ( T * bytes_per_elem # signal + T * bytes_per_elem # sorted copy + T * 4 # int32 rank indices - + (T // 2 + 1) * 8 # complex64 FFT + + (T // 2 + 1) * 8 # complex64 FFT coefficients + + T * bytes_per_elem # irfft output buffer (was missing) ) budget = vram_budget_gb * 1e9 * (1.0 - headroom) batch = max(1, int(budget // bytes_per_surrogate))