public void Elements() { using (H5File hf = H5File.Open(testfile, mode: "r")) { using (dset1d <int> DSET = hf.Root["datasets/int1d"] as dset1d <int>) { Assert.NotNull(DSET); var actual = DSET.Elements().ToArray(); var expected = new int[] { 0, 1, 2, 3, 4, 5, 6 }; Assert.Equal(expected, actual); } using (dset2d <int> DSET = hf.Root["datasets/int2d"] as dset2d <int>) { Assert.NotNull(DSET); var actual = DSET.Elements().Skip(5 * 7 + 4).Take(7).ToArray(); var expected = new int[7] { 0, 25, 0, 0, 1, 4, 9 }; Assert.Equal(expected, actual); } } }
public void float2d_To2dArray() { using (H5File hf = H5File.Open(testfile, mode: "r")) { dset2d <float> DSET = hf.Root["datasets/float2d"] as dset2d <float>; Assert.NotNull(DSET); Assert.Equal(Square, DSET.Length); var expect = new float[7, 7] { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0, 0 }, { 0, 0, 4, 0, 0, 0, 0 }, { 0, 0, 0, 9, 0, 0, 0 }, { 0, 0, 0, 0, 16, 0, 0 }, { 0, 0, 0, 0, 0, 25, 0 }, { 0, 1, 4, 9, 16, 25, 36 }, }; var actual = DSET.Values; for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { Assert.Equal(expect[i, j], actual[i, j]); } } } }
public void double2d_Arrays() { using (H5File hf = H5File.Open(testfile, mode: "r")) { dset2d <double> DSET = hf.Root["datasets/double2d"] as dset2d <double>; Assert.NotNull(DSET); Assert.Equal(Square, DSET.Length); Assert.Equal(new double[] { 0, 0, 4, 0, 0, 0, 0 }, DSET.Row(2)); Assert.Equal(new double[] { 0, 0, 0, 9, 0, 0, 0 }, DSET.Row(3)); Assert.Equal(new double[] { 0, 0, 0, 0, 0, 25, 0 }, DSET.Row(5)); Assert.Equal(new double[] { 0, 1, 4, 9, 16, 25, 36 }, DSET.Row(6)); Assert.Equal(new double[] { 0, 0, 4, 0, 0, 0, 4 }, DSET.Column(2)); Assert.Equal(new double[] { 0, 0, 0, 9, 0, 0, 9 }, DSET.Column(3)); Assert.Equal(new double[] { 0, 0, 0, 0, 0, 25, 25 }, DSET.Column(5)); Assert.Equal(new double[] { 0, 0, 0, 0, 0, 0, 36 }, DSET.Column(6)); Assert.Throws <IndexOutOfRangeException>(() => DSET.Row(7)); Assert.Throws <IndexOutOfRangeException>(() => DSET.Row(17)); Assert.Throws <IndexOutOfRangeException>(() => DSET.Row(-1)); Assert.Throws <IndexOutOfRangeException>(() => DSET.Column(7)); Assert.Throws <IndexOutOfRangeException>(() => DSET.Column(17)); Assert.Throws <IndexOutOfRangeException>(() => DSET.Column(-1)); } }
public void Cols() { int[][] expected = { new int[] { 0, 0, 0, 0, 0, 0, 0 }, new int[] { 0, 1, 0, 0, 0, 0, 1 }, new int[] { 0, 0, 4, 0, 0, 0, 4 }, new int[] { 0, 0, 0, 9, 0, 0, 9 }, new int[] { 0, 0, 0, 0, 16, 0, 16 }, new int[] { 0, 0, 0, 0, 0, 25, 25 }, new int[] { 0, 0, 0, 0, 0, 0, 36 }, }; using (H5File hf = H5File.Open(testfile, mode: "r")) { dset2d <int> DSET = hf.Root["datasets/int2d"] as dset2d <int>; Assert.NotNull(DSET); int index = 0; foreach (int[] actual in DSET.Columns()) { Assert.Equal(expected[index], actual); index += 1; } Assert.Equal(7, index); // manual testing.. var iterator = DSET.Columns().GetEnumerator(); Assert.True(iterator.MoveNext()); // init ~> 0 Assert.True(iterator.MoveNext()); // 1 Assert.True(iterator.MoveNext()); // 2 Assert.Equal(expected[2], iterator.Current); iterator.Reset(); Assert.True(iterator.MoveNext()); // 0 Assert.Equal(expected[0], iterator.Current); iterator.Dispose(); } }
public void double2d() { using (H5File hf = H5File.Open(testfile, mode: "r")) { dset2d <double> DSET = hf.Root["datasets/double2d"] as dset2d <double>; Assert.NotNull(DSET); Assert.Equal(Square, DSET.Length); Assert.Equal(typeof(double), DSET.PrimitiveType); double[] expected = new double[] { 0, 1, 4, 9, 16, 25, 36 }; double[] actual = new double[Edge]; for (long i = 0; i < DSET.Dims[0]; i++) { actual[i] = DSET[i, i]; } Assert.Equal(expected, actual); } }
public void double2d() { using (var container = new TempH5FileContainer()) { H5Group ROOT = container.Content().Root; int rank = 2; var dims = new long[] { 3, 2 }; using (dset2d <double> DSET = ROOT.CreateDataset("dataset", rank, dims, typeof(double)) as dset2d <double>) { Assert.NotNull(DSET); Assert.Equal(dims, DSET.Dims); DSET[0, 0] = 3.14; DSET[2, 1] = 3.14; DSET[1] = new double[] { 1.2, 3.4 }; Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 0]); Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 0] = 3.14); Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 2]); Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 2] = 3.14); Assert.Throws <IndexOutOfRangeException>(() => DSET[1, 7]); Assert.Throws <IndexOutOfRangeException>(() => DSET[1, 7] = 3.14); Assert.Throws <IndexOutOfRangeException>(() => DSET[1, -3]); Assert.Throws <IndexOutOfRangeException>(() => DSET[1, -3] = 3.14); Assert.Throws <IndexOutOfRangeException>(() => DSET[3]); Assert.Throws <IndexOutOfRangeException>(() => DSET[3] = new double[] { 1.0, 2.0 }); Assert.Throws <IndexOutOfRangeException>(() => DSET[-1]); Assert.Throws <IndexOutOfRangeException>(() => DSET[-1] = new double[] { 1.0, 2.0 }); Assert.Throws <IndexOutOfRangeException>(() => DSET[0] = new double[] { 1.0, 2.0, 3.0 }); } } }
public void TestAdvancedInjection() { using (var container = new TempH5FileContainer()) { H5File hf = container.Content(); using (MyObject myo = new MyObject(hf.Root)) { Assert.True(H5Link.Exists(hf.Root.ID, "alternative_path")); dset2d <float> dset = myo.advancedset as dset2d <float>; Assert.NotNull(dset); Assert.Equal(2, dset.Rank); Assert.Equal(new long[] { 3, 5 }, dset.Dims); Assert.Equal(15L, dset.Length); Assert.Equal(new float[5], dset[2]); if (H5Library.LibVersion == "1.8.12") { Assert.Throws <NotImplementedException>(() => dset.Resize(new long[] { 6, 9 })); } else { dset.Resize(new long[] { 6, 5 }); Assert.Equal(30L, dset.Length); dset[5] = new float[5] { 1, 2, 3, 4, 5 }; dset.Resize(new long[] { 6, 9 }); dset[3] = new float[9] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; } } } }
public void float2d() { using (var Container = new TempH5FileContainer()) { var hf = Container.Content(); var dims = new long[] { 3L, 5L }; dset2d <float> DSET = hf.Root.CreateDataset("tempdata", 2, dims, typeof(float)) as dset2d <float>; Assert.NotNull(DSET); Assert.Equal(dims, DSET.Dims); var expect = new float[3, 5] { { 0, 0, 2, 0, 5 }, { 1, 3, 0, 8, 9 }, { 4, 0, 7, 0, 2 }, }; DSET.Values = expect; var actual = DSET.Values; for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { Assert.Equal(expect[i, j], actual[i, j]); } } Assert.Throws <InvalidOperationException>(() => DSET.Values = new float[1, 1]); Assert.Throws <InvalidOperationException>(() => DSET.Values = new float[1, 5]); DSET.Dispose(); } }