Skip to content

Commit

Permalink
fixed last stack errors (#111390)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgsharp authored Jan 15, 2025
1 parent 8dcee50 commit e7788c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3501,7 +3501,7 @@ public static ref readonly TensorSpan<T> StackAlongDimension<T>(scoped ReadOnlyS
{
outputs[i] = Tensor.Unsqueeze(tensors[i], dimension);
}
return ref Tensor.ConcatenateOnDimension<T>(dimension, tensors, destination);
return ref Tensor.ConcatenateOnDimension<T>(dimension, outputs, destination);
}
#endregion

Expand Down
23 changes: 22 additions & 1 deletion src/libraries/System.Numerics.Tensors/tests/TensorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ public static void TensorSetSliceTests()
Assert.Equal(13, t0[1, 3]);
Assert.Equal(14, t0[1, 4]);
}

[Fact]
public static void TensorStackTests()
{
Expand Down Expand Up @@ -1075,7 +1076,7 @@ public static void TensorStackTests()
Assert.Equal(9, resultTensor[1, 4, 0]);
Assert.Equal(9, resultTensor[1, 4, 1]);

// stacking 2x2 tensors along dimention 1
// stacking 2x2 tensors along dimension 1
Tensor<int> v1 = Tensor.Create([1, 2, 3, 4], [2, 2]);
Tensor<int> v2 = Tensor.Create([10, 20, 30, 40], [2, 2]);

Expand All @@ -1095,6 +1096,26 @@ public static void TensorStackTests()
Assert.Equal(4, resultTensor[1, 0, 1]);
Assert.Equal(30, resultTensor[1, 1, 0]);
Assert.Equal(40, resultTensor[1, 1, 1]);

resultTensor = Tensor.StackAlongDimension(0, [v1, v2]);

Tensor<int> resultTensor2 = Tensor.Create<int>([2, 2, 2]);
Tensor.StackAlongDimension([v1, v2], resultTensor2, 1);

Assert.Equal(3, resultTensor2.Rank);
Assert.Equal(2, resultTensor2.Lengths[0]);
Assert.Equal(2, resultTensor2.Lengths[1]);
Assert.Equal(2, resultTensor2.Lengths[2]);

Assert.Equal(1, resultTensor2[0, 0, 0]);
Assert.Equal(2, resultTensor2[0, 0, 1]);
Assert.Equal(10, resultTensor2[0, 1, 0]);
Assert.Equal(20, resultTensor2[0, 1, 1]);

Assert.Equal(3, resultTensor2[1, 0, 0]);
Assert.Equal(4, resultTensor2[1, 0, 1]);
Assert.Equal(30, resultTensor2[1, 1, 0]);
Assert.Equal(40, resultTensor2[1, 1, 1]);
}

[Fact]
Expand Down

0 comments on commit e7788c1

Please sign in to comment.