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());
}
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);
}
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));
}
}
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);
}
Aggregations