use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstBinOp method frame_op_scalar.
/**
* Auto-widen the scalar to every element of the frame
*/
public ValFrame frame_op_scalar(Frame fr, final double d) {
Frame res = new MRTask() {
@Override
public void map(Chunk[] chks, NewChunk[] cress) {
for (int c = 0; c < chks.length; c++) {
Chunk chk = chks[c];
NewChunk cres = cress[c];
for (int i = 0; i < chk._len; i++) cres.addNum(op(chk.atd(i), d));
}
}
}.doAll(fr.numCols(), Vec.T_NUM, fr).outputFrame(fr._names, null);
// Cleanup categorical misuse
return cleanCategorical(fr, res);
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstCumu method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame f = stk.track(asts[1].exec(env)).getFrame();
AstRoot axisAR = asts[2];
for (Vec v : f.vecs()) {
if (v.isCategorical() || v.isString() || v.isUUID())
throw new IllegalArgumentException("Cumulative functions not applicable to enum, string, or UUID values");
}
double axis = axisAR.exec(env).getNum();
if (axis != 1.0 && axis != 0.0)
throw new IllegalArgumentException("Axis must be 0 or 1");
if (f.numCols() == 1) {
if (axis == 0.0) {
AstCumu.CumuTask t = new AstCumu.CumuTask(f.anyVec().nChunks(), init());
t.doAll(new byte[] { Vec.T_NUM }, f.anyVec());
final double[] chkCumu = t._chkCumu;
Vec cumuVec = t.outputFrame().anyVec();
new MRTask() {
@Override
public void map(Chunk c) {
if (c.cidx() != 0) {
double d = chkCumu[c.cidx() - 1];
for (int i = 0; i < c._len; ++i) c.set(i, op(c.atd(i), d));
}
}
}.doAll(cumuVec);
Key<Frame> k = Key.make();
return new ValFrame(new Frame(k, null, new Vec[] { cumuVec }));
} else {
return new ValFrame(new Frame(f));
}
} else {
if (axis == 0.0) {
// down the column implementation
AstCumu.CumuTaskWholeFrame t = new AstCumu.CumuTaskWholeFrame(f.anyVec().nChunks(), init(), f.numCols());
Frame fr2 = t.doAll(f.numCols(), Vec.T_NUM, f).outputFrame(null, f.names(), null);
final double[][] chkCumu = t._chkCumu;
new MRTask() {
@Override
public void map(Chunk[] cs) {
if (cs[0].cidx() != 0) {
for (int i = 0; i < cs.length; i++) {
double d = chkCumu[i][cs[i].cidx() - 1];
for (int j = 0; j < cs[i]._len; ++j) cs[i].set(j, op(cs[i].atd(j), d));
}
}
}
}.doAll(fr2);
return new ValFrame(new Frame(fr2));
} else {
AstCumu.CumuTaskAxis1 t = new AstCumu.CumuTaskAxis1(init());
Frame fr2 = t.doAll(f.numCols(), Vec.T_NUM, f).outputFrame(null, f.names(), null);
return new ValFrame(new Frame(fr2));
}
}
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class RapidsTest method checkTree.
private void checkTree(String tree, String thrownMessage) {
//Frame r = frame(new double[][]{{-1},{1},{2},{3},{4},{5},{6},{254}});
//Key ahex = Key.make("a.hex");
//Frame fr = new Frame(ahex, null, new Vec[]{r.remove(0)});
//r.delete();
//DKV.put(ahex, fr);
Frame fr = parse_test_file(Key.make("a.hex"), "smalldata/iris/iris_wheader.csv");
fr.remove(4).remove();
try {
Val val = Rapids.exec(tree);
Assert.assertNull(thrownMessage);
System.out.println(val.toString());
if (val instanceof ValFrame) {
Frame fr2 = val.getFrame();
System.out.println(fr2.vec(0));
fr2.remove();
}
} catch (IllegalArgumentException iae) {
if (thrownMessage != null) {
Assert.assertEquals(thrownMessage, iae.getMessage());
Log.debug("Expected Exception suppressed", iae);
} else
throw iae;
} finally {
fr.delete();
}
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class TableTest method chkTree.
private Frame chkTree(String tree, String fname, boolean expectThrow) {
Frame fr = parse_test_file(Key.make("hex"), fname);
try {
Val val = Rapids.exec(tree);
Assert.assertFalse(expectThrow);
System.out.println(val.toString());
if (val instanceof ValFrame)
return val.getFrame();
throw new IllegalArgumentException("exepcted a frame return");
} catch (IllegalArgumentException iae) {
// If not expecting a throw, then throw which fails the junit
if (!expectThrow)
throw iae;
// If expecting, then cleanup
fr.delete();
return null;
}
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class RBindTest method checkTree.
private Frame checkTree(String tree, boolean expectThrow) {
Frame fr = parse_test_file(Key.make("a.hex"), "smalldata/iris/iris_wheader.csv");
fr.remove(4).remove();
try {
Val val = Rapids.exec(tree);
Assert.assertFalse(expectThrow);
System.out.println(val.toString());
if (val instanceof ValFrame)
return val.getFrame();
throw new IllegalArgumentException("exepcted a frame return");
} catch (IllegalArgumentException iae) {
// If not expecting a throw, then throw which fails the junit
if (!expectThrow)
throw iae;
// If expecting, then cleanup
fr.delete();
return null;
}
}
Aggregations