Skip to content

fix(eigen): reject strides that are not a multiple of the scalar size - #6164

Open
henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:fix/eigen-nondivisible-stride
Open

fix(eigen): reject strides that are not a multiple of the scalar size#6164
henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:fix/eigen-nondivisible-stride

Conversation

@henryiii

@henryiii henryiii commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

EigenProps::conformable divided the numpy byte strides by sizeof(Scalar) with integer
division. 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 a
stride of 9 bytes) was thus seen as contiguous, and a mutable Eigen::Ref read and wrote the
neighbouring field.

The conformability result now records such strides. A mutable Eigen::Ref refuses the array, and
by-value and const Ref arguments copy it, as they already do for negative strides.

Fixes item 5 of #6159.

Suggested changelog entry:

  • Fixed Eigen matrix casters accepting numpy arrays whose stride is not a multiple of the scalar
    size, which let a mutable Eigen::Ref corrupt neighbouring data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant