Macaulay2 / Macaulay2/M2

SMat equality ignores sparse row positions and unequal list lengths

Open Beginner friendly
#4,706 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Engine
Dominant language
Macaulay2
Stars
435
Forks
297
Avg merge
4d 20h
Merged PRs (30d)
11

Description

`SMat::is_equal` can return true for matrices with different sparse supports. In `Macaulay2/e/basic-mutable-matrices/smat.hpp`, `vec_equals` compares coefficients but does not compare row indices or check that both lists end together.

The following direct engine C++ examples use `SMat` over ZZ/101. Each pair has shape 3 x 1 and must compare unequal:

| Left column (top to bottom) | Right column | Actual `is_equal` |
| --- | --- | --- |
| `[0, 0, 0]` | `[2, 0, 0]` | `true` |
| `[2, 0, 0]` | `[0, 2, 0]` | `true` |
| `[0, 2, 0]` | `[3, 2, 0]` | `true` |

Minimal C++ reproduction (inside the engine unit-test harness):

```cpp
M2::ARingZZp ring(101);
SMat left(ring, 3, 1), right(ring, 3, 1);
M2::ARingZZp::Element two(ring);
ring.set(two, 2);
left.set_entry(0, 0, two);
right.set_entry(1, 0, two);
EXPECT_FALSE(left.is_equal(right)); // fails: actual is true
```

All three cases were reproduced with a Debug CMake engine build on macOS arm64. The production header was unchanged. Equality should compare row positions, coefficients, and the lengths of the sparse lists. This was found while adding dedicated SMat engine unit tests.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Macaulay2/e/basic-mutable-matrices/smat.hpp, at SMat::is_equal and its vec_equals helper. Run the engine unit-test harness with the provided ZZ/101 sparse-matrix examples, then verify that equality accounts for row positions, coefficients, and matching sparse-list lengths.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.