Search in sources :

Example 41 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class HeapUpdateDoublesSketchTest method summaryCheckViaMemory.

//@Test  //visual only
public void summaryCheckViaMemory() {
    DoublesSketch qs = buildAndLoadQS(256, 1000000);
    String s = qs.toString();
    println(s);
    println("");
    Memory srcMem = WritableMemory.wrap(qs.toByteArray());
    HeapUpdateDoublesSketch qs2 = HeapUpdateDoublesSketch.heapifyInstance(srcMem);
    s = qs2.toString();
    println(s);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory)

Example 42 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class VarOptItemsUnionTest method serializeSamplingUnion.

@Test
public void serializeSamplingUnion() {
    final int n = 256;
    final int k = 128;
    final VarOptItemsSketch<Long> sketch = getUnweightedLongsVIS(k, n);
    sketch.update(n + 1L, 1000.0);
    sketch.update(n + 2L, 1001.0);
    sketch.update(n + 3L, 1002.0);
    sketch.update(n + 4L, 1003.0);
    sketch.update(n + 5L, 1004.0);
    sketch.update(n + 6L, 1005.0);
    sketch.update(n + 7L, 1006.0);
    sketch.update(n + 8L, 1007.0);
    final VarOptItemsUnion<Long> union = VarOptItemsUnion.newInstance(k);
    union.update(sketch);
    final ArrayOfLongsSerDe serDe = new ArrayOfLongsSerDe();
    final byte[] unionBytes = union.toByteArray(serDe);
    final Memory mem = Memory.wrap(unionBytes);
    final VarOptItemsUnion<Long> rebuilt = VarOptItemsUnion.heapify(mem, serDe);
    compareUnions(rebuilt, union);
    assertEquals(rebuilt.toString(), union.toString());
}
Also used : ArrayOfLongsSerDe(com.yahoo.sketches.ArrayOfLongsSerDe) Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 43 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class ReadOnlyMemoryTest method heapifyCompactSketch.

@Test
public void heapifyCompactSketch() {
    UpdateDoublesSketch s1 = DoublesSketch.builder().build();
    s1.update(1);
    s1.update(2);
    Memory mem = Memory.wrap(s1.toByteArray(true));
    DoublesSketch s2 = DoublesSketch.heapify(mem);
    Assert.assertEquals(s2.getMinValue(), 1.0);
    Assert.assertEquals(s2.getMaxValue(), 2.0);
}
Also used : Memory(com.yahoo.memory.Memory) Test(org.testng.annotations.Test)

Example 44 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class ReadOnlyMemoryTest method wrapAndTryUpdatingSparseSketch.

@Test
public void wrapAndTryUpdatingSparseSketch() {
    UpdateDoublesSketch s1 = DoublesSketch.builder().build();
    s1.update(1);
    s1.update(2);
    final byte[] bytes = s1.toByteArray(false);
    // 32 + MIN_K(=2) * 2 * 8 = 64
    Assert.assertEquals(bytes.length, 64);
    //final Memory mem = Memory.wrap(ByteBuffer.wrap(bytes).asReadOnlyBuffer());
    final Memory mem = Memory.wrap(bytes);
    final UpdateDoublesSketch s2 = (UpdateDoublesSketch) DoublesSketch.wrap(mem);
    Assert.assertEquals(s2.getMinValue(), 1.0);
    Assert.assertEquals(s2.getMaxValue(), 2.0);
    try {
        s2.update(3);
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
}
Also used : Memory(com.yahoo.memory.Memory) SketchesReadOnlyException(com.yahoo.sketches.SketchesReadOnlyException) Test(org.testng.annotations.Test)

Example 45 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class ReadOnlyMemoryTest method wrapUnionFromCompact.

@Test(expectedExceptions = SketchesArgumentException.class)
public void wrapUnionFromCompact() {
    UpdateDoublesSketch s1 = DoublesSketch.builder().build();
    s1.update(1);
    s1.update(2);
    Memory mem = Memory.wrap(s1.toByteArray(true));
    DoublesUnionBuilder.wrap(mem);
    fail();
}
Also used : Memory(com.yahoo.memory.Memory) Test(org.testng.annotations.Test)

Aggregations

Memory (com.yahoo.memory.Memory)141 Test (org.testng.annotations.Test)121 WritableMemory (com.yahoo.memory.WritableMemory)111 ArrayOfLongsSerDe (com.yahoo.sketches.ArrayOfLongsSerDe)11 ArrayOfStringsSerDe (com.yahoo.sketches.ArrayOfStringsSerDe)10 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)10 SketchesReadOnlyException (com.yahoo.sketches.SketchesReadOnlyException)6 MemoryRegion (com.yahoo.memory.MemoryRegion)2 NativeMemory (com.yahoo.memory.NativeMemory)2 ArrayOfNumbersSerDe (com.yahoo.sketches.ArrayOfNumbersSerDe)2 WritableDirectHandle (com.yahoo.memory.WritableDirectHandle)1 Util.checkIsCompactMemory (com.yahoo.sketches.quantiles.Util.checkIsCompactMemory)1 CompactSketch.createCompactSketch (com.yahoo.sketches.theta.CompactSketch.createCompactSketch)1 Union (com.yahoo.sketches.theta.Union)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1