Repository navigation
Read all four submatrices in QuadMatrix::read, not just in Debug - #82
Merged
Merged
Conversation
QuadMatrix::read wrapped the reads of topRight, bottomLeft and bottomRight in #ifdef MATHICGB_DEBUG. In a Release build MATHICGB_ASSERT discards its argument entirely, so the three asserts that compare the moduli disappear, the three variables they name become unused -- and the reads that produced them were deleted along with the warning. A Release build therefore reads topLeft, stops, and leaves the other three quadrants empty, with the file offset still sitting after the first submatrix. The reduction then runs on that, so a Release mgb matrix and a Debug one disagree about what a stored matrix reduces to. On cyclic5-1.qmat: build .brmat .rbrmat Release 20 B 20 B (empty: only topLeft was read) Debug 228 B 228 B with cmp reporting a difference at byte 1 of both files. Read all four unconditionally and mark the three moduli [[maybe_unused]], which is what 320c4a5 did for colCount in SparseMatrix::read -- the same commit, "changes so code compiles with only a few compiler warnings", that introduced this in 2022-01-04. It silenced the warning by removing the work instead. src/test/QuadMatrix.cpp is a regression test for it: give each quadrant a distinct entry, write, read back, compare all four. It fails in a Release build without the fix and passes in a Debug one, which is the bug stated as a test. Verified: without the fix the new test fails in Release and passes in Debug; with it both pass, 247/247 in each. Release and Debug also produce byte-identical .brmat and .rbrmat on cyclic5-1, -2, -5 and -9, the fixed Release output matches what Debug produced before the fix, the Release build compiles with no warnings, and autotools make distcheck passes. Reachable only through mgb matrix, which aborted before it could show any of this until PR #74, which is why it surfaced now and not in 2022. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
QuadMatrix::readwrapped the reads oftopRight,bottomLeftandbottomRightin#ifdef MATHICGB_DEBUG:In a Release build
MATHICGB_ASSERTdiscards its argument entirely, so thethree modulus comparisons disappear and the three variables they name become
unused — and the reads that produced them were deleted along with the warning.
SparseMatrix::readis not a query: it consumes bytes from theFILE*andfills the submatrix. So a Release build reads
topLeft, stops, leaves threequadrants empty, and leaves the file offset sitting after the first submatrix.
The reduction then runs on that.
What it looks like
Generating matrices with
mgb gb cyclic5 -reducer 26 -storeMatrices 1, thenmgb matrix cyclic5-1under each build:.brmat.rbrmatcmpdiffers at byte 1 of both. The Release result is not subtly wrong — it isempty, because only
topLeftwas ever read.The fix
Read all four unconditionally and mark the three moduli
[[maybe_unused]].This is the remedy the same commit already chose 60 lines away.
320c4a5(2022-01-04) is titled "changes so code compiles with only a few compiler
warnings. But
[[maybe_unused]]is used, which we might have to revert", andit fixed the identical warning in
SparseMatrix::readwithwhile taking the
#ifdefroute here. Both are consuming functions; only one ofthe two sites kept its work. (The commit message's worry is moot —
stdinc.hhas required C++17 since PR #60.)
The test
src/test/QuadMatrix.cppgives each quadrant a distinct entry, writes, readsback and compares all four, so an empty quadrant and a quadrant holding
another's data are both visible.
That asymmetry is the bug stated as a test. Note the gap was never the build
matrix — the pre-PR #80 cmake job set no
CMAKE_BUILD_TYPEat all, so it builtthis broken path too. Nothing exercised
QuadMatrix::read.Verification
both pass, 247/247 each.
.brmatand.rbrmatoncyclic5-1,-2,-5and-9— six comparisons, none differing.fix, so Debug was the correct side.
make distcheckpasses with the new test in the tarball.
Scope
320c4a5added exactly two#ifdef MATHICGB_DEBUGblocks. The other, atsrc/test/gb-test.cpp:251, wrapsReducer::ReducerType(reducerType)— a purecast, so nothing is lost when it compiles out. It is left alone. The remaining
#ifdef MATHICGB_DEBUGblocks undersrc/mathicgb/wrap asserts and debug-onlyhelpers, not work the release build needs.
This is reachable only through
mgb matrix, which aborted before it could showany of this until PR #74 — which is why a 2022 bug surfaces now.
🤖 Generated with Claude Code