Fix non-dense TensorSpan handling in SequenceEqual, Fill*, Resize*, and IndexOf* methods#124225
Fix non-dense TensorSpan handling in SequenceEqual, Fill*, Resize*, and IndexOf* methods#124225
Conversation
…or spans Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/area-system-numerics-tensors |
There was a problem hiding this comment.
Pull request overview
Fixes Tensor.SequenceEqual / TensorSpan.SequenceEqual so that comparisons involving non-dense tensor spans compare only the logical elements (ignoring unobserved gap/padding in the underlying buffer), while preserving the dense fast-path.
Changes:
- Updated
ReadOnlyTensorSpan<T>.SequenceEqualto use a dense fast-path and a non-dense element-by-element slow-path. - Simplified the
TensorSpan<T>overload to delegate to theReadOnlyTensorSpan<T>implementation. - Added unit tests covering non-dense vs non-dense, dense vs non-dense (both directions), differing logical elements, and the
TensorSpan<T>overload.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs | Fixes SequenceEqual semantics for non-dense spans and centralizes logic via the ReadOnlyTensorSpan<T> overload. |
| src/libraries/System.Numerics.Tensors/tests/TensorTests.cs | Adds regression tests validating correct SequenceEqual behavior across dense/non-dense scenarios. |
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs
Show resolved
Hide resolved
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs
Outdated
Show resolved
Hide resolved
|
@copilot do other methods have the same or similar problem? e.g. IndexOf*, ResizeTo, Fill*, etc.? Please investigate and fix any other similar problems in the whole library. |
…dd tests Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Investigated all methods in the library that use
Methods using |
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs
Show resolved
Hide resolved
…theories Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
@copilot invoke the code-review skill and post your analysis/results as a comment on this PR |
|
@copilot invoke the code-review skill and post your analysis/results as a comment on this PR |
🤖 Copilot Code Review — PR #123681Holistic AssessmentMotivation: The PR fixes a real correctness bug. Multiple Approach: The Summary: Detailed Findings
|
This is still an issue. |
SequenceEqualfor non-dense tensor spansFillGaussianNormalDistribution,FillUniformDistribution,Resize,ResizeTo,IndexOfMax,IndexOfMin,IndexOfMaxMagnitude,IndexOfMinMagnitudefor non-dense spansFlattenedLengthinstead of_shape.LinearLengthin dense fast-pathsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.