55using Clock = std::chrono::steady_clock;
60 using ComplexD = FFTD::Complex;
62 volatile long double benchmark_sink = 0;
66 bool validate =
false;
68 size_t repetitions = 64;
72 size_t batch_count = 16;
73 unsigned seed = 20260306u;
74 Array<size_t> sizes = {64, 128, 256, 300, 512, 1024, 1536, 2048};
80 double median_us = 0.0;
83 double stddev_us = 0.0;
90 size_t items_per_call = 1;
91 size_t repetitions = 0;
92 TimingStats sequential;
96 struct ValidationMetrics
98 long double max_forward_error = 0;
99 long double max_roundtrip_error = 0;
100 long double max_real_roundtrip_error = 0;
101 long double max_compact_roundtrip_error = 0;
104 template <
typename Real>
105 [[nodiscard]]
constexpr ValidationMetrics
106 validation_envelope()
noexcept
108 if constexpr (std::is_same_v<Real, float>)
109 return {1.0e-4L, 1.0e-4L, 1.0e-4L, 1.0e-4L};
110 else if constexpr (std::is_same_v<Real, double>)
111 return {1.0e-12L, 1.0e-12L, 1.0e-12L, 1.0e-12L};
113 return {1.0e-15L, 1.0e-15L, 1.0e-15L, 1.0e-15L};
116 [[nodiscard]]
constexpr bool
117 is_within_envelope(
const ValidationMetrics & metrics,
118 const ValidationMetrics & envelope)
noexcept
120 return metrics.max_forward_error <= envelope.max_forward_error
121 and metrics.max_roundtrip_error <= envelope.max_roundtrip_error
122 and metrics.max_real_roundtrip_error <= envelope.max_real_roundtrip_error
123 and metrics.max_compact_roundtrip_error <= envelope.max_compact_roundtrip_error;
127 parse_sizes(
const std::string & csv)
130 std::stringstream ss(csv);
132 while (std::getline(ss, item,
','))
138 const unsigned long long parsed = std::stoull(item);
139 sizes.
append(
static_cast<size_t>(parsed));
141 catch (
const std::invalid_argument &)
143 throw std::runtime_error(
"Invalid token '" + item
144 +
"' in --sizes argument");
146 catch (
const std::out_of_range &)
148 throw std::runtime_error(
"Out-of-range token '" + item
149 +
"' in --sizes argument");
155 [[nodiscard]] Options
156 parse_options(
const int argc,
char ** argv)
159 for (
int i = 1; i < argc; ++i)
161 const std::string arg = argv[i];
162 if (arg ==
"--validate")
164 else if (arg ==
"--json")
166 else if (arg ==
"--repetitions" and i + 1 < argc)
167 options.repetitions =
static_cast<size_t>(std::stoull(argv[++i]));
168 else if (arg ==
"--warmup" and i + 1 < argc)
169 options.warmup =
static_cast<size_t>(std::stoull(argv[++i]));
170 else if (arg ==
"--samples" and i + 1 < argc)
171 options.samples =
static_cast<size_t>(std::stoull(argv[++i]));
172 else if (arg ==
"--threads" and i + 1 < argc)
173 options.threads =
static_cast<size_t>(std::stoull(argv[++i]));
174 else if (arg ==
"--batch-count" and i + 1 < argc)
175 options.batch_count =
static_cast<size_t>(std::stoull(argv[++i]));
176 else if (arg ==
"--seed" and i + 1 < argc)
177 options.seed =
static_cast<unsigned>(std::stoul(argv[++i]));
178 else if (arg ==
"--sizes" and i + 1 < argc)
179 options.sizes = parse_sizes(argv[++i]);
180 else if (arg ==
"--help")
183 <<
"Usage: fft_benchmark [--validate] [--json] [--repetitions N]"
184 <<
" [--warmup N] [--samples N] [--threads N] [--batch-count N]"
185 <<
" [--seed N] [--sizes a,b,c]\n";
190 std::cerr <<
"Unknown option: " << arg <<
"\n";
197 std::cerr <<
"At least one benchmark size is required\n";
201 for (
size_t i = 0; i <
options.sizes.size(); ++i)
204 std::cerr <<
"Benchmark sizes must be positive\n";
210 std::cerr <<
"Repetitions must be positive\n";
216 std::cerr <<
"Samples must be positive\n";
222 std::cerr <<
"Batch count must be positive\n";
230 resolve_thread_count(
const size_t requested)
235 const size_t detected =
static_cast<size_t>(std::thread::hardware_concurrency());
236 return std::max<size_t>(1, detected);
239 template <
typename Real>
241 make_complex_signal(
const size_t n, std::mt19937_64 &
rng)
243 std::uniform_real_distribution<double> dist(-1.0, 1.0);
246 for (
size_t i = 0; i < n; ++i)
247 signal.
append(std::complex<Real>(
static_cast<Real
>(dist(
rng)),
248 static_cast<Real
>(dist(
rng))));
252 template <
typename Real>
254 make_complex_batch(
const size_t batch_count,
256 std::mt19937_64 &
rng)
260 for (
size_t item = 0; item < batch_count; ++item)
261 batch.
append(make_complex_signal<Real>(n,
rng));
265 template <
typename Real>
267 make_real_signal(
const size_t n, std::mt19937_64 &
rng)
269 std::uniform_real_distribution<double> dist(-1.0, 1.0);
272 for (
size_t i = 0; i < n; ++i)
273 signal.
append(
static_cast<Real
>(dist(
rng)));
277 template <
typename Real>
279 make_real_batch(
const size_t batch_count,
281 std::mt19937_64 &
rng)
285 for (
size_t item = 0; item < batch_count; ++item)
286 batch.
append(make_real_signal<Real>(n,
rng));
290 template <
typename Real>
292 naive_dft(
const Array<std::complex<Real>> & input,
const bool invert)
294 using Complex = std::complex<Real>;
298 const Real sign = invert ? Real(1) : Real(-1);
299 for (
size_t k = 0;
k < input.size(); ++
k)
302 for (
size_t t = 0; t < input.size(); ++t)
304 const Real angle = sign * Real(2) * std::numbers::pi_v<Real>
305 *
static_cast<Real
>(
k)
306 *
static_cast<Real
>(t)
307 /
static_cast<Real
>(input.size());
308 sum += input[t] * std::polar(Real(1), angle);
312 sum /=
static_cast<Real
>(input.size());
318 template <
typename Real>
319 [[nodiscard]]
long double
320 max_complex_error(
const Array<std::complex<Real>> & lhs,
321 const Array<std::complex<Real>> & rhs)
323 long double error = 0;
324 for (
size_t i = 0; i < lhs.size(); ++i)
326 static_cast<long double>(std::abs(lhs[i] - rhs[i])));
330 template <
typename Real>
331 [[nodiscard]]
long double
334 long double error = 0;
335 for (
size_t i = 0; i < lhs.
size(); ++i)
337 static_cast<long double>(std::abs(lhs[i] - rhs[i])));
341 template <
typename Real>
347 for (
size_t i = 0; i < input.
size(); ++i)
348 output.append(std::complex<Real>(input[i], Real(0)));
352 template <
typename Fn>
354 collect_us_per_call_samples(
const size_t warmup,
355 const size_t samples,
356 const size_t repetitions,
359 for (
size_t sample = 0; sample < warmup; ++sample)
360 for (
size_t i = 0; i < repetitions; ++i)
365 for (
size_t sample = 0; sample < samples; ++sample)
367 const auto t0 = Clock::now();
368 for (
size_t i = 0; i < repetitions; ++i)
371 std::chrono::duration_cast<std::chrono::duration<double, std::micro>>(
372 Clock::now() - t0).
count();
373 values.
append(elapsed /
static_cast<double>(repetitions));
378 [[nodiscard]] TimingStats
382 <<
"summarize_timings: at least one sample is required";
386 std::sort(&sorted[0], &sorted[0] + sorted.
size());
389 for (
size_t i = 0; i < values.
size(); ++i)
392 stats.mean_us =
sum /
static_cast<double>(values.
size());
393 stats.min_us = sorted[0];
394 stats.max_us = sorted[sorted.
size() - 1];
395 if (sorted.
size() % 2 == 1)
396 stats.median_us = sorted[sorted.
size() / 2];
398 stats.median_us = 0.5 * (sorted[sorted.
size() / 2 - 1]
399 + sorted[sorted.
size() / 2]);
401 double squared = 0.0;
402 for (
size_t i = 0; i < values.
size(); ++i)
404 const double delta = values[i] - stats.mean_us;
405 squared += delta * delta;
407 stats.stddev_us = std::sqrt(squared /
static_cast<double>(values.
size()));
411 template <
typename Fn>
412 [[nodiscard]] TimingStats
413 measure_timing_stats(
const size_t warmup,
414 const size_t samples,
415 const size_t repetitions,
418 return summarize_timings(collect_us_per_call_samples(warmup,
421 std::forward<Fn>(fn)));
425 make_fir_kernel(
const size_t taps)
429 const double denom =
static_cast<double>(std::max<size_t>(1, taps));
430 for (
size_t i = 0; i < taps; ++i)
432 const double phase = 2.0 * std::numbers::pi *
static_cast<double>(i) / denom;
433 kernel.
append(0.42 - 0.5 * std::cos(phase) + 0.08 * std::cos(2.0 * phase));
442 const size_t num_threads = resolve_thread_count(
options.threads);
447 for (
size_t i = 0; i <
options.sizes.size(); ++i)
449 const size_t n =
options.sizes[i];
452 make_complex_batch<double>(
options.batch_count, n,
rng);
455 make_real_batch<double>(
options.batch_count, n,
rng);
457 make_real_batch<double>(
options.batch_count, n * 4,
rng);
459 const Array<double> fir = make_fir_kernel(std::min<size_t>(129, std::max<size_t>(17, n / 8 + 1)));
460 const FFTD::Plan batch_plan(n);
461 const Array<double> lfilter_numerator = {0.067455, 0.134911, 0.067455};
462 const Array<double> lfilter_denominator = {1.0, -1.14298, 0.412802};
464 const size_t stft_fft_size = n;
465 const size_t window_size = std::min<size_t>(std::max<size_t>(16, n / 2), n);
467 FFTD::STFTOptions stft_options;
468 stft_options.hop_size = std::max<size_t>(1, window_size / 4);
469 stft_options.fft_size = stft_fft_size;
470 stft_options.pad_end =
true;
471 stft_options.validate_nola =
true;
473 const size_t fir_block_size = std::max<size_t>(64, n / 2);
475 BenchmarkRow complex_row;
476 complex_row.name =
"complex_fft";
477 complex_row.size = n;
478 complex_row.repetitions =
options.repetitions;
479 complex_row.sequential =
480 measure_timing_stats(
options.warmup,
485 const auto output = FFTD::transformed(complex_signal, false);
486 benchmark_sink += output[0].real();
488 complex_row.parallel =
489 measure_timing_stats(
options.warmup,
492 [&complex_signal, &pool]()
494 const auto output = FFTD::ptransformed(pool, complex_signal, false);
495 benchmark_sink += output[0].real();
497 rows.append(complex_row);
499 BenchmarkRow batched_complex_row;
500 batched_complex_row.name =
"batched_complex_fft";
501 batched_complex_row.size = n;
502 batched_complex_row.items_per_call =
options.batch_count;
503 batched_complex_row.repetitions = std::max<size_t>(
size_t(1),
505 batched_complex_row.sequential =
506 measure_timing_stats(
options.warmup,
508 batched_complex_row.repetitions,
509 [&complex_batch, &batch_plan]()
511 const auto output = batch_plan.transformed_batch(complex_batch, false);
512 benchmark_sink += output[0][0].real();
514 batched_complex_row.parallel =
515 measure_timing_stats(
options.warmup,
517 batched_complex_row.repetitions,
518 [&complex_batch, &batch_plan, &pool]()
520 const auto output = batch_plan.ptransformed_batch(pool,
523 benchmark_sink += output[0][0].real();
525 rows.append(batched_complex_row);
527 BenchmarkRow batched_real_row;
528 batched_real_row.name =
"batched_real_rfft";
529 batched_real_row.size = n;
530 batched_real_row.items_per_call =
options.batch_count;
531 batched_real_row.repetitions = std::max<size_t>(
size_t(1),
533 batched_real_row.sequential =
534 measure_timing_stats(
options.warmup,
536 batched_real_row.repetitions,
537 [&real_batch, &batch_plan]()
539 const auto output = batch_plan.rfft_batch(real_batch);
540 benchmark_sink += output[0][0].real();
542 batched_real_row.parallel =
543 measure_timing_stats(
options.warmup,
545 batched_real_row.repetitions,
546 [&real_batch, &batch_plan, &pool]()
548 const auto output = batch_plan.prfft_batch(pool,
550 benchmark_sink += output[0][0].real();
552 rows.append(batched_real_row);
554 BenchmarkRow real_row;
555 real_row.name =
"real_fft";
557 real_row.repetitions =
options.repetitions;
558 real_row.sequential =
559 measure_timing_stats(
options.warmup,
564 const auto output = FFTD::transform(real_signal);
565 benchmark_sink += output[0].real();
568 measure_timing_stats(
options.warmup,
571 [&real_signal, &pool]()
573 const auto output = FFTD::ptransform(pool, real_signal);
574 benchmark_sink += output[0].real();
576 rows.append(real_row);
578 BenchmarkRow compact_row;
579 compact_row.name =
"compact_rfft";
580 compact_row.size = n;
581 compact_row.repetitions =
options.repetitions;
582 compact_row.sequential =
583 measure_timing_stats(
options.warmup,
588 const auto output = FFTD::rfft(real_signal);
589 benchmark_sink += output[0].real();
591 compact_row.parallel =
592 measure_timing_stats(
options.warmup,
595 [&real_signal, &pool]()
597 const auto output = FFTD::prfft(pool, real_signal);
598 benchmark_sink += output[0].real();
600 rows.append(compact_row);
602 BenchmarkRow convolution_row;
603 convolution_row.name =
"convolution";
604 convolution_row.size = n;
605 convolution_row.repetitions =
options.repetitions;
606 convolution_row.sequential =
607 measure_timing_stats(
options.warmup,
610 [&long_signal, &fir]()
612 const auto output = FFTD::multiply(long_signal, fir);
613 benchmark_sink += output[0];
615 convolution_row.parallel =
616 measure_timing_stats(
options.warmup,
619 [&long_signal, &fir, &pool]()
621 const auto output = FFTD::pmultiply(pool, long_signal, fir);
622 benchmark_sink += output[0];
624 rows.append(convolution_row);
626 BenchmarkRow overlap_add_bank_row;
627 overlap_add_bank_row.name =
"overlap_add_bank";
628 overlap_add_bank_row.size = n;
629 overlap_add_bank_row.items_per_call =
options.batch_count;
630 overlap_add_bank_row.repetitions =
631 std::max<size_t>(
size_t(1),
options.repetitions / 4);
632 FFTD::OverlapAddBank overlap_bank(
options.batch_count, fir, fir_block_size);
633 overlap_add_bank_row.sequential =
634 measure_timing_stats(
options.warmup,
636 overlap_add_bank_row.repetitions,
637 [&long_real_batch, &overlap_bank]()
639 const auto output = overlap_bank.convolve(long_real_batch);
640 benchmark_sink += output[0][0];
642 overlap_add_bank_row.parallel =
643 measure_timing_stats(
options.warmup,
645 overlap_add_bank_row.repetitions,
646 [&long_real_batch, &overlap_bank, &pool]()
648 const auto output = overlap_bank.pconvolve(pool,
650 benchmark_sink += output[0][0];
652 rows.append(overlap_add_bank_row);
654 BenchmarkRow stft_row;
655 stft_row.name =
"stft";
656 stft_row.size = stft_fft_size;
657 stft_row.repetitions = std::max<size_t>(
size_t(1),
options.repetitions / 4);
658 stft_row.sequential =
659 measure_timing_stats(
options.warmup,
661 stft_row.repetitions,
662 [&long_signal, &window, &stft_options]()
664 const auto output = FFTD::stft(long_signal, window, stft_options);
665 benchmark_sink += static_cast<long double>(output.size());
668 measure_timing_stats(
options.warmup,
670 stft_row.repetitions,
671 [&long_signal, &window, &stft_options, &pool]()
673 const auto output = FFTD::pstft(pool, long_signal, window, stft_options);
674 benchmark_sink += static_cast<long double>(output.size());
676 rows.append(stft_row);
678 BenchmarkRow filter_row;
679 filter_row.name =
"filtfilt";
681 filter_row.repetitions = std::max<size_t>(
size_t(1),
options.repetitions / 4);
682 filter_row.sequential =
683 measure_timing_stats(
options.warmup,
685 filter_row.repetitions,
686 [&long_signal, &fir, fir_block_size]()
688 const auto output = FFTD::filtfilt(long_signal, fir, fir_block_size);
689 benchmark_sink += output[0];
691 filter_row.parallel =
692 measure_timing_stats(
options.warmup,
694 filter_row.repetitions,
695 [&long_signal, &fir, fir_block_size, &pool]()
697 const auto output = FFTD::pfiltfilt(pool,
701 benchmark_sink += output[0];
703 rows.append(filter_row);
705 BenchmarkRow lfilter_bank_row;
706 lfilter_bank_row.name =
"lfilter_bank";
707 lfilter_bank_row.size = n;
708 lfilter_bank_row.items_per_call =
options.batch_count;
709 lfilter_bank_row.repetitions =
710 std::max<size_t>(
size_t(1),
options.repetitions / 4);
711 FFTD::LFilterBank sequential_bank(
options.batch_count,
713 lfilter_denominator);
714 FFTD::LFilterBank parallel_bank(
options.batch_count,
716 lfilter_denominator);
717 lfilter_bank_row.sequential =
718 measure_timing_stats(
options.warmup,
720 lfilter_bank_row.repetitions,
721 [&real_batch, &sequential_bank]()
723 sequential_bank.reset();
724 const auto output = sequential_bank.filter(real_batch);
725 benchmark_sink += output[0][0];
727 lfilter_bank_row.parallel =
728 measure_timing_stats(
options.warmup,
730 lfilter_bank_row.repetitions,
731 [&real_batch, ¶llel_bank, &pool]()
733 parallel_bank.reset();
734 const auto output = parallel_bank.pfilter(pool, real_batch);
735 benchmark_sink += output[0][0];
737 rows.append(lfilter_bank_row);
743 template <
typename Real>
744 [[nodiscard]] ValidationMetrics
745 compute_validation_metrics(
const unsigned seed)
748 using Complex =
typename FFTT::Complex;
751 ValidationMetrics metrics;
753 for (
const size_t n : {size_t(3), size_t(5), size_t(8), size_t(10),
754 size_t(17), size_t(32)})
759 const auto expected = naive_dft(complex_signal,
false);
760 const auto obtained = FFTT::transformed(complex_signal,
false);
761 metrics.max_forward_error = std::max(metrics.max_forward_error,
762 max_complex_error(obtained,
expected));
765 FFTT::transform(roundtrip,
false);
766 FFTT::transform(roundtrip,
true);
767 metrics.max_roundtrip_error = std::max(metrics.max_roundtrip_error,
768 max_complex_error(roundtrip,
771 const auto full_spectrum = FFTT::transform(real_signal);
772 const auto restored_real = FFTT::inverse_transform_real(full_spectrum);
773 metrics.max_real_roundtrip_error = std::max(metrics.max_real_roundtrip_error,
774 max_real_error(restored_real,
777 const auto compact_spectrum = FFTT::rfft(real_signal);
778 const auto restored_compact = FFTT::irfft(compact_spectrum, n);
779 metrics.max_compact_roundtrip_error =
780 std::max(metrics.max_compact_roundtrip_error,
781 max_real_error(restored_compact, real_signal));
788 print_timing_stats_json(
const TimingStats & stats)
791 <<
"\"mean_us\": " << std::fixed << std::setprecision(6) << stats.mean_us <<
", "
792 <<
"\"median_us\": " << stats.median_us <<
", "
793 <<
"\"min_us\": " << stats.min_us <<
", "
794 <<
"\"max_us\": " << stats.max_us <<
", "
795 <<
"\"stddev_us\": " << stats.stddev_us
805 <<
" \"schema_version\": 1,\n"
806 <<
" \"mode\": \"benchmark\",\n"
807 <<
" \"metadata\": {\n"
808 <<
" \"seed\": " <<
options.seed <<
",\n"
809 <<
" \"threads\": " << resolve_thread_count(
options.threads) <<
",\n"
810 <<
" \"simd_backend\": \"" << FFTD::simd_backend_name() <<
"\",\n"
811 <<
" \"batched_plan_simd_backend\": \""
812 << FFTD::batched_plan_simd_backend_name() <<
"\",\n"
813 <<
" \"detected_simd_backend\": \""
814 << FFTD::detected_simd_backend_name() <<
"\",\n"
815 <<
" \"avx2_kernel_compiled\": "
816 << (FFTD::avx2_kernel_compiled() ?
"true" :
"false") <<
",\n"
817 <<
" \"neon_kernel_compiled\": "
818 << (FFTD::neon_kernel_compiled() ?
"true" :
"false") <<
",\n"
819 <<
" \"avx2_runtime_available\": "
820 << (FFTD::avx2_runtime_available() ?
"true" :
"false") <<
",\n"
821 <<
" \"neon_runtime_available\": "
822 << (FFTD::neon_runtime_available() ?
"true" :
"false") <<
",\n"
823 <<
" \"simd_preference\": \"" << FFTD::simd_preference_name() <<
"\",\n"
824 <<
" \"batch_count\": " <<
options.batch_count <<
",\n"
825 <<
" \"warmup_samples\": " <<
options.warmup <<
",\n"
826 <<
" \"samples\": " <<
options.samples <<
"\n"
829 for (
size_t i = 0; i <
rows.size(); ++i)
832 const double speedup_mean =
row.parallel.mean_us > 0.0
833 ?
row.sequential.mean_us /
row.parallel.mean_us
835 const double speedup_median =
row.parallel.median_us > 0.0
836 ?
row.sequential.median_us /
row.parallel.median_us
840 <<
" \"case\": \"" <<
row.name <<
"\",\n"
841 <<
" \"size\": " <<
row.size <<
",\n"
842 <<
" \"items_per_call\": " <<
row.items_per_call <<
",\n"
843 <<
" \"repetitions_per_sample\": " <<
row.repetitions <<
",\n"
844 <<
" \"metric_unit\": \"microseconds_per_call\",\n"
845 <<
" \"sequential\": ";
846 print_timing_stats_json(
row.sequential);
848 <<
" \"parallel\": ";
849 print_timing_stats_json(
row.parallel);
852 <<
"\"mean\": " << speedup_mean <<
", "
853 <<
"\"median\": " << speedup_median
856 if (i + 1 !=
rows.size())
860 std::cout <<
" ]\n}" << std::endl;
864 std::cout <<
"FFT baseline benchmark (microseconds per call)\n";
865 std::cout <<
"Configuration: seed=" <<
options.seed
866 <<
", threads=" << resolve_thread_count(
options.threads)
867 <<
", simd=" << FFTD::simd_backend_name()
868 <<
", batch_simd=" << FFTD::batched_plan_simd_backend_name()
869 <<
", detected_simd=" << FFTD::detected_simd_backend_name()
870 <<
", simd_pref=" << FFTD::simd_preference_name()
871 <<
", batch_count=" <<
options.batch_count
872 <<
", warmup=" <<
options.warmup
873 <<
", samples=" <<
options.samples
875 std::cout << std::left << std::setw(14) <<
"Case"
876 << std::right << std::setw(10) <<
"Size"
877 << std::setw(10) <<
"Batch"
878 << std::setw(12) <<
"Rep/S"
879 << std::setw(16) <<
"SeqMean"
880 << std::setw(16) <<
"ParMean"
881 << std::setw(16) <<
"SeqMedian"
882 << std::setw(16) <<
"ParMedian"
883 << std::setw(12) <<
"Speedup"
885 std::cout << std::string(108,
'-') <<
"\n";
886 for (
size_t i = 0; i <
rows.size(); ++i)
889 const double speedup =
row.parallel.mean_us > 0.0
890 ?
row.sequential.mean_us /
row.parallel.mean_us
892 std::cout << std::left << std::setw(14) <<
row.name
893 << std::right << std::setw(10) <<
row.size
894 << std::setw(10) <<
row.items_per_call
895 << std::setw(12) <<
row.repetitions
896 << std::setw(16) << std::fixed << std::setprecision(3) <<
row.sequential.mean_us
897 << std::setw(16) <<
row.parallel.mean_us
898 << std::setw(16) <<
row.sequential.median_us
899 << std::setw(16) <<
row.parallel.median_us
900 << std::setw(12) << speedup
903 std::cout <<
"Benchmark sink: " <<
static_cast<long double>(benchmark_sink) <<
"\n";
907 print_validation(
const bool json,
const unsigned seed)
909 const auto float_metrics = compute_validation_metrics<float>(
seed);
910 const auto double_metrics = compute_validation_metrics<double>(
seed);
911 const auto long_double_metrics = compute_validation_metrics<long double>(
seed);
912 const auto float_envelope = validation_envelope<float>();
913 const auto double_envelope = validation_envelope<double>();
914 const auto long_double_envelope = validation_envelope<long double>();
915 const bool valid = is_within_envelope(float_metrics, float_envelope)
916 and is_within_envelope(double_metrics, double_envelope)
917 and is_within_envelope(long_double_metrics,
918 long_double_envelope);
920 auto print_metrics = [](
const char * label,
const ValidationMetrics & metrics)
922 std::cout << std::left << std::setw(12) << label
923 << std::right << std::setw(18) << std::setprecision(6)
924 << std::scientific << metrics.max_forward_error
925 << std::setw(18) << metrics.max_roundtrip_error
926 << std::setw(18) << metrics.max_real_roundtrip_error
927 << std::setw(18) << metrics.max_compact_roundtrip_error
933 auto emit = [](
const char * label,
const ValidationMetrics & metrics,
const bool trailing)
935 std::cout <<
" \"" << label <<
"\": {"
936 <<
"\"max_forward_error\": " << std::scientific << metrics.max_forward_error <<
", "
937 <<
"\"max_roundtrip_error\": " << metrics.max_roundtrip_error <<
", "
938 <<
"\"max_real_roundtrip_error\": " << metrics.max_real_roundtrip_error <<
", "
939 <<
"\"max_compact_roundtrip_error\": " << metrics.max_compact_roundtrip_error
947 <<
" \"schema_version\": 1,\n"
948 <<
" \"mode\": \"validation\",\n"
949 <<
" \"valid\": " << (valid ?
"true" :
"false") <<
",\n"
950 <<
" \"metadata\": {\n"
951 <<
" \"seed\": " <<
seed <<
"\n"
953 <<
" \"validation\": {\n";
954 emit(
"float", float_metrics,
true);
955 emit(
"double", double_metrics,
true);
956 emit(
"long_double", long_double_metrics,
false);
957 std::cout <<
" }\n}" << std::endl;
961 std::cout <<
"FFT validation envelope (max absolute error, seed=" <<
seed <<
")\n";
962 std::cout << std::left << std::setw(12) <<
"Precision"
963 << std::right << std::setw(18) <<
"Forward"
964 << std::setw(18) <<
"RoundTrip"
965 << std::setw(18) <<
"RealIFFT"
966 << std::setw(18) <<
"CompactIRFFT"
968 std::cout << std::string(84,
'-') <<
"\n";
969 print_metrics(
"float", float_metrics);
970 print_metrics(
"double", double_metrics);
971 print_metrics(
"long double", long_double_metrics);
979 const Options
options = parse_options(argc, argv);
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
constexpr bool is_empty() const noexcept
Checks if the container is empty.
T & append(const T &data)
Append a copy of data
void reserve(size_t cap)
Reserves cap cells into the array.
Fast Fourier Transform (FFT) and DSP Toolkit.
A reusable thread pool for efficient parallel task execution.
Minimal std::expected-style result type for C++20.
Fast Fourier Transform (FFT) and Digital Signal Processing (DSP) toolkit.
std::chrono::steady_clock Clock
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
and
Check uniqueness with explicit hash + equality functors.
void error(const char *file, int line, const char *format,...)
Print an error message with file and line info.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
static struct argp_option options[]
void run_benchmarks(const BenchmarkConfig &config)
Dynamic array container with automatic resizing.