Search in sources :

Example 31 with Futures

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

the class RemoveVec method serve.

@Override
protected Response serve() {
    Futures fs = new Futures();
    for (Vec v : source.remove(cols)) v.remove(fs);
    DKV.put(source._key, source, fs);
    fs.blockForPending();
    return Inspect2.redirect(this, source._key.toString());
}
Also used : Futures(water.Futures)

Example 32 with Futures

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

the class AstLevels method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Frame f = stk.track(asts[1].exec(env)).getFrame();
    Futures fs = new Futures();
    Key[] keys = Vec.VectorGroup.VG_LEN1.addVecs(f.numCols());
    Vec[] vecs = new Vec[keys.length];
    // compute the longest vec... that's the one with the most domain levels
    int max = 0;
    for (int i = 0; i < f.numCols(); ++i) if (f.vec(i).isCategorical())
        if (max < f.vec(i).domain().length)
            max = f.vec(i).domain().length;
    final int rowLayout = Vec.ESPC.rowLayout(keys[0], new long[] { 0, max });
    for (int i = 0; i < f.numCols(); ++i) {
        AppendableVec v = new AppendableVec(keys[i], Vec.T_NUM);
        NewChunk nc = new NewChunk(v, 0);
        String[] dom = f.vec(i).domain();
        int numToPad = dom == null ? max : max - dom.length;
        if (dom != null)
            for (int j = 0; j < dom.length; ++j) nc.addNum(j);
        for (int j = 0; j < numToPad; ++j) nc.addNA();
        nc.close(0, fs);
        vecs[i] = v.close(rowLayout, fs);
        vecs[i].setDomain(dom);
    }
    fs.blockForPending();
    Frame fr2 = new Frame(vecs);
    return new ValFrame(fr2);
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Futures(water.Futures) Vec(water.fvec.Vec) AppendableVec(water.fvec.AppendableVec) AppendableVec(water.fvec.AppendableVec) Key(water.Key) NewChunk(water.fvec.NewChunk)

Example 33 with Futures

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

the class AstSeq method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    double from = asts[1].exec(env).getNum();
    double to = asts[2].exec(env).getNum();
    double by = asts[3].exec(env).getNum();
    double delta = to - from;
    if (delta == 0 && to == 0)
        throw new IllegalArgumentException("Expected `to` and `from` to have nonzero difference.");
    else {
        double n = delta / by;
        if (n < 0)
            throw new IllegalArgumentException("wrong sign in 'by' argument");
        else if (n > Double.MAX_VALUE)
            throw new IllegalArgumentException("'by' argument is much too small");
        Futures fs = new Futures();
        AppendableVec av = new AppendableVec(Vec.newKey(), Vec.T_NUM);
        NewChunk nc = new NewChunk(av, 0);
        int len = (int) n + 1;
        for (int r = 0; r < len; r++) nc.addNum(from + r * by);
        // May need to adjust values = by > 0 ? min(values, to) : max(values, to)
        nc.close(0, fs);
        Vec vec = av.layout_and_close(fs);
        fs.blockForPending();
        return new ValFrame(new Frame(vec));
    }
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Futures(water.Futures) Vec(water.fvec.Vec) AppendableVec(water.fvec.AppendableVec) AppendableVec(water.fvec.AppendableVec) NewChunk(water.fvec.NewChunk)

Example 34 with Futures

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

the class AstWhich method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Frame f = stk.track(asts[1].exec(env)).getFrame();
    // The 1-row version
    if (f.numRows() == 1 && f.numCols() > 1) {
        AppendableVec v = new AppendableVec(Vec.VectorGroup.VG_LEN1.addVec(), Vec.T_NUM);
        NewChunk chunk = new NewChunk(v, 0);
        for (int i = 0; i < f.numCols(); i++) if (f.vecs()[i].at8(0) != 0)
            chunk.addNum(i);
        Futures fs = chunk.close(0, new Futures());
        Vec vec = v.layout_and_close(fs);
        fs.blockForPending();
        return new ValFrame(new Frame(vec));
    }
    // The 1-column version
    Vec vec = f.anyVec();
    if (f.numCols() > 1 || !vec.isInt())
        throw new IllegalArgumentException("which requires a single integer column");
    Frame f2 = new MRTask() {

        @Override
        public void map(Chunk c, NewChunk nc) {
            long start = c.start();
            for (int i = 0; i < c._len; ++i) if (c.at8(i) != 0)
                nc.addNum(start + i);
        }
    }.doAll(new byte[] { Vec.T_NUM }, vec).outputFrame();
    return new ValFrame(f2);
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Futures(water.Futures) MRTask(water.MRTask)

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