Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ public static Tensor<T> Resize<T>(Tensor<T> tensor, ReadOnlySpan<nint> lengths)

if (tensor.IsDense)
{
ReadOnlySpan<T> span = MemoryMarshal.CreateSpan(ref Unsafe.Add(ref tensor.AsTensorSpan()._reference, tensor._start), tensor._values.Length - tensor._start);
ReadOnlySpan<T> span = MemoryMarshal.CreateSpan(ref tensor.AsReadOnlyTensorSpan()._reference, (int)tensor.FlattenedLength);
Span<T> ospan = MemoryMarshal.CreateSpan(ref output.AsTensorSpan()._reference, (int)output.FlattenedLength);
if (newSize >= span.Length)
{
Expand Down
39 changes: 39 additions & 0 deletions src/libraries/System.Numerics.Tensors/tests/TensorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,45 @@ public static void TensorResizeTests()
Assert.Equal(0, t1[1, 4]);
}

[Fact]
public static void TensorResizeWithStartTests()
{
Tensor<int> t0 = Tensor.Create([1, 2, 3, 4, 5, 6], start: 2, lengths: [4], strides: []);
Tensor<int> t1 = Tensor.Resize(t0, [4]);
Assert.Equal([4], t1.Lengths);
Assert.Equal(3, t1[0]);
Assert.Equal(4, t1[1]);
Assert.Equal(5, t1[2]);
Assert.Equal(6, t1[3]);

t1 = Tensor.Resize(t0, [6]);
Assert.Equal([6], t1.Lengths);
Assert.Equal(3, t1[0]);
Assert.Equal(4, t1[1]);
Assert.Equal(5, t1[2]);
Assert.Equal(6, t1[3]);
Assert.Equal(0, t1[4]);
Assert.Equal(0, t1[5]);

t1 = Tensor.Resize(t0, [2]);
Assert.Equal([2], t1.Lengths);
Assert.Equal(3, t1[0]);
Assert.Equal(4, t1[1]);

t1 = Tensor.Resize(t0, [1, 1]);
Assert.Equal([1, 1], t1.Lengths);
Assert.Equal(3, t1[0, 0]);

t1 = Tensor.Resize(t0, [2, 3]);
Assert.Equal([2, 3], t1.Lengths);
Assert.Equal(3, t1[0, 0]);
Assert.Equal(4, t1[0, 1]);
Assert.Equal(5, t1[0, 2]);
Assert.Equal(6, t1[1, 0]);
Assert.Equal(0, t1[1, 1]);
Assert.Equal(0, t1[1, 2]);
}

[Fact]
public static void TensorSplitTests()
{
Expand Down
Loading