Пример #1
0
        public void WriteAndReadByteTensorViaMemoryFile()
        {
            const int size = 10;

            var file = new Torch.IO.MemoryFile("rwb");

            Assert.IsNotNull(file);
            Assert.IsTrue(file.CanWrite);

            var tensor0 = new AtenSharp.ByteTensor(size);

            for (var i = 0; i < size; ++i)
            {
                tensor0[i] = (byte)i;
            }

            file.WriteTensor(tensor0);
            Assert.AreEqual(size * sizeof(byte), file.Position);
            file.Seek(0);

            var tensor1 = new AtenSharp.ByteTensor(size);
            var rd      = file.ReadTensor(tensor1);

            Assert.AreEqual(rd, size);
            Assert.AreEqual(size * sizeof(byte), file.Position);

            for (var i = 0; i < rd; ++i)
            {
                Assert.AreEqual(tensor1[i], tensor1[i]);
            }

            file.Close();
            Assert.IsFalse(file.IsOpen);
        }
Пример #2
0
        public void WriteAndReadDoublesViaMemoryFile()
        {
            var file = new Torch.IO.MemoryFile("rwb");

            Assert.IsNotNull(file);
            Assert.IsTrue(file.CanWrite);

            var data0 = new double[4];

            for (var i = 0; i < data0.Length; ++i)
            {
                data0[i] = (double)i;
            }
            file.WriteDoubles(data0);
            Assert.AreEqual(data0.Length * sizeof(double), file.Position);
            file.Seek(0);

            var data1 = new double[data0.Length];
            var rd    = file.ReadDoubles(data1, data0.Length);

            Assert.AreEqual(rd, data0.Length);
            Assert.AreEqual(data0.Length * sizeof(double), file.Position);

            for (var i = 0; i < rd; ++i)
            {
                Assert.AreEqual(data0[i], data1[i]);
            }
            file.Close();
            Assert.IsFalse(file.IsOpen);
        }
Пример #3
0
        public void WriteAndReadStorageDoublesViaMemoryFile()
        {
            const int size = 10;

            var file = new Torch.IO.MemoryFile("rwb");

            Assert.IsNotNull(file);
            Assert.IsTrue(file.CanWrite);

            var storage0 = new TorchSharp.DoubleTensor.DoubleStorage(size);

            for (var i = 0; i < size; ++i)
            {
                storage0[i] = (double)i;
            }

            file.WriteDoubles(storage0);
            Assert.AreEqual(size * sizeof(double), file.Position);
            file.Seek(0);

            var storage1 = new TorchSharp.DoubleTensor.DoubleStorage(size);
            var rd       = file.ReadDoubles(storage1);

            Assert.AreEqual(rd, size);
            Assert.AreEqual(size * sizeof(double), file.Position);

            for (var i = 0; i < rd; ++i)
            {
                Assert.AreEqual(storage0[i], storage1[i]);
            }

            file.Close();
            Assert.IsFalse(file.IsOpen);
        }
Пример #4
0
        public void WriteShortToMemoryFile()
        {
            var file = new Torch.IO.MemoryFile("wb");

            Assert.IsNotNull(file);
            Assert.IsTrue(file.CanWrite);
            file.Close();
            Assert.IsFalse(file.IsOpen);
        }
Пример #5
0
        public void CreateReadWritableMemoryFile()
        {
            var file = new Torch.IO.MemoryFile("rw");

            Assert.IsNotNull(file);
            Assert.IsTrue(file.CanRead);
            Assert.IsTrue(file.CanWrite);
            file.Close();
            Assert.IsFalse(file.IsOpen);
        }
Пример #6
0
        public void SeekToEndInMemoryFile()
        {
            var storage = new MemoryFile.CharStorage(256);

            Assert.IsNotNull(storage);
            storage.Fill(0);
            var file = new Torch.IO.MemoryFile(storage, "w");

            Assert.IsNotNull(file);
            Assert.IsFalse(file.CanRead);
            Assert.IsTrue(file.CanWrite);

            file.SeekEnd();
            Assert.AreEqual(255, file.Position);
            file.Close();
            Assert.IsFalse(file.IsOpen);
        }
Пример #7
0
        public void WriteAndReadDoubleViaMemoryFile()
        {
            var file = new Torch.IO.MemoryFile("rwb");

            Assert.IsNotNull(file);
            Assert.IsTrue(file.CanWrite);
            file.WriteDouble(13);
            file.WriteDouble(17);
            file.Seek(0);
            var rd = file.ReadDouble();

            Assert.AreEqual(13, rd);
            rd = file.ReadDouble();
            Assert.AreEqual(17, rd);
            file.Close();
            Assert.IsFalse(file.IsOpen);
        }