dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.98k stars 4.66k forks source link

Tensor.ReverseDimension on sliced TensorSpan sometimes produces invalid results #107707

Open JaThePlayer opened 1 week ago

JaThePlayer commented 1 week ago

Description

Using Tensor.ReverseDimension(slice, dimension) on a TensorSpan created via TensorSpan.Slice creates a tensor with partially invalid values - in this case, the source tensor has no '0' values, but the result has two of them.

Reproduction Steps

var t = Tensor.Create([1,2,3, 4,5,6, 7,8,9], [3, 3]);

var slice = t.AsTensorSpan().Slice([0..3, 1..3]);

var reversed = Tensor.ReverseDimension<int>(slice, 0);
Console.WriteLine(reversed.ToString([]));

Expected behavior

Program prints

[3x2], type = System.Int32, isPinned = False
{                                           
{8,9}                                       
{5,6}                                       
{2,3}                                       
} 

Actual behavior

Program prints

[3x2], type = System.Int32, isPinned = False
{                                           
{8,9}                                       
{0,5}                                       
{6,0}                                       
}

Regression?

No response

Known Workarounds

Using the copying Tensor.Slice method instead works.

Configuration

.NET version: 9.0.100-rc.1.24452.12 OS: Windows 10 Education 22H2 Architecture: x64 (Intel Core i7-7700)

Other information

No response

dotnet-policy-service[bot] commented 1 week ago

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