public static void Main(string [] args) { var x = new FloatTensor(10); var b = new FloatTensor(10); b.Fill(30); Dump(b); x.Random(new RandomGenerator(), 10); FloatTensor.Add(x, 100, b); Dump(x); Dump(b); #if false Dump(x); var y = x.Add(100); Dump(y); #endif for (int i = 0; i < 1000; i++) { using (var a = new FloatTensor(1000)){ using (var c = new FloatTensor(1000)) { var d = a.Add(10); a.CAdd(0, d); d.Dispose(); } } } }
public void TestPoissonNLLLoss2() { using (TorchTensor input = FloatTensor.Random(new long[] { 5, 2 })) using (TorchTensor target = FloatTensor.Random(new long[] { 5, 2 })) { var outTensor = NN.LossFunction.PoissonNLL(true, true)(input, target); } }
public void TestPoissonNLLLoss2() { using (TorchTensor input = FloatTensor.Random(new long[] { 5, 2 })) using (TorchTensor target = FloatTensor.Random(new long[] { 5, 2 })) { Assert.IsNotNull(NN.LossFunction.PoissonNLL(true, true)(input, target)); } }
public void TestSetGrad() { var x = FloatTensor.Random(new long[] { 10, 10 }); Assert.False(x.IsGradRequired); x.RequiresGrad(true); Assert.True(x.IsGradRequired); x.RequiresGrad(false); Assert.False(x.IsGradRequired); }
public void RandomTest() { var res = FloatTensor.Random(new long[] { 2 }); Assert.Equal(new long[] { 2 }, res.Shape); var res1 = ShortTensor.RandomIntegers(10, new long[] { 200 }); Assert.Equal(new long[] { 200 }, res1.Shape); var res2 = IntTensor.RandomIntegers(10, new long[] { 200 }); Assert.Equal(new long[] { 200 }, res2.Shape); var res3 = LongTensor.RandomIntegers(10, new long[] { 200 }); Assert.Equal(new long[] { 200 }, res3.Shape); var res4 = ByteTensor.RandomIntegers(10, new long[] { 200 }); Assert.Equal(new long[] { 200 }, res4.Shape); var res5 = SByteTensor.RandomIntegers(10, new long[] { 200 }); Assert.Equal(new long[] { 200 }, res5.Shape); var res6 = HalfTensor.RandomIntegers(10, new long[] { 200 }); Assert.Equal(new long[] { 200 }, res6.Shape); //var res7 = ComplexHalfTensor.RandomIntegers(10, new long[] { 200 }); //Assert.Equal(new long[] { 200 }, res7.Shape); //var res8 = ComplexFloatTensor.RandomIntegers(10, new long[] { 200 }); //Assert.Equal(new long[] { 200 }, res8.Shape); //var res9 = ComplexDoubleTensor.RandomIntegers(10, new long[] { 200 }); //Assert.Equal(new long[] { 200 }, res9.Shape); }