Search in sources :

Example 11 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class HeapUpdateDoublesSketchTest method checkMemTooSmall1.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMemTooSmall1() {
    Memory mem = Memory.wrap(new byte[7]);
    HeapUpdateDoublesSketch.heapifyInstance(mem);
    fail();
// qs2.getQuantile(0.5);
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 12 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class HeapUpdateDoublesSketchTest method checkZeroPatternReturn.

@Test
public void checkZeroPatternReturn() {
    int k = PreambleUtil.DEFAULT_K;
    DoublesSketch qs1 = buildAndLoadQS(k, 64);
    byte[] byteArr = qs1.toByteArray();
    Memory mem = Memory.wrap(byteArr);
    HeapUpdateDoublesSketch.heapifyInstance(mem);
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 13 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class CpcWrapperTest method check.

@SuppressWarnings("unused")
@Test
public void check() {
    int lgK = 10;
    CpcSketch sk1 = new CpcSketch(lgK);
    CpcSketch sk2 = new CpcSketch(lgK);
    CpcSketch skD = new CpcSketch(lgK);
    double dEst = skD.getEstimate();
    double dlb = skD.getLowerBound(2);
    double dub = skD.getUpperBound(2);
    int n = 100000;
    for (int i = 0; i < n; i++) {
        sk1.update(i);
        sk2.update(i + n);
        skD.update(i);
        skD.update(i + n);
    }
    byte[] concatArr = skD.toByteArray();
    CpcUnion union = new CpcUnion(lgK);
    CpcSketch result = union.getResult();
    double uEst = result.getEstimate();
    double ulb = result.getLowerBound(2);
    double uub = result.getUpperBound(2);
    union.update(sk1);
    union.update(sk2);
    CpcSketch merged = union.getResult();
    byte[] mergedArr = merged.toByteArray();
    Memory concatMem = Memory.wrap(concatArr);
    CpcWrapper concatSk = new CpcWrapper(concatMem);
    assertEquals(concatSk.getLgK(), lgK);
    printf("              %12s %12s %12s\n", "Lb", "Est", "Ub");
    double ccEst = concatSk.getEstimate();
    double ccLb = concatSk.getLowerBound(2);
    double ccUb = concatSk.getUpperBound(2);
    printf("Concatenated: %12.0f %12.0f %12.0f\n", ccLb, ccEst, ccUb);
    // Memory mergedMem = Memory.wrap(mergedArr);
    CpcWrapper mergedSk = new CpcWrapper(mergedArr);
    double mEst = mergedSk.getEstimate();
    double mLb = mergedSk.getLowerBound(2);
    double mUb = mergedSk.getUpperBound(2);
    printf("Merged:       %12.0f %12.0f %12.0f\n", mLb, mEst, mUb);
    assertEquals(Family.CPC, CpcWrapper.getFamily());
}
Also used : Memory(org.apache.datasketches.memory.Memory) Test(org.testng.annotations.Test)

Example 14 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class FdtSketchTest method checkFdtSketch.

@SuppressWarnings("deprecation")
@Test
public void checkFdtSketch() {
    final int lgK = 14;
    final FdtSketch sketch = new FdtSketch(lgK);
    final String[] nodesArr = { "abc", "def" };
    sketch.update(nodesArr);
    final SketchIterator<ArrayOfStringsSummary> it = sketch.iterator();
    int count = 0;
    while (it.next()) {
        final String[] nodesArr2 = it.getSummary().getValue();
        assertEquals(nodesArr2, nodesArr);
        count++;
    }
    assertEquals(count, 1);
    // serialize
    final byte[] byteArr = sketch.toByteArray();
    // deserialize
    Memory mem = Memory.wrap(byteArr);
    FdtSketch sketch2 = new FdtSketch(mem);
    // check output
    final SketchIterator<ArrayOfStringsSummary> it2 = sketch2.iterator();
    int count2 = 0;
    while (it2.next()) {
        final String[] nodesArr2 = it2.getSummary().getValue();
        assertEquals(nodesArr2, nodesArr);
        count2++;
    }
    assertEquals(count, count2);
    assertEquals(sketch2.getEstimate(), sketch.getEstimate());
    assertEquals(sketch2.getLowerBound(2), sketch.getLowerBound(2));
    assertEquals(sketch2.getUpperBound(2), sketch.getUpperBound(2));
}
Also used : ArrayOfStringsSummary(org.apache.datasketches.tuple.strings.ArrayOfStringsSummary) Memory(org.apache.datasketches.memory.Memory) Test(org.testng.annotations.Test)

Example 15 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class MurmurHash3v2Test method checkEmptiesNulls.

@Test
public void checkEmptiesNulls() {
    long seed = 123;
    long[] hashOut = new long[2];
    try {
        // mem empty
        MurmurHash3v2.hash(Memory.wrap(new long[0]), 0, 0, seed, hashOut);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        Memory mem = null;
        // mem null
        MurmurHash3v2.hash(mem, 0, 0, seed, hashOut);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        String s = "";
        // string empty
        MurmurHash3v2.hash(s, seed, hashOut);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        String s = null;
        // string null
        MurmurHash3v2.hash(s, seed, hashOut);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        byte[] barr = new byte[0];
        // byte[] empty
        MurmurHash3v2.hash(barr, seed);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        byte[] barr = null;
        // byte[] null
        MurmurHash3v2.hash(barr, seed);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        char[] carr = new char[0];
        // char[] empty
        MurmurHash3v2.hash(carr, seed);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        char[] carr = null;
        // char[] null
        MurmurHash3v2.hash(carr, seed);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        int[] iarr = new int[0];
        // int[] empty
        MurmurHash3v2.hash(iarr, seed);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        int[] iarr = null;
        // int[] null
        MurmurHash3v2.hash(iarr, seed);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        long[] larr = new long[0];
        // long[] empty
        MurmurHash3v2.hash(larr, seed);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
    try {
        long[] larr = null;
        // long[] null
        MurmurHash3v2.hash(larr, seed);
        fail();
    }// OK
     catch (final IllegalArgumentException e) {
    }
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

Memory (org.apache.datasketches.memory.Memory)213 Test (org.testng.annotations.Test)180 WritableMemory (org.apache.datasketches.memory.WritableMemory)164 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)17 ArrayOfLongsSerDe (org.apache.datasketches.ArrayOfLongsSerDe)14 SketchesReadOnlyException (org.apache.datasketches.SketchesReadOnlyException)11 File (java.io.File)10 ArrayOfStringsSerDe (org.apache.datasketches.ArrayOfStringsSerDe)10 Util.getResourceFile (org.apache.datasketches.Util.getResourceFile)10 MapHandle (org.apache.datasketches.memory.MapHandle)10 WritableHandle (org.apache.datasketches.memory.WritableHandle)6 SharedLocal (org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal)3 ArrayOfNumbersSerDe (org.apache.datasketches.ArrayOfNumbersSerDe)2 CloseableIterator (org.apache.druid.java.util.common.parsers.CloseableIterator)2 IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)1 HashSet (java.util.HashSet)1 Family (org.apache.datasketches.Family)1 SketchesStateException (org.apache.datasketches.SketchesStateException)1 CompressedState.importFromMemory (org.apache.datasketches.cpc.CompressedState.importFromMemory)1 DefaultMemoryRequestServer (org.apache.datasketches.memory.DefaultMemoryRequestServer)1