Commit 5379f2e
Release Manager
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes #12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes #12345". -->
Fixes [#40167](#40167). This PR
fixes a bug in `Matrix_mod2_dense._matrix_times_vector_` revealed in
[#40167](#40167), where the
parent of the resulting vector was incorrectly reused from the input
vector.
The regression was introduced in [PR
#37375](#37375), which added an
optimization to speed up matrix-vector multiplication when the matrix is
square and matches the vector dimension. However, it failed to account
for edge cases where the input vector's parent is not the full ambient
vector space—for example, when working with subspaces. In this case, we
can no longer assume that the ambient space is the vector's ambient
space.
In such cases, reusing the parent leads to incorrect coercion or a
result vector with an invalid parent space. This patch introduces an
explicit check: if the vector's parent is the full space `GF(2)^n`, it
is reused; otherwise, a default parent is constructed to ensure
correctness.
### Example (correct behavior restored)
```python
sage: M = Matrix(GF(2), [[1, 1], [0, 1]])
sage: v = vector(GF(2), [0, 1])
sage: V = span([v]) # one-dimensional subspace of GF(2)^2
sage: image_basis = [M * b for b in V.basis()]
sage: image = span(image_basis)
sage: image.basis() == [(1, 1)]
True # now returns True
```
### 📝 Checklist
<!-- Put an `x` in all the boxes that apply. -->
- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
### ⌛ Dependencies
<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - #12345: short description why this is a dependency -->
<!-- - #34567: ... -->
URL: #40176
Reported by: Aolong Li
Reviewer(s): Travis Scrimshaw
File tree
3 files changed
+18
-4
lines changed- build/pkgs/configure
- src/sage/matrix
3 files changed
+18
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
680 | 690 | | |
681 | 691 | | |
682 | | - | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
683 | 697 | | |
684 | 698 | | |
685 | 699 | | |
| |||
0 commit comments