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