Search in sources :

Example 1 with ValNum

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());
    }
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec) ValStr(water.rapids.vals.ValStr) BufferedString(water.parser.BufferedString) ValNum(water.rapids.vals.ValNum)

Example 2 with ValNum

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);
}
Also used : Frame(water.fvec.Frame) Model(hex.Model) Iced(water.Iced) ValNum(water.rapids.vals.ValNum) Key(water.Key)

Example 3 with ValNum

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);
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) ValNum(water.rapids.vals.ValNum)

Example 4 with ValNum

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);
}
Also used : Val(water.rapids.Val) ValNum(water.rapids.vals.ValNum)

Example 5 with ValNum

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);
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) ValRow(water.rapids.vals.ValRow) Vec(water.fvec.Vec) ValNum(water.rapids.vals.ValNum)

Aggregations

ValNum (water.rapids.vals.ValNum)20 Frame (water.fvec.Frame)15 Vec (water.fvec.Vec)11 ValFrame (water.rapids.vals.ValFrame)8 MRTask (water.MRTask)6 Key (water.Key)4 NewChunk (water.fvec.NewChunk)4 Val (water.rapids.Val)4 Chunk (water.fvec.Chunk)3 ValRow (water.rapids.vals.ValRow)3 BufferedString (water.parser.BufferedString)2 Model (hex.Model)1 QuantileModel (hex.quantile.QuantileModel)1 MutableDateTime (org.joda.time.MutableDateTime)1 Iced (water.Iced)1 Value (water.Value)1 AstExec (water.rapids.ast.AstExec)1 AstId (water.rapids.ast.params.AstId)1 ValStr (water.rapids.vals.ValStr)1