public void WriteAndReadDoubleTensorViaDiskFile() { const int size = 10; var file = new Torch.IO.DiskFile("test20.dat", "rwb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); var tensor0 = new AtenSharp.DoubleTensor(size); for (var i = 0; i < size; ++i) { tensor0[i] = (double)i; } file.WriteTensor(tensor0); Assert.AreEqual(size * sizeof(double), file.Position); file.Seek(0); var tensor1 = new AtenSharp.DoubleTensor(size); var rd = file.ReadTensor(tensor1); Assert.AreEqual(rd, size); Assert.AreEqual(size * sizeof(double), file.Position); for (var i = 0; i < rd; ++i) { Assert.AreEqual(tensor1[i], tensor1[i]); } file.Close(); Assert.IsFalse(file.IsOpen); }
public void WriteAndReadIntsViaDiskFile() { var file = new Torch.IO.DiskFile("test11.dat", "rwb"); file.UseNativeEndianEncoding(); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); Assert.IsTrue(file.IsBinary); var data0 = new int[4]; for (var i = 0; i < data0.Length; ++i) { data0[i] = i + 32000000; } file.WriteInts(data0); file.Flush(); Assert.AreEqual(data0.Length * sizeof(int), file.Position); file.Seek(0); var data1 = new int[data0.Length]; var rd = file.ReadInts(data1, data0.Length); Assert.AreEqual(rd, data0.Length); Assert.AreEqual(data0.Length * sizeof(int), file.Position); for (var i = 0; i < rd; ++i) { Assert.AreEqual(data0[i], data1[i]); } file.Close(); Assert.IsFalse(file.IsOpen); }
public void WriteAndReadDoublesViaDiskFile() { var file = new Torch.IO.DiskFile("test14.dat", "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); }
public void WriteAndReadStorageCharsViaDiskFile() { const int size = 10; var file = new Torch.IO.DiskFile("test15c.dat", "rwb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); var storage0 = new MemoryFile.CharStorage(size); for (var i = 0; i < size; ++i) { storage0[i] = (byte)i; } file.WriteChars(storage0); Assert.AreEqual(size * sizeof(byte), file.Position); file.Seek(0); var storage1 = new MemoryFile.CharStorage(size); var rd = file.ReadChars(storage1); Assert.AreEqual(rd, size); Assert.AreEqual(size * sizeof(byte), file.Position); for (var i = 0; i < rd; ++i) { Assert.AreEqual(storage0[i], storage1[i]); } file.Close(); Assert.IsFalse(file.IsOpen); }
public void WriteAndReadStorageDoublesViaDiskFile() { const int size = 10; var file = new Torch.IO.DiskFile("test1A.dat", "rwb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); var storage0 = new AtenSharp.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 AtenSharp.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); }
public void CreateReadWritableDiskFile() { var file = new Torch.IO.DiskFile("test2.dat", "rwb"); Assert.IsTrue(file.CanRead); Assert.IsTrue(file.CanWrite); Assert.IsTrue(file.IsBinary); file.Close(); Assert.IsFalse(file.IsOpen); }
public void WriteCharToDiskFile() { var file = new Torch.IO.DiskFile("test3c.dat", "wb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); file.WriteChar(17); file.Close(); Assert.IsFalse(file.IsOpen); }
public void CreateAutoSpacingDiskFile() { var file = new Torch.IO.DiskFile("test1as.dat", "w"); Assert.IsTrue(file.IsAutoSpacing); file.IsAutoSpacing = false; Assert.IsFalse(file.IsAutoSpacing); file.IsAutoSpacing = true; Assert.IsTrue(file.IsAutoSpacing); file.Close(); Assert.IsFalse(file.IsOpen); }
public void CreateQuietDiskFile() { var file = new Torch.IO.DiskFile("test1q.dat", "w"); Assert.IsFalse(file.IsQuiet); file.IsQuiet = true; Assert.IsTrue(file.IsQuiet); file.IsQuiet = false; Assert.IsFalse(file.IsQuiet); file.Close(); Assert.IsFalse(file.IsOpen); }
public void WriteAndReadShortViaDiskFile() { var file = new Torch.IO.DiskFile("test6.dat", "rwb"); Assert.IsNotNull(file); Assert.IsTrue(file.CanWrite); file.WriteShort(13); file.WriteShort(17); file.Seek(0); var rd = file.ReadShort(); Assert.AreEqual(13, rd); rd = file.ReadShort(); Assert.AreEqual(17, rd); }
public void WriteAndReadDoubleViaDiskFile() { var file = new Torch.IO.DiskFile("testE.dat", "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); }