Skip to content

Add some additional Tensor APIs #117739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 18, 2025

Conversation

tannergooding
Copy link
Member

This resolves #117373, resolves #117372, resolves #117375

Copy link
Contributor

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

@tannergooding tannergooding force-pushed the fix-117373-117372-117375 branch from 5ee338d to 34139ac Compare July 17, 2025 03:16
@tannergooding tannergooding marked this pull request as ready for review July 17, 2025 05:20
@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 05:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces new factory methods (CreateFromShape/CreateFromShapeUninitialized), implements span-based GetSpan and TryGetSpan APIs across Tensor, TensorSpan, and ReadOnlyTensorSpan, adds TensorMarshal interop helpers, and cleans up unused usings.

  • Renamed static creation methods and updated all references and tests to CreateFromShape….
  • Added GetSpan/TryGetSpan overloads (with nint and NIndex) and corresponding unit tests.
  • Introduced TensorMarshal for creating tensor spans from raw memory.

Reviewed Changes

Copilot reviewed 59 out of 59 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/TensorTests.cs Renamed factory calls, added GetSpan/TryGetSpan tests
tests/TensorSpanTests.cs Added GetSpan/TryGetSpan tests for TensorSpan
src/.../Runtime/InteropServices/TensorMarshal.cs New interop API for creating tensor spans
src/.../Tensor_1.cs & related files Implemented GetSpan/TryGetSpan on Tensor, updated interface
src/.../ITensor_1.cs Updated interface to declare new span-based methods
Comments suppressed due to low confidence (2)

src/libraries/System.Numerics.Tensors/tests/TensorTests.cs:2913

  • Add test cases covering the GetSpan and TryGetSpan overloads that accept ReadOnlySpan<NIndex> to ensure the new NIndex-based APIs are exercised.
        public static void GetSpanTest()

src/libraries/System.Numerics.Tensors/src/System/Runtime/InteropServices/TensorMarshal.cs:21

  • Consider validating that lengths.Length == strides.Length (or providing a default stride when empty) to avoid constructing a TensorSpan with mismatched dimension metadata.
        public static TensorSpan<T> CreateTensorSpan<T>(scoped ref T data, nint dataLength, scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides, bool pinned)

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

If this missed the Preview 7 snap, we should backport into the branch.

@tannergooding
Copy link
Member Author

/ba-g unrelated wasm timeouts

@tannergooding tannergooding merged commit d757c03 into dotnet:main Jul 18, 2025
83 of 87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants