Search in sources :

Example 66 with WritableMemory

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

the class HeapUpdateDoublesSketchTest method testIt.

//Himanshu's case
@Test
public void testIt() {
    java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocate(1 << 20);
    WritableMemory mem = WritableMemory.wrap(bb);
    int k = 1024;
    DoublesSketch qsk = new DoublesSketchBuilder().setK(k).build();
    DoublesUnion u1 = DoublesUnionBuilder.heapify(qsk);
    u1.getResult().putMemory(mem);
    DoublesUnion u2 = DoublesUnionBuilder.heapify(mem);
    DoublesSketch qsk2 = u2.getResult();
    assertTrue(qsk2.isEmpty());
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 67 with WritableMemory

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

the class HeapUpdateDoublesSketchTest method checkPutMemory.

@Test
public void checkPutMemory() {
    //k = 128
    UpdateDoublesSketch qs1 = DoublesSketch.builder().build();
    for (int i = 0; i < 1000; i++) qs1.update(i);
    int bytes = qs1.getUpdatableStorageBytes();
    WritableMemory dstMem = WritableMemory.wrap(new byte[bytes]);
    qs1.putMemory(dstMem, false);
    Memory srcMem = dstMem;
    DoublesSketch qs2 = DoublesSketch.heapify(srcMem);
    assertEquals(qs1.getMinValue(), qs2.getMinValue(), 0.0);
    assertEquals(qs1.getMaxValue(), qs2.getMaxValue(), 0.0);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 68 with WritableMemory

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

the class HeapUpdateDoublesSketchTest method checkPutMemoryTooSmall.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkPutMemoryTooSmall() {
    //k = 128
    UpdateDoublesSketch qs1 = DoublesSketch.builder().build();
    for (int i = 0; i < 1000; i++) qs1.update(i);
    int bytes = qs1.getCompactStorageBytes();
    //too small
    WritableMemory dstMem = WritableMemory.wrap(new byte[bytes - 1]);
    qs1.putMemory(dstMem);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 69 with WritableMemory

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

the class CompactSketchTest method checkMemTooSmall.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMemTooSmall() {
    int k = 512;
    int u = k;
    boolean compact = true;
    boolean ordered = false;
    UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build();
    for (int i = 0; i < u; i++) usk.update(i);
    int bytes = usk.getCurrentBytes(compact);
    //too small
    byte[] byteArray = new byte[bytes - 8];
    WritableMemory mem = WritableMemory.wrap(byteArray);
    usk.compact(ordered, mem);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 70 with WritableMemory

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

the class DirectIntersectionTest method checkWrap.

@Test
public void checkWrap() {
    int lgK = 9;
    int k = 1 << lgK;
    Intersection inter, inter2, inter3;
    UpdateSketch sk1, sk2;
    CompactSketch resultComp1, resultComp2;
    double est, est2;
    int memBytes = getMaxIntersectionBytes(k);
    byte[] memArr1 = new byte[memBytes];
    WritableMemory iMem = WritableMemory.wrap(memArr1);
    //1st call = valid
    sk1 = UpdateSketch.builder().setNominalEntries(k).build();
    //est mode
    for (int i = 0; i < 2 * k; i++) sk1.update(i);
    CompactSketch compSkIn1 = sk1.compact(true, null);
    println("compSkIn1: " + compSkIn1.getEstimate());
    inter = SetOperation.builder().buildIntersection(iMem);
    inter.update(compSkIn1);
    byte[] memArr2 = inter.toByteArray();
    WritableMemory srcMem = WritableMemory.wrap(memArr2);
    inter2 = Sketches.wrapIntersection(srcMem);
    //2nd call = valid intersecting
    sk2 = UpdateSketch.builder().setNominalEntries(k).build();
    //est mode
    for (int i = 0; i < 2 * k; i++) sk2.update(i);
    CompactSketch compSkIn2 = sk2.compact(true, null);
    println("sk2: " + compSkIn2.getEstimate());
    inter2.update(compSkIn2);
    resultComp1 = inter2.getResult(false, null);
    est = resultComp1.getEstimate();
    assertTrue(est > k);
    println("Est: " + est);
    byte[] memArr3 = inter2.toByteArray();
    WritableMemory srcMem2 = WritableMemory.wrap(memArr3);
    inter3 = Sketches.wrapIntersection(srcMem2);
    resultComp2 = inter3.getResult(false, null);
    est2 = resultComp2.getEstimate();
    println("Est2: " + est2);
    inter.reset();
    inter2.reset();
    inter3.reset();
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

WritableMemory (com.yahoo.memory.WritableMemory)264 Test (org.testng.annotations.Test)210 Memory (com.yahoo.memory.Memory)34 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)15 ArrayOfLongsSerDe (com.yahoo.sketches.ArrayOfLongsSerDe)11 ArrayOfStringsSerDe (com.yahoo.sketches.ArrayOfStringsSerDe)6 WritableDirectHandle (com.yahoo.memory.WritableDirectHandle)5 MemoryRequestServer (com.yahoo.memory.MemoryRequestServer)2 ArrayOfDoublesSerDe (com.yahoo.sketches.ArrayOfDoublesSerDe)2 ArrayOfNumbersSerDe (com.yahoo.sketches.ArrayOfNumbersSerDe)2 PreambleUtil.extractTgtHllType (com.yahoo.sketches.hll.PreambleUtil.extractTgtHllType)2 ResizeFactor (com.yahoo.sketches.ResizeFactor)1 PreambleUtil.extractCurMode (com.yahoo.sketches.hll.PreambleUtil.extractCurMode)1 PreambleUtil.insertTgtHllType (com.yahoo.sketches.hll.PreambleUtil.insertTgtHllType)1 Util.checkIsCompactMemory (com.yahoo.sketches.quantiles.Util.checkIsCompactMemory)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ByteBuffer (java.nio.ByteBuffer)1