Repository navigation
fix(eigen): reject strides that are not a multiple of the scalar size - #6164
Conversation
|
— codex on behalf of Ralf — I checked both cases below on with-GIL and free-threaded CPython 3.14.10 with NumPy 2.5.5.
Ralf has yet to review these findings. |
|
🤖 AI text below 🤖 I reproduced both points on CPython 3.14.7 with NumPy 2.5.5. Both are fixed in 7aa9acc.
The new assertions failed before the fix. I updated the PR description and the changelog entry. |
…ngth-1 axis A const Ref with fully dynamic strides got the source array back from ensure() and then failed the stride check. Force a copy in that case. This also lets such a Ref accept an array with negative strides. A stride that is not a multiple of the scalar size is now ignored on an axis of length 1, because that stride is never used. Assisted-by: ClaudeCode:claude-fable-5-2
7aa9acc to
fbb67b2
Compare
|
codex GPT-6.2-Sol ultra (I'll add a commit for the suggested test improvement): I’d approve PR #6164. Henry fixed both findings from the earlier review. A const Eigen One optional test improvement is to use Full CI passed for the current head. Clean local builds ran the focused Eigen pytest suite on CPython 3.14.10 with the GIL and free-threaded, with 45 passed and 12 SciPy-dependent skips in each. GitHub CI |
Use add_any so the packed matrix reaches Eigen's stride check instead of being refused earlier by the C-contiguous argument requirement.
🤖 AI text below 🤖
EigenProps::conformabledivided the numpy byte strides bysizeof(Scalar)with integerdivision. A stride that is not a whole number of scalars was truncated. A field of a packed
structured array (for example
np.zeros(4, dtype=[('a', 'f8'), ('b', 'i1')])['a'], which has astride of 9 bytes) was thus seen as contiguous, and a mutable
Eigen::Refread and wrote theneighbouring field.
The conformability result now records such strides. A mutable
Eigen::Refrefuses the array, andby-value and
const Refarguments copy it, as they already do for negative strides. The stride ofan axis of length 1 is not used, so it is not checked.
A
const Refwith fully dynamic strides (py::EigenDRef<const M>) did not copy, becausearray_t::ensurereturns the source array when the dtype is correct. The caster now forces acopy in that case. This also fixes the same failure for negative strides.
Fixes item 5 of #6159.
Suggested changelog entry:
size, which let a mutable
Eigen::Refcorrupt neighbouring data. AconstEigen::Refwith fully dynamic strides now copies such arrays, and arrays with negative strides, instead of
raising
TypeError.📚 Documentation preview 📚: https://pybind11--6164.org.readthedocs.build/