Skip to content

Validate from_slice/from_vec shapes and add stepped slice_assign#3615

Open
NahButch wants to merge 1 commit into
huggingface:mainfrom
NahButch:from-slice-validate
Open

Validate from_slice/from_vec shapes and add stepped slice_assign#3615
NahButch wants to merge 1 commit into
huggingface:mainfrom
NahButch:from-slice-validate

Conversation

@NahButch

@NahButch NahButch commented Jun 12, 2026

Copy link
Copy Markdown

from_slice and from_vec accepted shapes whose element count does not match the data length, building tensors whose shape lies about their storage; reads past the data then fail or silently misbehave later (#3534). Both now return Error::ShapeMismatch, while one-hole shape inference keeps working. This also turns silent mask-construction bugs of the #3582 family into immediate errors.

Adds slice_assign_with_step, the stepped counterpart of slice_assign matching Python's dst[start:end:step] = src semantics (#3095), built on the same mask/pad approach with zero-dilation along stepped dims; tests cover 1-D/2-D mixed steps, step-1 equivalence with slice_assign, and error cases.

Note: this implements the validation approach @pjdurden outlined on #3534 last month; happy to defer if that work is still in flight.

Fixes #3534
Fixes #3095

🤖 Generated with Claude Code

from_slice and from_vec accepted shapes whose element count does not
match the data length, building tensors whose shape lies about their
storage; reads past the data then fail or silently misbehave later
(huggingface#3534). Both now return Error::ShapeMismatch, while one-hole shape
inference keeps working. This also turns silent mask-construction bugs
of the huggingface#3582 family into immediate errors.

Adds slice_assign_with_step, the stepped counterpart of slice_assign
matching Python's dst[start:end:step] = src semantics (huggingface#3095), built
on the same mask/pad approach with zero-dilation along stepped dims.

Fixes huggingface#3534
Fixes huggingface#3095

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant