Search in sources :

Example 21 with Futures

use of water.Futures in project h2o-3 by h2oai.

the class C8ChunkTest method test_setNA.

@Test
public void test_setNA() {
    // Create a vec with one chunk with 15 elements, and set its numbers
    water.Key key = Vec.newKey();
    Vec vec = new Vec(key, Vec.ESPC.rowLayout(key, new long[] { 0, 15 })).makeZero();
    long[] vals = new long[] { Long.MIN_VALUE + 1, 1, 0, 2, 0, 51, 0, 33, 0, 21234, 3422, 3767, 0, 0, Long.MAX_VALUE };
    Vec.Writer w = vec.open();
    for (int i = 0; i < vals.length; ++i) w.set(i, vals[i]);
    w.close();
    Chunk cc = vec.chunkForChunkIdx(0);
    assert cc instanceof C8Chunk;
    Futures fs = new Futures();
    fs.blockForPending();
    for (int i = 0; i < vals.length; ++i) Assert.assertEquals(vals[i], cc.at8(i), Double.MIN_VALUE);
    for (int i = 0; i < vals.length; ++i) Assert.assertEquals(vals[i], cc.at8_abs(i), Double.MIN_VALUE);
    int[] NAs = new int[] { 1, 5, 2 };
    int[] notNAs = new int[] { 0, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
    for (int na : NAs) cc.setNA_abs(na);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    NewChunk nc = new NewChunk(null, 0);
    cc.extractRows(nc, 0, vals.length);
    Assert.assertEquals(vals.length, nc._sparseLen);
    Assert.assertEquals(vals.length, nc._len);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    Chunk cc2 = nc.compress();
    Assert.assertEquals(vals.length, cc._len);
    Assert.assertTrue(cc2 instanceof C8Chunk);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    Assert.assertTrue(Arrays.equals(cc._mem, cc2._mem));
    vec.remove();
}
Also used : Futures(water.Futures)

Example 22 with Futures

use of water.Futures in project h2o-3 by h2oai.

the class C2ChunkTest method test_setNA.

@Test
public void test_setNA() {
    // Create a vec with one chunk with 15 elements, and set its numbers
    Key key = Vec.newKey();
    Vec vec = new Vec(key, Vec.ESPC.rowLayout(key, new long[] { 0, 15 })).makeZero();
    int[] vals = new int[] { 0, 3, 0, 6, 0, 0, 0, -32767, 0, 12, 234, 32767, 0, 0, 19 };
    Vec.Writer w = vec.open();
    for (int i = 0; i < vals.length; ++i) w.set(i, vals[i]);
    w.close();
    Chunk cc = vec.chunkForChunkIdx(0);
    assert cc instanceof C2Chunk;
    Futures fs = new Futures();
    fs.blockForPending();
    for (int i = 0; i < vals.length; ++i) Assert.assertEquals(vals[i], cc.at8(i));
    for (int i = 0; i < vals.length; ++i) Assert.assertEquals(vals[i], cc.at8_abs(i));
    int[] NAs = new int[] { 1, 5, 2 };
    int[] notNAs = new int[] { 0, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
    for (int na : NAs) cc.setNA_abs(na);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    NewChunk nc = new NewChunk(null, 0);
    cc.extractRows(nc, 0, (int) vec.length());
    Assert.assertEquals(vals.length, nc._sparseLen);
    Assert.assertEquals(vals.length, nc._len);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    Chunk cc2 = nc.compress();
    Assert.assertEquals(vals.length, cc._len);
    Assert.assertTrue(cc2 instanceof C2Chunk);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    Assert.assertTrue(Arrays.equals(cc._mem, cc2._mem));
    vec.remove();
}
Also used : Futures(water.Futures) Key(water.Key)

Example 23 with Futures

use of water.Futures in project h2o-3 by h2oai.

the class C2SChunkTest method test_setNA.

@Test
public void test_setNA() {
    // Create a vec with one chunk with 15 elements, and set its numbers
    water.Key key = Vec.newKey();
    Vec vec = new Vec(key, Vec.ESPC.rowLayout(key, new long[] { 0, 15 })).makeZero();
    int[] vals = new int[] { 0, 3, 0, 6, 0, 0, 0, -32769, 0, 12, 234, 32765, 0, 0, 19 };
    Vec.Writer w = vec.open();
    for (int i = 0; i < vals.length; ++i) w.set(i, vals[i]);
    w.close();
    Chunk cc = vec.chunkForChunkIdx(0);
    assert cc instanceof C2SChunk;
    Futures fs = new Futures();
    fs.blockForPending();
    for (int i = 0; i < vals.length; ++i) Assert.assertEquals(vals[i], cc.at8(i));
    for (int i = 0; i < vals.length; ++i) Assert.assertEquals(vals[i], cc.at8_abs(i));
    int[] NAs = new int[] { 1, 5, 2 };
    int[] notNAs = new int[] { 0, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
    for (int na : NAs) cc.setNA_abs(na);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    NewChunk nc = new NewChunk(null, 0);
    cc.extractRows(nc, 0, (int) vec.length());
    Assert.assertEquals(vals.length, nc._sparseLen);
    Assert.assertEquals(vals.length, nc._len);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    Chunk cc2 = nc.compress();
    Assert.assertEquals(vals.length, cc._len);
    Assert.assertTrue(cc2 instanceof C2SChunk);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    Assert.assertTrue(Arrays.equals(cc._mem, cc2._mem));
    vec.remove();
}
Also used : Futures(water.Futures)

Example 24 with Futures

use of water.Futures in project h2o-2 by h2oai.

the class Frames method create.

/**
   * Creates a frame programmatically.
   */
public static Frame create(String[] headers, double[][] rows) {
    Futures fs = new Futures();
    Vec[] vecs = new Vec[rows[0].length];
    Key[] keys = new Vec.VectorGroup().addVecs(vecs.length);
    for (int c = 0; c < vecs.length; c++) {
        AppendableVec vec = new AppendableVec(keys[c]);
        NewChunk chunk = new NewChunk(vec, 0);
        for (int r = 0; r < rows.length; r++) chunk.addNum(rows[r][c]);
        chunk.close(0, fs);
        vecs[c] = vec.close(fs);
    }
    fs.blockForPending();
    return new Frame(headers, vecs);
}
Also used : Futures(water.Futures) Key(water.Key)

Example 25 with Futures

use of water.Futures in project h2o-3 by h2oai.

the class AstRecAssignTestUtils method seqStrVec.

static Vec seqStrVec(int... runs) {
    Key k = Vec.VectorGroup.VG_LEN1.addVec();
    Futures fs = new Futures();
    AppendableVec avec = new AppendableVec(k, Vec.T_STR);
    NewChunk chunk = new NewChunk(avec, 0);
    int seq = 0;
    for (int r : runs) {
        if (seq > 0)
            chunk.addStr(null);
        for (int i = 0; i < r; i++) chunk.addStr(String.valueOf(seq++));
    }
    chunk.close(0, fs);
    Vec vec = avec.layout_and_close(fs);
    fs.blockForPending();
    return vec;
}
Also used : Futures(water.Futures) Vec(water.fvec.Vec) AppendableVec(water.fvec.AppendableVec) AppendableVec(water.fvec.AppendableVec) Key(water.Key) NewChunk(water.fvec.NewChunk)

Aggregations

Futures (water.Futures)34 Vec (water.fvec.Vec)11 Key (water.Key)10 Frame (water.fvec.Frame)7 AppendableVec (water.fvec.AppendableVec)4 NewChunk (water.fvec.NewChunk)4 ValFrame (water.rapids.vals.ValFrame)4 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 Test (org.junit.Test)2 MRTask (water.MRTask)2 DataInfo (hex.FrameTask.DataInfo)1 DMatrix (hex.la.DMatrix)1 File (java.io.File)1 IOException (java.io.IOException)1 Job (water.Job)1 FrameKeyV3 (water.api.schemas3.KeyV3.FrameKeyV3)1 ByteVec (water.fvec.ByteVec)1 NFSFileVec (water.fvec.NFSFileVec)1 BufferedString (water.parser.BufferedString)1