Skip to content

Tensor.StdDev does not handle non-contiguous input #110772

Description

@lilinus

Description

Tensor.StdDev does not handle non-contiguous input.

The method uses

Reproduction Steps

using System.Numerics.Tensors;

// Create 4x4 matrix with upper-left 2x2 matrix
var t = Tensor.Create<double>([4, 4]);
t[[0, 0]] = 1;
t[[0, 1]] = 1;
t[[1, 0]] = 1;
t[[1, 1]] = 1;

// Take slice of upper left 2x2 matrix
var t1 = t.Slice([0..2, 0..2]); // This makes a copy so it is contiguous
var t2 = t.AsReadOnlyTensorSpan().Slice([0..2, 0..2]); // Refers to original span, i.e. non-cotiguous.

// Should print 0 (StdDev of all ones)
Console.WriteLine(Tensor.StdDev<double>(t1));
Console.WriteLine(Tensor.StdDev<double>(t2));

Expected behavior

Both print statements should print 0.

Actual behavior

First print statement prints 0.
Second print throws: System.ArgumentException: 'Destination is too short. Arg_ParamName_Name'

Regression?

No response

Known Workarounds

No response

Configuration

.NET 9

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Numerics.Tensorsin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions