Skip to content

[release/11.0-rc1] Fix duplicate _start offset in Tensor.Resize - #132472

Merged
tannergooding merged 1 commit into
release/11.0-rc1from
backport/pr-128511-to-release/11.0-rc1
Aug 19, 2026
Merged

[release/11.0-rc1] Fix duplicate _start offset in Tensor.Resize#132472
tannergooding merged 1 commit into
release/11.0-rc1from
backport/pr-128511-to-release/11.0-rc1

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Backport of #128511 to release/11.0-rc1.

Closes #128512

/cc @tannergooding @prozolic

Customer Impact

  • Customer reported
  • Found internally

Tensor.Resize returns incorrect values when resizing a dense tensor whose start is greater than zero. For example, resizing a tensor representing [3, 4, 5, 6] returns [5, 6, 0, 0] because the start offset is applied twice.

Regression

  • Yes
  • No

Introduced by #114927, which added the affected Tensor.Resize implementation.

Testing

Added TensorResizeWithStartTests covering tensors with a nonzero start when resizing to the same size, growing, shrinking, and changing rank. The original fix in #128511 completed CI successfully.

Risk

Low. The production change only removes the duplicate offset and uses the existing read-only tensor span and flattened length, matching the approach already used by Tensor.ResizeTo. No public API surface changes.

Note

This description was drafted with GitHub Copilot.

Closes #128512

This PR fix the offset used when creating a `ReadOnlySpan<T>` that
starts at `_start` in `Tensor.Resize`. `AsTensorSpan()._reference`
already includes the `_start` offset, so applying it again via
`Unsafe.Add` caused the span to start at the wrong position.

Changes:
- Remove `Unsafe.Add` when creating a `ReadOnlySpan<T>`
- Change from `tensor.AsTensorSpan` to `Tensor.AsReadOnlyTensorSpan` to
match `Tensor.ResizeTo`
- Use `(int)tensor.FlattenedLength` instead of `tensor._values.Length -
tensor._start`
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics-tensors
See info in area-owners.md if you want to be subscribed.

@artl93 artl93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression. Basic functionality along the lines of "we should do math right". Approved.

@tannergooding

Copy link
Copy Markdown
Member

/ba-g System.Net.HttpListener.Tests timeouts

@tannergooding
tannergooding merged commit 1c4703c into release/11.0-rc1 Aug 19, 2026
95 of 101 checks passed
@tannergooding
tannergooding deleted the backport/pr-128511-to-release/11.0-rc1 branch August 19, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants