Skip to content

Clarify expected behavior of Tensor.SequenceEqual with non-dense spans #124112

@vcsjones

Description

@vcsjones

Given a non-dense ReadOnlyTensorSpan<T>, SequenceEqual will be false if the unobserved elements are not the same.

For example:

using System;
using System.Numerics.Tensors;

int[] d1 = [10, 20, 99, 99, 30, 40, 99, 99];
int[] d2 = [10, 20, 77, 77, 30, 40, 77, 77];

var ts1 = new ReadOnlyTensorSpan<int>(d1, [2, 2], [4, 1]);
var ts2 = new ReadOnlyTensorSpan<int>(d2, [2, 2], [4, 1]);

DumpTensorSpan(ts1);
DumpTensorSpan(ts2);

bool result = ts1.SequenceEqual(ts2);
Console.WriteLine($"SequenceEqual: {result}");

static void DumpTensorSpan<T>(ReadOnlyTensorSpan<T> span)
{
    Console.WriteLine($"Dense: {span.IsDense}");
    
    foreach (T x in span)
    {
        Console.Write($"{x}, ");
    }
    
    Console.WriteLine();
}

This will print

Dense: False
10, 20, 30, 40, 
Dense: False
10, 20, 30, 40, 
SequenceEqual: False

I am not sure if this is "by design" or not. If it is, the documentation may want to make a note of how non-dense spans behavior.

The unit tests for this appear to be commented out:

//public static void TensorSequenceEqualTests()

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions