Search in sources :

Example 91 with Memory

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

the class UnionImplTest method checkFastWrap.

@Test
public void checkFastWrap() {
    int k = 16;
    long seed = DEFAULT_UPDATE_SEED;
    int unionSize = Sketches.getMaxUnionBytes(k);
    WritableMemory srcMem = WritableMemory.wrap(new byte[unionSize]);
    Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(srcMem);
    //exact
    for (int i = 0; i < k; i++) {
        union.update(i);
    }
    assertEquals(union.getResult().getEstimate(), k, 0.0);
    Union union2 = UnionImpl.fastWrap(srcMem, seed);
    assertEquals(union2.getResult().getEstimate(), k, 0.0);
    Memory srcMemR = srcMem;
    Union union3 = UnionImpl.fastWrap(srcMemR, seed);
    assertEquals(union3.getResult().getEstimate(), k, 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 92 with Memory

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

the class SerializerDeserializerTest method deserializeFromMemoryUsupportedClass.

@Test(expectedExceptions = SketchesArgumentException.class)
public void deserializeFromMemoryUsupportedClass() {
    Memory mem = null;
    SerializerDeserializer.deserializeFromMemory(mem, 0, "bogus");
}
Also used : Memory(com.yahoo.memory.Memory) Test(org.testng.annotations.Test)

Example 93 with Memory

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

the class HeapUnionTest method checkSerVer2Handling.

@Test
public void checkSerVer2Handling() {
    //4096
    int lgK = 12;
    int k = 1 << lgK;
    int u1 = 2 * k;
    //smaller exact sketch forces early stop
    int u2 = 1024;
    int totU = u1 + u2;
    UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
    UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
    //2*k
    for (int i = 0; i < u1; i++) usk1.update(i);
    //2*k + 1024 no overlap
    for (int i = u1; i < totU; i++) usk2.update(i);
    WritableMemory skMem1 = WritableMemory.wrap(usk1.compact(true, null).toByteArray());
    WritableMemory skMem2 = WritableMemory.wrap(usk2.compact(true, null).toByteArray());
    Memory v2mem1 = convertSerV3toSerV2(skMem1);
    Memory v2mem2 = convertSerV3toSerV2(skMem2);
    Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
    union.update(v2mem1);
    union.update(v2mem2);
    CompactSketch cOut = union.getResult(true, null);
    assertEquals(cOut.getEstimate(), totU, .05 * k);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 94 with Memory

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

the class ReadOnlyMemoryTest method heapifyUnion.

@Test
public void heapifyUnion() {
    Union u1 = SetOperation.builder().buildUnion();
    u1.update(1);
    Memory mem = Memory.wrap(ByteBuffer.wrap(u1.toByteArray()).asReadOnlyBuffer());
    Union u2 = (Union) SetOperation.heapify(mem);
    u2.update(2);
    Assert.assertEquals(u2.getResult().getEstimate(), 2.0);
}
Also used : Memory(com.yahoo.memory.Memory) Test(org.testng.annotations.Test)

Example 95 with Memory

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

the class ReadOnlyMemoryTest method heapifyUpdateSketch.

@Test
public void heapifyUpdateSketch() {
    UpdateSketch us1 = UpdateSketch.builder().build();
    us1.update(1);
    Memory mem = Memory.wrap(ByteBuffer.wrap(us1.toByteArray()).asReadOnlyBuffer());
    // downcasting is not recommended, for testing only
    UpdateSketch us2 = (UpdateSketch) Sketch.heapify(mem);
    us2.update(2);
    assertEquals(us2.getEstimate(), 2.0);
}
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