private void TestTwoTensorInPlace <Tin>(Func <TorchTensor, TorchTensor, TorchTensor> tensorFunc, Func <Tin, Tin, Tin> scalarFunc) { var c1 = FloatTensor.Arange(0, 10, 1); var c2 = FloatTensor.Arange(10, 0, -1); var c3 = FloatTensor.Ones(new long[] { 10, 10 }); var x = c1 * c3; var xClone = x.Clone(); var y = c2 * c3; var z = tensorFunc(x, y); var xData = x.Data <Tin>(); var xCloneData = xClone.Data <Tin>(); var yData = y.Data <Tin>(); var zData = z.Data <Tin>(); Assert.True(xData == zData); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { Assert.Equal(zData[i + j], scalarFunc(xCloneData[i + j], yData[i + j])); } } }
private void TestOneTensor <Tin, Tout>(Func <TorchTensor, TorchTensor> tensorFunc, Func <Tin, Tout> scalarFunc) { var c1 = FloatTensor.Arange(0, 10, 1); var c2 = FloatTensor.Ones(new long[] { 10, 10 }); var x = c1 * c2; var y = tensorFunc(x); var xData = x.Data <Tin>(); var yData = y.Data <Tout>(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { Assert.Equal(yData[i + j], scalarFunc(xData[i + j])); } } }