public void TestReshapeInt2DPointToTheSameStorage() { var x = IntTorchTensor.Create(5, 10); for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { int tmp = (int)(i + j); x[i, j] = tmp; } } Tensor <int> y = x.Reshape(new int[] { 10, 5 }); x[4, 9] = 0; y[3, 4] = 0; for (int i = 0; i < 1; i++) { for (int j = 0; j < 10; j++) { Assert.Equal(x[i, j], y[i * 2 + j / 5, j % 5]); } } }
public void TestReshapeInt1DFail() { Tensor <int> x = IntTorchTensor.Create(10); x.Fill((int)1); Assert.Throws <ArgumentException>(() => x.Reshape(new int[] { 9 })); }
public void TestShapeAndStridesInt4D() { var x = IntTorchTensor.Create(10, 10, 3, 10); for (int i = 0; i < 4; i++) { Assert.Equal(x.Dimensions[0], (int)x.TorchSharpTensor.GetTensorDimension(0)); Assert.Equal(x.Strides[0], (int)x.TorchSharpTensor.GetTensorStride(0)); } }
public void TestFillInt1D() { Tensor <int> x = IntTorchTensor.Create(10); x.Fill((int)30); for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(30, x[i]); } }
public void TestFillBySetInt1D() { Tensor <int> x = IntTorchTensor.Create(10); for (int i = 0; i < x.Dimensions[0]; i++) { x[i] = (int)30; } for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(x[i], (int)30); } }
public void TestCloneEmptyInt1D() { Tensor <int> x = IntTorchTensor.Create(10); x.Fill((int)1); Tensor <int> y = x.CloneEmpty(); Assert.Equal(y.Dimensions.ToArray(), x.Dimensions.ToArray()); for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(y[i], (int)0); } }
public void TestDanglingMemoryInt() { Memory <int> buffer; using (var x = IntTorchTensor.Create(10)) { x.Fill(33); buffer = x.Buffer; } var arr = buffer.ToArray(); for (int i = 0; i < 10; i++) { Assert.Equal(33, arr[i]); } }
public void TestReshapeInt2D() { var x = IntTorchTensor.Create(5, 10); var y = x.Reshape(new int[] { 10, 5 }); for (int i = 0; i < 2; i++) { Assert.Equal(x.Dimensions[0], (int)x.TorchSharpTensor.GetTensorDimension(0)); Assert.Equal(x.Strides[0], (int)x.TorchSharpTensor.GetTensorStride(0)); } Equals(x.Dimensions.ToArray(), new int[] { 5, 10 }); Equals(x.Strides.ToArray(), new int[] { 1, 10 }); Equals(y.Dimensions.ToArray(), new int[] { 10, 5 }); Equals(y.Strides.ToArray(), new int[] { 1, 5 }); }
public void TestReshapeInt1D() { Tensor <int> x = IntTorchTensor.Create(10); for (int i = 0; i < x.Dimensions[0]; i++) { x[i] = (int)i; } Tensor <int> y = x.Reshape(new int[] { 10 }); for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(y[i], (int)i); Assert.Equal(x[i], (int)i); } }
public void TestCloneInt1D() { Tensor <int> x = IntTorchTensor.Create(10); x.Fill((int)1); Tensor <int> y = x.Clone(); for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(x[i], y[i]); } y[5] = (int)0; Assert.NotEqual(x[5], y[5]); }
public void TestReshapeInt1DPointToTheSameStorage() { Tensor <int> x = IntTorchTensor.Create(10); for (int i = 0; i < x.Dimensions[0]; i++) { x[i] = (int)i; } Tensor <int> y = x.Reshape(new int[] { 10 }); y[5] = (int)0; for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(y[i], x[i]); } }
public void TestCloneInt2D() { Tensor <int> x = IntTorchTensor.Create(10, 10); x.Fill((int)1); Tensor <int> y = x.Clone(); for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { Assert.Equal(x[i, j], y[i, j]); } } y[5, 5] = (int)0; Assert.NotEqual(x[5, 5], y[5, 5]); }
public void TestFillBySetInt2D() { Tensor <int> x = IntTorchTensor.Create(10, 10); for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { x[i, j] = (int)30; } } for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { Assert.Equal(x[i, j], (int)30); } } }
public void TestFillEquivalanceInt2D() { var x = IntTorchTensor.Create(10, 10); for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { int tmp = (int)(i + j); x[i, j] = tmp; } } for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { Assert.Equal(x[i, j], x.TorchSharpTensor[i, j]); } } }
public void TestCreationInt4D() { Tensor <int> x = IntTorchTensor.Create(10, 10, 3, 10); Assert.NotNull(x); }
public void TestCreationInt0D() { Assert.Throws <ArgumentOutOfRangeException>(() => IntTorchTensor.Create()); }