Skip to content

Conversation

@tannergooding
Copy link
Member

The formatting was previously incorrect, resulting in output similar to:

System.Numerics.Tensors.Tensor<Single>[System.Numerics.Tensors.TensorShape]{
[
  [ 1, 2, ],
  [ 3, 4, ]]}

The correct formatting is meant to be:

System.Numerics.Tensors.Tensor<Int32>[2, 2] {
  [1, 2],
  [3, 4]
}

Explicit tests validating various scenarios were added.

@Copilot Copilot AI review requested due to automatic review settings August 14, 2025 20:39
Copy link
Contributor

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 fixes the formatting of the ToString methods for tensor types to improve readability and provide better structured output. The previous implementation produced incorrectly formatted strings that were difficult to read, mixing type information with content formatting in an inconsistent way.

Key changes include:

  • Refactored ToString implementation to centralize formatting logic across all tensor types
  • Fixed shape representation to use comma-separated dimensions instead of TensorShape object representation
  • Added proper indentation and structure for multi-dimensional tensor content display

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs Simplified ToString methods to delegate to centralized formatting logic
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs Updated ToString methods to use centralized formatting with proper type name
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs Added comprehensive ToString overload with documentation and delegated to centralized logic
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs Complete rewrite of ToString formatting logic with proper indentation and structure
src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs Updated API surface to reflect new ToString method signatures
src/libraries/System.Numerics.Tensors/tests/TensorTests.cs Added comprehensive tests for ToString functionality across different scenarios
src/libraries/System.Numerics.Tensors/tests/TensorSpanTests.cs Added comprehensive tests for TensorSpan ToString functionality
src/libraries/System.Numerics.Tensors/tests/ReadOnlyTensorSpanTests.cs Added comprehensive tests for ReadOnlyTensorSpan ToString functionality

@dotnet-policy-service
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.

@jeffhandley
Copy link
Member

@artl93 FYI - I'm merging this for RC1 as it meets the bug bar.

@jeffhandley jeffhandley merged commit 7ba3876 into dotnet:main Aug 15, 2025
85 of 88 checks passed
@tannergooding tannergooding deleted the tensor-tostring branch August 15, 2025 22:07
@github-actions github-actions bot locked and limited conversation to collaborators Sep 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants