Example #1
0
        public void TensorsThatShouldNotBeDisposedArent()
        {
            torch.Tensor data       = torch.rand(10, 10);
            torch.Tensor undisposed = null;
            using (var d = torch.NewDisposeScope()) {
                undisposed = d.MoveToOuter(data * data + data);
                Assert.False(undisposed.IsInvalid);
            }

            // One was kept
            Assert.False(undisposed.IsInvalid);
        }
Example #2
0
        public void TensorsCanBeDisposedInTheMiddleOfTheProcess()
        {
            torch.Tensor data = torch.rand(10, 10);
            torch.Tensor t1, t2;
            using (var d = torch.NewDisposeScope()) {
                t1 = data * data + data;
                t2 = data + data - t1;
                t2 = d.DisposeEverythingBut(t2);
                Assert.True(t1.IsInvalid);
                t2 = t2 + data;
            }

            Assert.True(t2.IsInvalid);
            Assert.False(data.IsInvalid);
        }
Example #3
0
        public void DisposeScopesCanBeNestled()
        {
            DisposeScopeManager.Statistics.Reset();
            torch.Tensor data = torch.rand(10, 10);
            using (torch.NewDisposeScope()) {
                var t1 = data * data + data;

                var innerCount = DisposeScopeManager.Statistics.ThreadTotalLiveCount;
                using (torch.NewDisposeScope()) {
                    var t2 = data + data - t1;
                }

                // Inner scope was disposed
                Assert.Equal(DisposeScopeManager.Statistics.ThreadTotalLiveCount, innerCount);
            }

            // It was all disposed
            Assert.Equal(0, DisposeScopeManager.Statistics.ThreadTotalLiveCount);
        }
Example #4
0
        public void TensorsAreDisposedCorrectly()
        {
            torch.Tensor data        = torch.rand(10, 10);
            var          disposables = new List <torch.Tensor>();

            using (var d = torch.NewDisposeScope()) {
                var newValue = data * data + data;
                disposables = d.DisposablesView.OfType <torch.Tensor>().ToList();
                foreach (var disposable in disposables)
                {
                    Assert.False(disposable.IsInvalid);
                }
            }

            // They were all disposed
            foreach (var disposable in disposables)
            {
                Assert.True(disposable.IsInvalid);
            }
        }
Example #5
0
 public override torch.Tensor forward(torch.Tensor t)
 {
     return(this.seq.forward(t));
 }
Example #6
0
 public override torch.Tensor forward(torch.Tensor t)
 {
     return(torch.matmul(t, Weight));
 }
Example #7
0
 public override torch.Tensor forward(torch.Tensor t) => bn1.forward(t);
Example #8
0
 public override torch.Tensor forward(torch.Tensor t) => t.clone();
Example #9
0
 public override torch.Tensor forward(torch.Tensor input)
 {
     throw new NotImplementedException();
 }