You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit be7b579
Browse filesBrowse the repository at this point in the historyBrowse files
Fix tensor shape consistency and native-width traversal (dotnet#135060)
## Summary
Make tensor shape handling consistent across broadcasting, elementwise
operations, copies, equality, reshaping, axis operations, and views:
- Treat default rank-zero empty values as effective shape `[0]`, without
changing their stored `Rank`, `Lengths`, or `Strides`. Only redundant
leading singleton axes can be added or removed; explicit zero axes and
non-leading singleton axes remain significant. Stack and concatenate
interpret axes using the first input's effective shape.
- Fix all ten internal `Any` span kernels to traverse the input length
and handle empty inputs correctly.
- Keep empty view origins within source storage, handle zero-containing
shape products without intermediate overflow, and retain native-sized
counts and offsets instead of narrowing them prematurely.
- Preserve overlap-safe ordering for native-width dense copies.
Index-of-min/max reductions reuse `TensorPrimitives` for dense spans,
dense suffixes, and bounded gathered blocks, preserving first-NaN, tie,
signed-zero, and magnitude semantics.
- Share concatenation validation and copying, avoid revalidating
prepared stack inputs, and remove redundant shape comparisons after
alignment. Caller-supplied destinations retain shape and overlap
validation before writes.
This includes behavioral compatibility changes, not new public API. Some
formerly inconsistent shape combinations are now accepted or rejected
according to the shared rules. For example, default empty values can
explicitly broadcast to `[2, 0]`, while binary operations with `[0, 2]`
reject the incompatible trailing dimension. Unsupported overlapping
layouts and self-overlapping output layouts throw before writing. The
README and affected API remarks document the shape and storage
contracts; breaking-change documentation is required after merge.
## Validation
- Release build of the tensor solution passed across its target
frameworks.
- Full suites passed normally and with hardware intrinsics disabled:
**6,266 net11.0 tests and 200 net481 tests** per run, with no failures
or skips.
- Regression coverage includes default/ranked empties, leading-padding
alignment, dense and strided destinations, rejection before writes,
native-width logical counts, forced chunk boundaries, NaNs/ties, high
ranks, and protected-memory boundaries.
- Two consecutive independent shape/storage audit passes covered
**149,246 cases each**, with no failures; the second used software
intrinsics.
## Performance
Local BenchmarkDotNet comparisons used Windows x64, a Ryzen 9 7950X, and
the .NET 11 RC SDK/runtime.
For a native-width broadcast view with shape `[nint.MaxValue / 1024,
1024]`, strides `[0, 1]`, and a NaN at the end of the first dense
suffix, `IndexOfMax` measured **295 ns** with dense-suffix primitive
dispatch versus **4,050 ns** with an elementwise native-width fallback.
This compares dispatch strategies and early NaN termination, not full
traversal of a multi-gigabyte allocation or throughput against
upstream's length-narrowing path.
Concatenation, stack, and dispatch comparisons retained the same
allocation counts. Separate-process timings varied substantially and
some apparent regressions reversed with run order. A same-process
comparison using separately loaded assemblies measured row dispatch at
**326 -> 309 ns** for rank 2 and **351 -> 356 ns** for rank 6, within
measurement variability. No general throughput improvement is claimed
for the validation simplification or metadata snapshots.
> [!NOTE]
> This pull request was authored with assistance from GitHub Copilot.
Co-authored-by: Copilot App <[email protected]>
Copy file name to clipboardExpand all lines: src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Common/TensorPrimitives.IIndexOfMinMaxOperator.cs
Copy file name to clipboardExpand all lines: src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionSpan_1.cs
+11-3Lines changed: 11 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -18,16 +18,24 @@ public readonly ref struct ReadOnlyTensorDimensionSpan<T>
0 commit comments