Search in sources :

Example 41 with NewChunk

use of water.fvec.NewChunk in project h2o-2 by h2oai.

the class ASTFunc method map.

@Override
double[] map(Env env, double[] in, double[] out) {
    final int sp = env._sp;
    Key key = Vec.VectorGroup.VG_LEN1.addVecs(1)[0];
    AppendableVec av = new AppendableVec(key);
    NewChunk nc = new NewChunk(av, 0);
    for (double v : in) nc.addNum(v);
    nc.close(0, null);
    Frame fr = new Frame(new String[] { "row" }, new Vec[] { av.close(null) });
    env.push(this);
    env.push(fr);
    this.apply(env, 2, null);
    if (env.isDbl()) {
        if (out == null || out.length < 1)
            out = new double[1];
        out[0] = env.popDbl();
    } else if (env.isAry()) {
        fr = env.peekAry();
        if (fr.vecs().length > 1)
            H2O.unimpl();
        Vec vec = fr.anyVec();
        if (vec.length() > 1 << 8)
            H2O.unimpl();
        if (out == null || out.length < vec.length())
            out = new double[(int) vec.length()];
        for (long i = 0; i < vec.length(); i++) out[(int) i] = vec.at(i);
        env.pop();
    } else {
        H2O.unimpl();
    }
    assert sp == env._sp;
    return out;
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) AppendableVec(water.fvec.AppendableVec) AppendableVec(water.fvec.AppendableVec) Key(water.Key) NewChunk(water.fvec.NewChunk)

Example 42 with NewChunk

use of water.fvec.NewChunk in project h2o-3 by h2oai.

the class AstTable method fast_table.

// -------------------------------------------------------------------------
// Fast-path for 1 integer column
private ValFrame fast_table(Vec v1, int ncols, String colname) {
    if (ncols != 1 || !v1.isInt())
        return null;
    long spanl = (long) v1.max() - (long) v1.min() + 1;
    // Cap at decent array size, for performance
    if (spanl > 1000000)
        return null;
    // First fast-pass counting
    AstTable.FastCnt fastCnt = new AstTable.FastCnt((long) v1.min(), (int) spanl).doAll(v1);
    final long[] cnts = fastCnt._cnts;
    final long minVal = fastCnt._min;
    // Second pass to build the result frame, skipping zeros
    Vec dataLayoutVec = Vec.makeCon(0, cnts.length);
    Frame fr = new MRTask() {

        @Override
        public void map(Chunk[] cs, NewChunk nc0, NewChunk nc1) {
            final Chunk c = cs[0];
            for (int i = 0; i < c._len; ++i) {
                int idx = (int) (i + c.start());
                if (cnts[idx] > 0) {
                    nc0.addNum(idx + minVal);
                    nc1.addNum(cnts[idx]);
                }
            }
        }
    }.doAll(new byte[] { Vec.T_NUM, Vec.T_NUM }, dataLayoutVec).outputFrame(new String[] { colname, "Count" }, new String[][] { v1.domain(), null });
    dataLayoutVec.remove();
    return new ValFrame(fr);
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec) MRTask(water.MRTask) Chunk(water.fvec.Chunk) NewChunk(water.fvec.NewChunk) NewChunk(water.fvec.NewChunk)

Aggregations

NewChunk (water.fvec.NewChunk)42 Frame (water.fvec.Frame)34 Chunk (water.fvec.Chunk)32 ValFrame (water.rapids.vals.ValFrame)23 MRTask (water.MRTask)22 Vec (water.fvec.Vec)19 AppendableVec (water.fvec.AppendableVec)8 BufferedString (water.parser.BufferedString)6 Key (water.Key)5 Futures (water.Futures)4 MRTask2 (water.MRTask2)4 ValNum (water.rapids.vals.ValNum)4 C0DChunk (water.fvec.C0DChunk)3 Val (water.rapids.Val)2 ValRow (water.rapids.vals.ValRow)2 ConfusionMatrix (hex.ConfusionMatrix)1 MersenneTwisterRNG (hex.rng.MersenneTwisterRNG)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1