dotnet / runtime

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

System.Numerics.Tensors Incorrect IndexOutOfRangeException on empty slice #106536

Open soerenwolfers opened 4 weeks ago

soerenwolfers commented 4 weeks ago

Description

new TensorSpan<double>(Array.Empty<double>()).Slice(new NRange[] { .. });

throws an IndexOutOfRangeException but should return an empty span.

Reproduction Steps

using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using System.Numerics.Tensors;

namespace ConsoleApp1;

public abstract class Program
{
    [Experimental("SYSLIB5001")]
    public static void Main()
    {
        new TensorSpan<double>(Array.Empty<double>()).Slice(new NRange[] { .. });
    }
}

Expected behavior

Empty span

Actual behavior

Exception

Regression?

No response

Known Workarounds

No response

Configuration

.Net8, Ubuntu22, x64

Other information

No response

dotnet-policy-service[bot] commented 4 weeks ago

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

dotnet-policy-service[bot] commented 4 weeks ago

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