Search in sources :

Example 36 with WritableMemory

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

the class DirectIntersectionTest method checkOverlappedDirect.

//Check Alex's bug intersecting 2 direct full sketches with only overlap of 2
//
@Test
public void checkOverlappedDirect() {
    int k = 1 << 4;
    //plenty of room
    int memBytes = 2 * k * 16 + PREBYTES;
    UpdateSketch sk1 = Sketches.updateSketchBuilder().setNominalEntries(k).build();
    UpdateSketch sk2 = Sketches.updateSketchBuilder().setNominalEntries(k).build();
    for (int i = 0; i < k; i++) {
        sk1.update(i);
        //overlap by 2
        sk2.update(k - 2 + i);
    }
    WritableMemory memIn1 = WritableMemory.wrap(new byte[memBytes]);
    WritableMemory memIn2 = WritableMemory.wrap(new byte[memBytes]);
    WritableMemory memOut = WritableMemory.wrap(new byte[memBytes]);
    CompactSketch csk1 = sk1.compact(true, memIn1);
    CompactSketch csk2 = sk2.compact(true, memIn2);
    Intersection inter = Sketches.setOperationBuilder().buildIntersection(memOut);
    inter.update(csk1);
    inter.update(csk2);
    CompactSketch cskOut = inter.getResult(true, memOut);
    assertEquals(cskOut.getEstimate(), 2.0, 0.0);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 37 with WritableMemory

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

the class DirectQuickSelectSketchTest method checkResetAndStartingSubMultiple.

@Test
public void checkResetAndStartingSubMultiple() {
    int k = 512;
    int u = 4 * k;
    WritableMemory mem = makeNativeMemory(k);
    UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build(mem);
    //for internal checks
    DirectQuickSelectSketch sk1 = (DirectQuickSelectSketch) usk;
    assertTrue(usk.isEmpty());
    for (int i = 0; i < u; i++) {
        usk.update(i);
    }
    assertFalse(usk.isEmpty());
    assertTrue(sk1.getRetainedEntries(false) > k);
    assertTrue(sk1.getThetaLong() < Long.MAX_VALUE);
    sk1.reset();
    assertTrue(usk.isEmpty());
    assertEquals(sk1.getRetainedEntries(false), 0);
    assertEquals(usk.getEstimate(), 0.0, 0.0);
    assertEquals(sk1.getThetaLong(), Long.MAX_VALUE);
    assertNotNull(sk1.getMemory());
    assertFalse(sk1.isOrdered());
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 38 with WritableMemory

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

the class DirectQuickSelectSketchTest method checkRebuild.

@Test
public void checkRebuild() {
    int k = 512;
    int u = 4 * k;
    WritableMemory mem = makeNativeMemory(k);
    UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build(mem);
    //for internal checks
    DirectQuickSelectSketch sk1 = (DirectQuickSelectSketch) usk;
    assertTrue(usk.isEmpty());
    for (int i = 0; i < u; i++) {
        usk.update(i);
    }
    assertFalse(usk.isEmpty());
    assertTrue(usk.getEstimate() > 0.0);
    assertTrue(sk1.getRetainedEntries(false) > k);
    sk1.rebuild();
    assertEquals(sk1.getRetainedEntries(false), k);
    assertEquals(sk1.getRetainedEntries(true), k);
    sk1.rebuild();
    assertEquals(sk1.getRetainedEntries(false), k);
    assertEquals(sk1.getRetainedEntries(true), k);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 39 with WritableMemory

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

the class DirectQuickSelectSketchTest method checkUpperAndLowerBounds.

@Test
public void checkUpperAndLowerBounds() {
    int k = 512;
    int u = 2 * k;
    WritableMemory mem = makeNativeMemory(k);
    UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build(mem);
    for (int i = 0; i < u; i++) {
        usk.update(i);
    }
    double est = usk.getEstimate();
    double ub = usk.getUpperBound(1);
    double lb = usk.getLowerBound(1);
    assertTrue(ub > est);
    assertTrue(lb < est);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 40 with WritableMemory

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

the class DirectQuickSelectSketchTest method checkConstructorMemTooSmall.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkConstructorMemTooSmall() {
    int k = 16;
    WritableMemory mem = makeNativeMemory(8);
    UpdateSketch.builder().setNominalEntries(k).build(mem);
}
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