public void WriteAndReadLongsViaMemoryFile() { var file = new Torch.IO.MemoryFile("rwb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); var data0 = new long[4]; for (var i = 0; i < data0.Length; ++i) { data0[i] = i; } file.WriteLongs(data0); Assert.AreEqual(data0.Length * sizeof(long), file.Position); file.Seek(0); var data1 = new long[data0.Length]; var rd = file.ReadLongs(data1, data0.Length); Assert.AreEqual(rd, data0.Length); Assert.AreEqual(data0.Length * sizeof(long), file.Position); for (var i = 0; i < rd; ++i) { Assert.AreEqual(data0[i], data1[i]); } file.Close(); Assert.IsFalse(file.IsOpen); }
public void WriteAndReadStorageLongsViaMemoryFile() { const int size = 10; var file = new Torch.IO.MemoryFile("rwb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); var storage0 = new TorchSharp.LongTensor.LongStorage(size); for (var i = 0; i < size; ++i) { storage0[i] = i; } file.WriteLongs(storage0); Assert.AreEqual(size * sizeof(long), file.Position); file.Seek(0); var storage1 = new TorchSharp.LongTensor.LongStorage(size); var rd = file.ReadLongs(storage1); Assert.AreEqual(rd, size); Assert.AreEqual(size * sizeof(long), file.Position); for (var i = 0; i < rd; ++i) { Assert.AreEqual(storage0[i], storage1[i]); } file.Close(); Assert.IsFalse(file.IsOpen); }