public void TestReshapeDouble2DPointToTheSameStorage() { var x = DoubleTorchTensor.Create(5, 10); for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { double tmp = (double)(i + j); x[i, j] = tmp; } } Tensor <double> 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 TestReshapeDouble1DFail() { Tensor <double> x = DoubleTorchTensor.Create(10); x.Fill((double)1); Assert.Throws <ArgumentException>(() => x.Reshape(new int[] { 9 })); }
public void TestShapeAndStridesDouble4D() { var x = DoubleTorchTensor.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 TestFillDouble1D() { Tensor <double> x = DoubleTorchTensor.Create(10); x.Fill((double)30); for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(30, x[i]); } }
public void TestFillBySetDouble1D() { Tensor <double> x = DoubleTorchTensor.Create(10); for (int i = 0; i < x.Dimensions[0]; i++) { x[i] = (double)30; } for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(x[i], (double)30); } }
public void TestCloneEmptyDouble1D() { Tensor <double> x = DoubleTorchTensor.Create(10); x.Fill((double)1); Tensor <double> y = x.CloneEmpty(); Assert.Equal(y.Dimensions.ToArray(), x.Dimensions.ToArray()); for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(y[i], (double)0); } }
public void TestDanglingMemoryDouble() { Memory <double> buffer; using (var x = DoubleTorchTensor.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 TestReshapeDouble2D() { var x = DoubleTorchTensor.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 TestReshapeDouble1D() { Tensor <double> x = DoubleTorchTensor.Create(10); for (int i = 0; i < x.Dimensions[0]; i++) { x[i] = (double)i; } Tensor <double> y = x.Reshape(new int[] { 10 }); for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(y[i], (double)i); Assert.Equal(x[i], (double)i); } }
public void TestCloneDouble1D() { Tensor <double> x = DoubleTorchTensor.Create(10); x.Fill((double)1); Tensor <double> y = x.Clone(); for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(x[i], y[i]); } y[5] = (double)0; Assert.NotEqual(x[5], y[5]); }
public void TestReshapeDouble1DPointToTheSameStorage() { Tensor <double> x = DoubleTorchTensor.Create(10); for (int i = 0; i < x.Dimensions[0]; i++) { x[i] = (double)i; } Tensor <double> y = x.Reshape(new int[] { 10 }); y[5] = (double)0; for (int i = 0; i < x.Dimensions[0]; i++) { Assert.Equal(y[i], x[i]); } }
public void TestFillBySetDouble2D() { Tensor <double> x = DoubleTorchTensor.Create(10, 10); for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { x[i, j] = (double)30; } } for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { Assert.Equal(x[i, j], (double)30); } } }
public void TestFillEquivalanceDouble2D() { var x = DoubleTorchTensor.Create(10, 10); for (int i = 0; i < x.Dimensions[0]; i++) { for (int j = 0; j < x.Dimensions[1]; j++) { double tmp = (double)(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 TestCreationDouble4D() { Tensor <double> x = DoubleTorchTensor.Create(10, 10, 3, 10); Assert.NotNull(x); }
public void TestCreationDouble0D() { Assert.Throws <ArgumentOutOfRangeException>(() => DoubleTorchTensor.Create()); }