@Test public void testConstructor() { double[] da = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; DoubleDataset a = new DoubleDataset(da); IndexIterator it = a.getIterator(); for (int i = 0; it.hasNext(); i++) { assertEquals(i, a.getElementDoubleAbs(it.index), 1e-5 * i); } DoubleDataset b = new DoubleDataset(da, 3, 4); it = b.getIterator(); for (int i = 0; it.hasNext(); i++) { assertEquals(i, b.getElementDoubleAbs(it.index), 1e-5 * i); } DoubleDataset c = new DoubleDataset(a.getSliceView(new int[] {1}, null, new int[] {2})); it = c.getIterator(); for (int i = 0; it.hasNext(); i++) { assertEquals(2 * i + 1, c.getElementDoubleAbs(it.index), 1e-5 * i); } // test hashes a.hashCode(); b.hashCode(); c.hashCode(); }
@Test public void testCreators() { double dz = 0.5; DoubleDataset z = DoubleDataset.createFromObject(dz); assertEquals(0, z.getRank()); assertEquals(1, z.getSize()); assertEquals(dz, z.getElementDoubleAbs(0), 1e-14); double[] da = {0, 1, 2, 3, 4, 5}; DoubleDataset a = DoubleDataset.createFromObject(da); assertEquals(1, a.getRank()); assertEquals(6, a.getSize()); assertEquals(6, a.getShape()[0]); IndexIterator it = a.getIterator(); for (int i = 0; it.hasNext(); i++) { assertEquals(i, a.getElementDoubleAbs(it.index), 1e-15 * i); } double[][] db = {{0, 1, 2}, {3, 4, 5}}; DoubleDataset b = DoubleDataset.createFromObject(db); assertEquals(2, b.getRank()); assertEquals(6, b.getSize()); assertEquals(2, b.getShape()[0]); assertEquals(3, b.getShape()[1]); it = b.getIterator(); for (int i = 0; it.hasNext(); i++) { assertEquals(i, b.getElementDoubleAbs(it.index), 1e-15 * i); } double[][] dc = {{0, 1, 2, 3}, {4, 5, 6}}; DoubleDataset c = DoubleDataset.createFromObject(dc); assertEquals(2, c.getRank()); assertEquals(8, c.getSize()); assertEquals(2, c.getShape()[0]); assertEquals(4, c.getShape()[1]); it = c.getIterator(); for (int i = 0; it.hasNext(); i++) { if (i < 7) assertEquals(i, c.getElementDoubleAbs(it.index), 1e-15 * i); else assertEquals(0, c.getElementDoubleAbs(it.index), 1e-15); } double[][] dd = {{0, 1, 2}, {4, 5, 6, 7}}; DoubleDataset d = DoubleDataset.createFromObject(dd); assertEquals(2, d.getRank()); assertEquals(8, d.getSize()); assertEquals(2, d.getShape()[0]); assertEquals(4, d.getShape()[1]); it = d.getIterator(); for (int i = 0; it.hasNext(); i++) { if (i != 3) assertEquals(i, d.getElementDoubleAbs(it.index), 1e-15 * i); else assertEquals(0, d.getElementDoubleAbs(it.index), 1e-15); } }