From fbf3a2d6bd13a1bbeee1e89b04dd595959bfa392 Mon Sep 17 00:00:00 2001 From: Susi Lehtola Date: Sat, 29 Aug 2026 18:40:10 +0300 Subject: [PATCH] Fix container type and empty-vector defects in the composite quadratures Three unrelated defects in the same two headers. SubQuadrature's generator declared its weights in the *point* container type and returned it as the weight_container half of the tuple: point_container points ( ... ); point_container weights( ... ); // wrong type This compiles today only because every radial quadrature happens to use std::vector for both. It breaks as soon as the two differ, which is exactly what mixed precision needs: SubQuadrature> does not compile before this change. Two of the surrounding assertions also tested `>= 0` on size_t, which is vacuous; drop them and keep the bounds that say something. RadialGridPartition::finalize() read partition_idx_.back() without checking that anything had been added, which is undefined behaviour on an empty vector. make_pruned_grid() guards against an empty region list one layer up, but finalize() is public and the class is default-constructible, so the guard is not structural. Throw instead. Six adaptor overrides in the two spherical quadrature headers were written as `override {;` -- a stray empty statement after the opening brace. Harmless, but remove them. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01FDTFYJMQ76iujDFNHzZyXF --- .../pruned_spherical_quadrature.hpp | 10 +++++++--- .../spherical_quadrature.hpp | 6 +++--- .../composite_quadratures/sub_quadrature.hpp | 18 ++++++++---------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/integratorxx/composite_quadratures/pruned_spherical_quadrature.hpp b/include/integratorxx/composite_quadratures/pruned_spherical_quadrature.hpp index d90305f..273fcf3 100644 --- a/include/integratorxx/composite_quadratures/pruned_spherical_quadrature.hpp +++ b/include/integratorxx/composite_quadratures/pruned_spherical_quadrature.hpp @@ -5,6 +5,7 @@ #include #include +#include #include namespace IntegratorXX { @@ -45,6 +46,9 @@ class RadialGridPartition { template void finalize( const RadialQuad& rq ) { + if( partition_idx_.empty() ) + throw std::runtime_error( + "RadialGridPartition: cannot finalize without any angular quadrature"); if( partition_idx_.back() != rq.npts() ) partition_idx_.emplace_back( rq.npts() ); } @@ -179,13 +183,13 @@ class PrunedSphericalQuadrature : const point_container& sph_points_adaptor() const override { return quad_base_type::points(); } - point_container& sph_points_adaptor() override {; + point_container& sph_points_adaptor() override { return quad_base_type::points(); } - const weight_container& sph_weights_adaptor() const override {; + const weight_container& sph_weights_adaptor() const override { return quad_base_type::weights(); } - weight_container& sph_weights_adaptor() override {; + weight_container& sph_weights_adaptor() override { return quad_base_type::weights(); } diff --git a/include/integratorxx/composite_quadratures/spherical_quadrature.hpp b/include/integratorxx/composite_quadratures/spherical_quadrature.hpp index e26bf91..45a80cc 100644 --- a/include/integratorxx/composite_quadratures/spherical_quadrature.hpp +++ b/include/integratorxx/composite_quadratures/spherical_quadrature.hpp @@ -132,13 +132,13 @@ class SphericalQuadrature : const point_container& sph_points_adaptor() const override { return quad_base_type::points(); } - point_container& sph_points_adaptor() override {; + point_container& sph_points_adaptor() override { return quad_base_type::points(); } - const weight_container& sph_weights_adaptor() const override {; + const weight_container& sph_weights_adaptor() const override { return quad_base_type::weights(); } - weight_container& sph_weights_adaptor() override {; + weight_container& sph_weights_adaptor() override { return quad_base_type::weights(); } diff --git a/include/integratorxx/composite_quadratures/sub_quadrature.hpp b/include/integratorxx/composite_quadratures/sub_quadrature.hpp index 15809a4..c14bcdf 100644 --- a/include/integratorxx/composite_quadratures/sub_quadrature.hpp +++ b/include/integratorxx/composite_quadratures/sub_quadrature.hpp @@ -47,16 +47,14 @@ struct quadrature_traits< inline static std::tuple generate( range_idx_type idx_range, const Quadrature& quad ) { const auto [begin_idx, end_idx] = idx_range; - assert( begin_idx >= 0 ); - assert( begin_idx <= quad.npts() ); - assert( end_idx >= 0 ); - assert( end_idx <= quad.npts() ); - assert( begin_idx < end_idx ); - - point_container points( quad.points().begin() + begin_idx, - quad.points().begin() + end_idx ); - point_container weights( quad.weights().begin() + begin_idx, - quad.weights().begin() + end_idx ); + // begin_idx and end_idx are size_t, so the lower bounds are vacuous + assert( begin_idx < end_idx ); + assert( end_idx <= quad.npts() ); + + point_container points ( quad.points().begin() + begin_idx, + quad.points().begin() + end_idx ); + weight_container weights( quad.weights().begin() + begin_idx, + quad.weights().begin() + end_idx ); return std::make_tuple( points, weights ); }