Search in sources :

Example 86 with Memory

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

the class HeapAlphaSketchTest method checkHeapifySeedConflict.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifySeedConflict() {
    int k = 512;
    long seed1 = 1021;
    long seed2 = DEFAULT_UPDATE_SEED;
    UpdateSketch usk = UpdateSketch.builder().setFamily(fam_).setSeed(seed1).setNominalEntries(k).build();
    byte[] byteArray = usk.toByteArray();
    Memory srcMem = Memory.wrap(byteArray);
    Sketch.heapify(srcMem, seed2);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 87 with Memory

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

the class HeapAlphaSketchTest method checkHeapifyMemoryEstimating.

@Test
public void checkHeapifyMemoryEstimating() {
    int k = 512;
    int u = 2 * k;
    long seed = DEFAULT_UPDATE_SEED;
    boolean estimating = (u > k);
    //int maxBytes = (k << 4) + (Family.ALPHA.getLowPreLongs());
    UpdateSketch sk1 = UpdateSketch.builder().setFamily(fam_).setSeed(seed).setNominalEntries(k).build();
    for (int i = 0; i < u; i++) sk1.update(i);
    double sk1est = sk1.getEstimate();
    double sk1lb = sk1.getLowerBound(2);
    double sk1ub = sk1.getUpperBound(2);
    assertEquals(sk1.isEstimationMode(), estimating);
    byte[] byteArray = sk1.toByteArray();
    Memory mem = Memory.wrap(byteArray);
    UpdateSketch sk2 = (UpdateSketch) Sketch.heapify(mem, DEFAULT_UPDATE_SEED);
    assertEquals(sk2.getEstimate(), sk1est);
    assertEquals(sk2.getLowerBound(2), sk1lb);
    assertEquals(sk2.getUpperBound(2), sk1ub);
    assertEquals(sk2.isEmpty(), false);
    assertEquals(sk2.isEstimationMode(), estimating);
    assertEquals(sk2.getClass().getSimpleName(), sk1.getClass().getSimpleName());
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 88 with Memory

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

the class ReadOnlyMemoryTest method heapifyCompactUnorderedSketch.

@Test
public void heapifyCompactUnorderedSketch() {
    UpdateSketch updateSketch = UpdateSketch.builder().build();
    updateSketch.update(1);
    Memory mem = Memory.wrap(ByteBuffer.wrap(updateSketch.compact(false, null).toByteArray()).asReadOnlyBuffer());
    Sketch sketch = Sketch.heapify(mem);
    assertEquals(sketch.getEstimate(), 1.0);
}
Also used : Memory(com.yahoo.memory.Memory) Test(org.testng.annotations.Test)

Example 89 with Memory

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

the class SketchTest method checkWrapToHeapifyConversion1.

@Test
public void checkWrapToHeapifyConversion1() {
    int k = 512;
    UpdateSketch sketch1 = UpdateSketch.builder().setNominalEntries(k).build();
    for (int i = 0; i < k; i++) {
        sketch1.update(i);
    }
    double uest1 = sketch1.getEstimate();
    int bytes = sketch1.getCurrentBytes(true);
    WritableMemory v3mem = WritableMemory.wrap(new byte[bytes]);
    sketch1.compact(true, v3mem);
    Memory v1mem = ForwardCompatibilityTest.convertSerV3toSerV1(v3mem);
    Sketch csk2 = Sketch.wrap(v1mem);
    assertFalse(csk2.isDirect());
    assertEquals(uest1, csk2.getEstimate(), 0.0);
    Memory v2mem = ForwardCompatibilityTest.convertSerV3toSerV2(v3mem);
    csk2 = Sketch.wrap(v2mem);
    assertFalse(csk2.isDirect());
    assertEquals(uest1, csk2.getEstimate(), 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 90 with Memory

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

the class SketchTest method checkWrapBadFamily.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkWrapBadFamily() {
    UpdateSketch sketch = UpdateSketch.builder().setFamily(Family.ALPHA).setNominalEntries(1024).build();
    byte[] byteArr = sketch.toByteArray();
    Memory srcMem = Memory.wrap(byteArr);
    Sketch.wrap(srcMem);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) 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