feat(linear-static-3d-euler-beam): step 9 - dense-math-adapters-review-fix

This commit is contained in:
KOKO\Mimi
2026-08-09 11:47:58 +09:00
parent 15b5e9916b
commit 4155267c45
3 changed files with 32 additions and 1 deletions
@@ -127,3 +127,20 @@
- handoff: backend-free `fesa::Vector` and `fesa::Matrix` public APIs, with owning
dense storage and checked BLAS operations, are available to Step 10 and later
DOF/element/assembly tasks.
### Review Fix Round 1 — matrix-storage-size-overflow
- regression_test: `tests/unit/math/matrix_test.cpp` now constructs
`Matrix{SIZE_MAX / 2 + 1, 2}` and requires `std::length_error`.
- RED: `cmake --build .harness/build --config Debug --target fesa_tests` exited 0;
`ctest --test-dir .harness/build -C Debug -R DenseMath --output-on-failure`
exited 8 with 1/2 failures because the wraparound constructor threw nothing.
- fix: `Matrix` computes its storage size through a checked helper before vector
construction and rejects exactly `columns != 0 && rows > SIZE_MAX / columns`.
- GREEN: the same targeted build and DenseMath CTest commands exited 0; 2/2 passed.
- VERIFY: approved MSVC x64 configure and full Debug build exited 0; targeted
DenseMath passed 2/2, discovery found 7 tests, and the full suite passed 7/7.
The public-header MKL scan had zero matches, `git diff --check` exited 0, and
`git diff --exit-code -- reference/` exited 0.
- scope: the deferred empty-dot review minor was not changed, reference artifacts
remain untouched, and phase Step 9 status/timestamps were not modified.
+10 -1
View File
@@ -9,6 +9,15 @@
namespace fesa {
namespace {
std::size_t checkedStorageSize(const std::size_t rows, const std::size_t columns) {
// Reject shape multiplication overflow before logical dimensions and storage diverge.
if (columns != 0 &&
rows > (std::numeric_limits<std::size_t>::max)() / columns) {
throw std::length_error{"Dense matrix dimensions exceed the storage size range."};
}
return rows * columns;
}
MKL_INT toMklSize(const std::size_t size) {
if (size > static_cast<std::size_t>((std::numeric_limits<MKL_INT>::max)())) {
throw std::length_error{"Dense matrix dimension exceeds the MKL integer range."};
@@ -30,7 +39,7 @@ Matrix::Matrix(
const std::size_t rows,
const std::size_t columns,
const double value)
: rows_(rows), columns_(columns), values_(rows * columns, value) {}
: rows_(rows), columns_(columns), values_(checkedStorageSize(rows, columns), value) {}
Matrix::Matrix(const Matrix& other)
: rows_(other.rows_), columns_(other.columns_), values_(other.values_.size()) {
+5
View File
@@ -2,6 +2,7 @@
#include <gtest/gtest.h>
#include <limits>
#include <stdexcept>
#include <utility>
@@ -9,6 +10,10 @@ namespace fesa {
namespace {
TEST(DenseMath, RowMajorMatrixMatchesKnownGemvGemm) {
const std::size_t wraparoundRows =
(std::numeric_limits<std::size_t>::max)() / 2U + 1U;
EXPECT_THROW(static_cast<void>(Matrix{wraparoundRows, 2}), std::length_error);
Matrix zeroRows{0, 3};
Vector threeValues{3, 2.0};
const Vector zeroRowProduct = zeroRows.multiply(threeValues);