Repository navigation
Fix sparse matrix subtraction - #4771
Open
diracdeltafunk wants to merge 3 commits into
Open
diracdeltafunk wants to merge 3 commits into
diracdeltafunk wants to merge 3 commits into
Conversation
Visit every node while negating a copied sparse column. The old loop skipped the last coefficient and dereferenced null for an empty column. Add engine tests for arithmetic and empty-column subtraction. Fixes Macaulay2#4707.
d-torrance
self-requested a review
October 31, 2026 13:19
d-torrance
requested changes
Oct 31, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
isn't |
dimpase
approved these changes
Oct 31, 2026
dimpase
left a comment
Contributor
There was a problem hiding this comment.
ok, but the NULL question ought to be sorted
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Thanks, changed to nullptr -- I think you're right that this is what you're supposed to do in C++. Claude identified some more NULLs that could be nullptrs in the codebase. I can ask Claude to hunt these down for another PR. |
4 of 12 tasks
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.
Description
vec_negate, whichsubtractInPlaceuses to negate each column of the matrix being subtracted, looped whilep->next != NULLinstead ofp != NULL. So it skipped the last stored entry of each column and crashed on an empty column. This broke subtraction of sparse mutable matrices:Before:
A - Bwas{{9}, {8}}, and subtracting the zero matrix crashed M2. After:{{5}, {8}}and{{7}, {11}}.Related issues and pull requests
Fixes #4707.
Testing
Built
M2-unit-testson macOS arm64. Added two engine tests: one forall coefficients being subtracted and one for an empty column. Against
the original code, the first failed and the second exited with SIGSEGV.
With the fix, both pass via CTest (
2/2).Also checked the example above in M2 and ran all 277 engine unit tests. The second commit adds the new test to the autotools build's
Makefile.files; I only built with CMake.Release notes
Fix incorrect sparse matrix subtraction and a crash on empty columns.
AI disclosure
Tools and models used: OpenAI Codex (GPT-6).
How AI was used, and on which parts: Codex investigated the bug, wrote
the fix and tests, ran the checks, and drafted this description.
How I verified the result: I looked at the code
License
Checklist
developmentbranch.