use of water.rapids.vals.ValNum in project h2o-3 by h2oai.
the class AstFlatten method apply.
@Override
public Val apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
// did not flatten
if (fr.numCols() != 1 || fr.numRows() != 1)
return new ValFrame(fr);
Vec vec = fr.anyVec();
switch(vec.get_type()) {
case Vec.T_BAD:
case Vec.T_NUM:
return new ValNum(vec.at(0));
case Vec.T_TIME:
// check for missing values
return vec.isNA(0) ? new ValNum(Double.NaN) : new ValNum(vec.at8(0));
case Vec.T_STR:
return new ValStr(vec.atStr(new BufferedString(), 0).toString());
case // check for missing values
Vec.T_CAT:
return vec.isNA(0) ? new ValStr("NA") : new ValStr(vec.factor(vec.at8(0)));
default:
throw H2O.unimpl("The type of vector: " + vec.get_type_str() + " is not supported by " + str());
}
}
use of water.rapids.vals.ValNum in project h2o-3 by h2oai.
the class AstRename method apply.
@Override
public ValNum apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Key oldKey = Key.make(env.expand(asts[1].exec(env).getStr()));
Key newKey = Key.make(env.expand(asts[2].exec(env).getStr()));
Iced o = DKV.remove(oldKey).get();
if (o instanceof Frame)
DKV.put(newKey, new Frame(newKey, ((Frame) o)._names, ((Frame) o).vecs()));
else if (o instanceof Model) {
((Model) o)._key = newKey;
DKV.put(newKey, o);
} else
throw new IllegalArgumentException("Trying to rename Value of type " + o.getClass());
return new ValNum(Double.NaN);
}
use of water.rapids.vals.ValNum in project h2o-3 by h2oai.
the class AstProd method apply.
@Override
public ValNum apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
for (Vec v : fr.vecs()) if (v.isCategorical() || v.isUUID() || v.isString())
throw new IllegalArgumentException("`" + str() + "`" + " only defined on a data frame with all numeric variables");
double prod = new AstProd.RedProd().doAll(fr)._d;
return new ValNum(prod);
}
use of water.rapids.vals.ValNum in project h2o-3 by h2oai.
the class AstReducerOp method apply.
@Override
public Val apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
// NOTE: no *initial* value needed for the reduction. Instead, the
// reduction op is used between pairs of actual values, and never against
// the empty list. NaN is returned if there are *no* values in the
// reduction.
double d = Double.NaN;
for (int i = 1; i < asts.length; i++) {
Val val = asts[i].exec(env);
double d2 = val.isFrame() ? new AstReducerOp.RedOp().doAll(stk.track(val).getFrame())._d : val.getNum();
if (i == 1)
d = d2;
else
d = op(d, d2);
}
return new ValNum(d);
}
use of water.rapids.vals.ValNum in project h2o-3 by h2oai.
the class AstRollupOp method apply.
@Override
public Val apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Val arg1 = asts[1].exec(env);
if (arg1.isRow()) {
// Row-wise operation
double[] ds = arg1.getRow();
double d = ds[0];
for (int i = 1; i < ds.length; i++) d = op(d, ds[i]);
return new ValRow(new double[] { d }, null);
}
// Normal column-wise operation
Frame fr = stk.track(arg1).getFrame();
Vec[] vecs = fr.vecs();
if (vecs.length == 0 || vecs[0].naCnt() > 0)
return new ValNum(Double.NaN);
double d = rup(vecs[0]);
for (int i = 1; i < vecs.length; i++) {
if (vecs[i].naCnt() > 0)
return new ValNum(Double.NaN);
d = op(d, rup(vecs[i]));
}
return new ValNum(d);
}
Aggregations