private static void WriteDataset(long f, string name, Tensor data) { switch (data.dtype) { case TF_DataType.TF_FLOAT: Hdf5.WriteDatasetFromArray <float>(f, name, data.numpy().ToMuliDimArray <float>()); break; case TF_DataType.TF_DOUBLE: Hdf5.WriteDatasetFromArray <double>(f, name, data.numpy().ToMuliDimArray <double>()); break; case TF_DataType.TF_INT32: Hdf5.WriteDatasetFromArray <int>(f, name, data.numpy().ToMuliDimArray <int>()); break; case TF_DataType.TF_INT64: Hdf5.WriteDatasetFromArray <long>(f, name, data.numpy().ToMuliDimArray <long>()); break; default: Hdf5.WriteDatasetFromArray <float>(f, name, data.numpy().ToMuliDimArray <float>()); break; } }
private long WriteDataset(string filename) { long tef2 = Hdf5.CreateFile(filename); int[] blah = { 1, 2, 4, 5, 0 }; Hdf5.WriteDatasetFromArray <int>(tef2, "blah", blah); Hdf5.CloseFile(tef2); var what = "???"; // breakpoint in VS to test h5 file contents independently before next write step tef2 = Hdf5.OpenFile(filename); blah[4] = 6; Hdf5.WriteDatasetFromArray <int>(tef2, "blah", blah); // This command throws several debug errors from PInvoke var(success, result) = Hdf5.ReadDataset <int>(tef2, "blah"); Assert.IsTrue(success); Assert.IsTrue(result.Cast <int>().SequenceEqual(blah)); // loading the hdf5 file shows it only has {1, 2, 4, 5, 0} stored. return(tef2); }
public void OverrideDataset() { string filename1 = "overridedataset1.h5"; long id = WriteDataset(filename1); FileInfo fi = new FileInfo(filename1); var l1 = fi.Length; Hdf5.CloseFile(id); File.Delete(filename1); string filename = "overridedataset.h5"; Hdf5.Settings.EnableErrorReporting(true); Hdf5.Settings.OverrideExistingData = true; long tef2 = Hdf5.CreateFile(filename); int[] blah = { 1, 2, 4, 5, 0 }; Hdf5.WriteDatasetFromArray <int>(tef2, "blah", blah); Hdf5.CloseFile(tef2); var what = "???"; // breakpoint in VS to test h5 file contents independently before next write step tef2 = Hdf5.OpenFile(filename); for (int i = 0; i < 10; i++) { blah[4] = i + i; Hdf5.WriteDatasetFromArray <int>(tef2, "blah", blah); } var(success, result) = Hdf5.ReadDataset <int>(tef2, "blah"); Assert.IsTrue(success); Assert.IsTrue(result.Cast <int>().SequenceEqual(blah)); FileInfo fi2 = new FileInfo(filename); var l2 = fi.Length; Hdf5.CloseFile(tef2); File.Delete(filename); Assert.IsTrue(l1 == l2); }
public void OverrideAndIncreaseDataset() { string filename = "overrideandincreasedataset.h5"; Hdf5.Settings.EnableErrorReporting(true); Hdf5.Settings.OverrideExistingData = true; long id = Hdf5.CreateFile(filename); int[] d1 = { 1, 2, 3, 4, 5 }; int[] d2 = { 11, 12, 13, 14, 15 }; Hdf5.WriteDatasetFromArray <int>(id, "d1", d1); Hdf5.WriteDatasetFromArray <int>(id, "d2", d2); Hdf5.CloseFile(id); id = Hdf5.OpenFile(filename); var(success, result) = Hdf5.ReadDataset <int>(id, "d1"); var(success1, result2) = Hdf5.ReadDataset <int>(id, "d2"); Hdf5.CloseFile(id); int[] d3 = { 21, 22, 24, 25, 26, 27, 28, 29, 210 }; Assert.IsTrue(success); Assert.IsTrue(result.Cast <int>().SequenceEqual(d1)); Assert.IsTrue(success1); Assert.IsTrue(result2.Cast <int>().SequenceEqual(d2)); id = Hdf5.OpenFile(filename); Hdf5.WriteDatasetFromArray <int>(id, "d1", d3); Hdf5.CloseFile(id); id = Hdf5.OpenFile(filename); var(success3, result3) = Hdf5.ReadDataset <int>(id, "d1"); var(success4, result4) = Hdf5.ReadDataset <int>(id, "d2"); Hdf5.CloseFile(id); Assert.IsTrue(success3); Assert.IsTrue(result3.Cast <int>().SequenceEqual(d3)); Assert.IsTrue(success4); Assert.IsTrue(result4.Cast <int>().SequenceEqual(d2)); }