Search in sources :

Example 66 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class AstTokenizeTest method testTokenize.

@Test
public void testTokenize() {
    Frame fr = makeTestFrame();
    Vec expected = svec("Foot", "on", "the", "pedal", "Never", "ever", "false", "metal", null, "Engine", "running", "hotter", "than", "a", "boiling", "kettle", "My", "job", "ain't", "a", "job", null, "It's", "a", "damn", "good", "time", "City", "to", "city", "I'm", "running", "my", "rhymes", null);
    Frame res = null;
    try {
        ValFrame val = (ValFrame) Rapids.exec("(tmp= py_1 (tokenize data \"\\\\s\"))");
        res = val.getFrame();
        Vec actual = res.anyVec();
        assertStringVecEquals(expected, actual);
    } finally {
        fr.remove();
        expected.remove();
        if (res != null)
            res.remove();
    }
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec) Test(org.junit.Test)

Example 67 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class RapidsTest method testProstate_assign_frame_scalar.

@Test
public void testProstate_assign_frame_scalar() {
    Frame fr = parse_test_file(Key.make("prostate.hex"), "smalldata/logreg/prostate.csv");
    try {
        Val val = Rapids.exec("(tmp= py_1 (:= prostate.hex -1 1 (== (cols_py prostate.hex 1) 0)))");
        if (val instanceof ValFrame) {
            Frame fr2 = val.getFrame();
            System.out.println(fr2.vec(0));
            fr2.remove();
        }
    } finally {
        fr.delete();
    }
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 68 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class RapidsTest method testCombo.

@Test
public void testCombo() {
    Frame fr = parse_test_file(Key.make("a.hex"), "smalldata/iris/iris_wheader.csv");
    String tree = "(tmp= py_2 (:= (tmp= py_1 (cbind a.hex (== (cols_py a.hex 4.0 ) \"Iris-setosa\" ) ) ) (as.factor (cols_py py_1 5.0 ) ) 5.0 [] ) )";
    //String tree = "(:= (tmp= py_1 a.hex) (h2o.runif a.hex -1) 4 [])";
    Val val = Rapids.exec(tree);
    if (val instanceof ValFrame) {
        Frame fr2 = val.getFrame();
        System.out.println(fr2.vec(0));
        fr2.remove();
    }
    fr.delete();
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 69 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class SortTest method testBasicSortRapids.

@Test
public void testBasicSortRapids() {
    Frame fr = null, res = null;
    // Stable sort columns 1 and 2
    String tree = "(sort hex [1 2])";
    try {
        // Build a frame which is unsorted on small-count categoricals in columns
        // 0 and 1, and completely sorted on a record-number based column 2.
        // Sort will be on columns 0 and 1, in that order, and is expected stable.
        fr = buildFrame(1000, 10);
        fr.insertVec(0, "row", fr.remove(2));
        //
        Val val = Rapids.exec(tree);
        assertTrue(val instanceof ValFrame);
        res = val.getFrame();
        res.add("row", res.remove(0));
        new CheckSort().doAll(res);
    } finally {
        if (fr != null)
            fr.delete();
        if (res != null)
            res.delete();
    }
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Test(org.junit.Test)

Example 70 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class AstCumuTest method testCumuSimple.

@Test
public void testCumuSimple() {
    Scope.enter();
    try {
        Session sess = new Session();
        new TestFrameBuilder().withName("$fr", sess).withColNames("c1", "c2", "c3", "c4").withDataForCol(0, ard(1, 1)).withDataForCol(1, ard(2, 2)).withDataForCol(2, ard(3, 3)).withDataForCol(3, ard(4, 4)).build();
        Val val = Rapids.exec("(cumsum $fr 1)", sess);
        Assert.assertTrue(val instanceof ValFrame);
        Frame res = Scope.track(val.getFrame());
        Assert.assertEquals(res.vec(0).at8(0L), 1);
        Assert.assertEquals(res.vec(1).at8(0L), 3);
        Assert.assertEquals(res.vec(2).at8(0L), 6);
        Assert.assertEquals(res.vec(3).at8(0L), 10);
        val = Rapids.exec("(cumsum $fr 0)", sess);
        Assert.assertTrue(val instanceof ValFrame);
        res = Scope.track(val.getFrame());
        Assert.assertEquals(res.vec(0).at8(1L), 2);
        Assert.assertEquals(res.vec(1).at8(1L), 4);
        Assert.assertEquals(res.vec(2).at8(1L), 6);
        Assert.assertEquals(res.vec(3).at8(1L), 8);
        val = Rapids.exec("(cummax $fr 1)", sess);
        Assert.assertTrue(val instanceof ValFrame);
        res = Scope.track(val.getFrame());
        Assert.assertEquals(res.vec(0).at8(0L), 1);
        Assert.assertEquals(res.vec(1).at8(0L), 2);
        Assert.assertEquals(res.vec(2).at8(0L), 3);
        Assert.assertEquals(res.vec(3).at8(0L), 4);
    } finally {
        Scope.exit();
    }
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) TestFrameBuilder(water.fvec.TestFrameBuilder) Session(water.rapids.Session) Test(org.junit.Test)

Aggregations

ValFrame (water.rapids.vals.ValFrame)132 Frame (water.fvec.Frame)98 Val (water.rapids.Val)48 Vec (water.fvec.Vec)43 Test (org.junit.Test)38 MRTask (water.MRTask)32 Chunk (water.fvec.Chunk)24 NewChunk (water.fvec.NewChunk)23 BufferedString (water.parser.BufferedString)16 AstNumList (water.rapids.ast.params.AstNumList)11 AstNum (water.rapids.ast.params.AstNum)7 ValNum (water.rapids.vals.ValNum)7 AstRoot (water.rapids.ast.AstRoot)6 ValRow (water.rapids.vals.ValRow)6 ArrayList (java.util.ArrayList)5 Key (water.Key)5 AstStrList (water.rapids.ast.params.AstStrList)5 Futures (water.Futures)4 AstParameter (water.rapids.ast.AstParameter)4 Random (java.util.Random)3