From d2e43c82f11a88b5e0fe717f378f882f1846d368 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Wed, 14 Oct 2026 10:58:52 -0400 Subject: [PATCH] feat(discretization): added implementation of checked_block_size tho see the note in the header, this could be made more general likeley --- .../discretization/blocks/system_layout.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/lib/serif/discretization/blocks/system_layout.cpp diff --git a/src/lib/serif/discretization/blocks/system_layout.cpp b/src/lib/serif/discretization/blocks/system_layout.cpp new file mode 100644 index 00000000..3886ee93 --- /dev/null +++ b/src/lib/serif/discretization/blocks/system_layout.cpp @@ -0,0 +1,20 @@ +#include "serif/discretization/blocks/system_layout.hpp" + +#include +#include +#include "serif/utils/error/errors.hpp" + +namespace serif::discretization::blocks +{ + std::size_t checked_block_size(const std::span sizes) + { + using namespace utils::errors; + + std::size_t total = 0; + for (const std::size_t size : sizes) { + serif_ensure(size <= std::numeric_limits::max() - total, "The system's packed coefficient count overflows size_t. Check the individual coordinate sizes."); + total += size; + } + return total; + } +} // namespace serif::discretization::blocks