/** * Wrap the given Memory as an ArrayOfDoublesUnion * @param mem the given Memory * @return an ArrayOfDoublesUnion */ public static ArrayOfDoublesUnion wrap(final Memory mem) { return wrap(mem, DEFAULT_UPDATE_SEED); }
/** * Wrap the given WritableMemory as an ArrayOfDoublesUnion * @param mem the given Memory * @return an ArrayOfDoublesUnion */ public static ArrayOfDoublesUnion wrap(final WritableMemory mem) { return wrap(mem, DEFAULT_UPDATE_SEED); }
/** * Wrap the given Memory and seed as an ArrayOfDoublesUnion * @param mem the given Memory * @param seed the given seed * @return an ArrayOfDoublesUnion */ public static ArrayOfDoublesUnion wrapUnion(final Memory mem, final long seed) { return ArrayOfDoublesUnion.wrap(mem, seed); }
/** * Wrap the given Memory and seed as an ArrayOfDoublesUnion * @param mem the given Memory * @param seed the given seed * @return an ArrayOfDoublesUnion */ public static ArrayOfDoublesUnion wrapUnion(final WritableMemory mem, final long seed) { return ArrayOfDoublesUnion.wrap(mem, seed); }
@Test public void wrapAndTryUpdatingUnionV0_9_1() throws Exception { byte[] bytes = TestUtil.readBytesFromFile(getClass().getClassLoader() .getResource("ArrayOfDoublesUnion_v0.9.1.bin").getFile()); ArrayOfDoublesUnion union2 = ArrayOfDoublesUnion.wrap(Memory.wrap(bytes)); ArrayOfDoublesCompactSketch result = union2.getResult(); Assert.assertEquals(result.getEstimate(), 12288.0, 12288 * 0.01); boolean thrown = false; try { union2.reset(); } catch (SketchesReadOnlyException e) { thrown = true; } Assert.assertTrue(thrown); }
/** * Wrap the given Memory and seed as an ArrayOfDoublesUnion * @param mem the given Memory * @param seed the given seed * @return an ArrayOfDoublesUnion */ public static ArrayOfDoublesUnion wrapUnion(final Memory mem, final long seed) { return ArrayOfDoublesUnion.wrap(mem, seed); }
/** * Wrap the given Memory as an ArrayOfDoublesUnion * @param mem the given Memory * @return an ArrayOfDoublesUnion */ public static ArrayOfDoublesUnion wrap(final Memory mem) { return wrap(mem, DEFAULT_UPDATE_SEED); }
/** * Wrap the given Memory and seed as an ArrayOfDoublesUnion * @param mem the given Memory * @param seed the given seed * @return an ArrayOfDoublesUnion */ public static ArrayOfDoublesUnion wrapUnion(final WritableMemory mem, final long seed) { return ArrayOfDoublesUnion.wrap(mem, seed); }
/** * Wrap the given WritableMemory as an ArrayOfDoublesUnion * @param mem the given Memory * @return an ArrayOfDoublesUnion */ public static ArrayOfDoublesUnion wrap(final WritableMemory mem) { return wrap(mem, DEFAULT_UPDATE_SEED); }
union1.update(sketch2); ArrayOfDoublesUnion union2 = ArrayOfDoublesUnion.wrap(WritableMemory.wrap(union1.toByteArray())); ArrayOfDoublesCompactSketch result = union2.getResult(WritableMemory.wrap(new byte[1000000])); Assert.assertEquals(result.getEstimate(), 12288.0, 12288 * 0.01);
@Test public void heapToDirect() { ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().build(); sketch1.update(1, new double[] {1.0}); sketch1.update(1, new double[] {1.0}); sketch1.update(1, new double[] {1.0}); sketch1.update(2, new double[] {1.0}); ArrayOfDoublesUpdatableSketch sketch2 = new ArrayOfDoublesUpdatableSketchBuilder().build(); sketch2.update(2, new double[] {1.0}); sketch2.update(2, new double[] {1.0}); sketch2.update(3, new double[] {1.0}); sketch2.update(3, new double[] {1.0}); sketch2.update(3, new double[] {1.0}); ArrayOfDoublesUnion heapUnion = new ArrayOfDoublesSetOperationBuilder().buildUnion(); heapUnion.update(sketch1); ArrayOfDoublesUnion directUnion = ArrayOfDoublesUnion.wrap(WritableMemory.wrap(heapUnion.toByteArray())); directUnion.update(sketch2); ArrayOfDoublesCompactSketch result = directUnion.getResult(WritableMemory.wrap(new byte[1000000])); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getEstimate(), 3.0); double[][] values = result.getValues(); Assert.assertEquals(values.length, 3); Assert.assertEquals(values[0][0], 3.0); Assert.assertEquals(values[1][0], 3.0); Assert.assertEquals(values[2][0], 3.0); }
@Test public void directSerializeDeserializeWithSeed() { long seed = 1; int key = 0; ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed) .build(WritableMemory.wrap(new byte[1000000])); for (int i = 0; i < 8192; i++) { sketch1.update(key++, new double[] {1.0}); } key -= 4096; // overlap half of the entries ArrayOfDoublesUpdatableSketch sketch2 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed) .build(WritableMemory.wrap(new byte[1000000])); for (int i = 0; i < 8192; i++) { sketch2.update(key++, new double[] {1.0}); } ArrayOfDoublesUnion union1 = new ArrayOfDoublesSetOperationBuilder().setSeed(seed) .buildUnion(WritableMemory.wrap(new byte[1000000])); union1.update(sketch1); union1.update(sketch2); ArrayOfDoublesUnion union2 = ArrayOfDoublesUnion.wrap(WritableMemory.wrap(union1.toByteArray()), seed); ArrayOfDoublesCompactSketch result = union2.getResult(WritableMemory.wrap(new byte[1000000])); Assert.assertEquals(result.getEstimate(), 12288.0, 12288 * 0.01); }