Search in sources :

Example 76 with Key

use of water.Key in project h2o-3 by h2oai.

the class ParserTestARFF method testNum.

@Test
public void testNum() {
    String data = "@RELATION type\n" + "\n" + "@ATTRIBUTE num numeric\n" + "\n" + "@DATA\n" + "0\n" + "1.324e-13\n" + "-2\n";
    double[][] exp = new double[][] { ard(0), ard(1.324e-13), ard(-2) };
    Key k = ParserTest.makeByteVec(data);
    ParserTest.testParsed(ParseDataset.parse(Key.make(), k), exp, 3);
}
Also used : Key(water.Key) Test(org.junit.Test)

Example 77 with Key

use of water.Key in project h2o-3 by h2oai.

the class C2ChunkTest method test_setNA.

@Test
public void test_setNA() {
    // Create a vec with one chunk with 15 elements, and set its numbers
    Key key = Vec.newKey();
    Vec vec = new Vec(key, Vec.ESPC.rowLayout(key, new long[] { 0, 15 })).makeZero();
    int[] vals = new int[] { 0, 3, 0, 6, 0, 0, 0, -32767, 0, 12, 234, 32767, 0, 0, 19 };
    Vec.Writer w = vec.open();
    for (int i = 0; i < vals.length; ++i) w.set(i, vals[i]);
    w.close();
    Chunk cc = vec.chunkForChunkIdx(0);
    assert cc instanceof C2Chunk;
    Futures fs = new Futures();
    fs.blockForPending();
    for (int i = 0; i < vals.length; ++i) Assert.assertEquals(vals[i], cc.at8(i));
    for (int i = 0; i < vals.length; ++i) Assert.assertEquals(vals[i], cc.at8_abs(i));
    int[] NAs = new int[] { 1, 5, 2 };
    int[] notNAs = new int[] { 0, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
    for (int na : NAs) cc.setNA_abs(na);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    NewChunk nc = new NewChunk(null, 0);
    cc.extractRows(nc, 0, (int) vec.length());
    Assert.assertEquals(vals.length, nc._sparseLen);
    Assert.assertEquals(vals.length, nc._len);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    Chunk cc2 = nc.compress();
    Assert.assertEquals(vals.length, cc._len);
    Assert.assertTrue(cc2 instanceof C2Chunk);
    for (int na : NAs) Assert.assertTrue(cc.isNA(na));
    for (int na : NAs) Assert.assertTrue(cc.isNA_abs(na));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA(notna));
    for (int notna : notNAs) Assert.assertTrue(!cc.isNA_abs(notna));
    Assert.assertTrue(Arrays.equals(cc._mem, cc2._mem));
    vec.remove();
}
Also used : Futures(water.Futures) Key(water.Key)

Example 78 with Key

use of water.Key in project h2o-3 by h2oai.

the class ParserTest2 method testSingleQuotes.

@Test
public void testSingleQuotes() {
    String[] data = new String[] { "'Tomass,test,first,line'\n'Tomas''s,test2',test2\nlast,'line''", "s, trailing, piece'" };
    String[][] expectFalse = new String[][] { ar("'Tomass", "test", "first", "line'"), ar("'Tomas''s", "test2'", "test2", null), ar("last", "'line''s", "trailing", "piece'") };
    Key k = ParserTest.makeByteVec(data);
    ParseSetup gSetupF = ParseSetup.guessSetup(null, StringUtils.bytesOf(data[0]), CSV_INFO, (byte) ',', 4, false, /*single quote*/
    ParseSetup.NO_HEADER, null, null, null, null);
    gSetupF._column_types = ParseSetup.strToColumnTypes(new String[] { "Enum", "Enum", "Enum", "Enum" });
    Frame frF = ParseDataset.parse(Key.make(), new Key[] { k }, false, gSetupF);
    testParsed(frF, expectFalse);
    String[][] expectTrue = new String[][] { ar("Tomass,test,first,line", null), ar("Tomas''stest2", "test2"), ar("last", "lines trailing piece") };
    ParseSetup gSetupT = ParseSetup.guessSetup(null, StringUtils.bytesOf(data[0]), CSV_INFO, (byte) ',', 2, true, /*single quote*/
    ParseSetup.NO_HEADER, null, null, null, null);
    gSetupT._column_types = ParseSetup.strToColumnTypes(new String[] { "Enum", "Enum", "Enum", "Enum" });
    Frame frT = ParseDataset.parse(Key.make(), new Key[] { k }, true, gSetupT);
    //testParsed(frT,expectTrue);  // not currently passing
    frT.delete();
}
Also used : Frame(water.fvec.Frame) Key(water.Key) Test(org.junit.Test)

Example 79 with Key

use of water.Key in project h2o-3 by h2oai.

the class ParserTest2 method testSparse.

// Test very sparse data
@Test
public void testSparse() {
    // Build 100 zero's and 1 one.
    double[][] exp = new double[101][1];
    exp[50][0] = 1;
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 50; i++) sb.append("0.0\n");
    sb.append("1.0\n");
    for (int i = 0; i < 50; i++) sb.append("0.0\n");
    Key k = ParserTest.makeByteVec(sb.toString());
    ParserTest.testParsed(ParseDataset.parse(Key.make(), k), exp, 101);
    // Build 100 zero's and 1 non-zero.
    exp = new double[101][1];
    exp[50][0] = 2;
    sb = new StringBuilder();
    for (int i = 0; i < 50; i++) sb.append("0\n");
    sb.append("2\n");
    for (int i = 0; i < 50; i++) sb.append("0\n");
    k = ParserTest.makeByteVec(sb.toString());
    ParserTest.testParsed(ParseDataset.parse(Key.make(), k), exp, 101);
    // Build 100 zero's and some non-zeros.  Last line is truncated.
    for (char sep : SEPARATORS) {
        exp = new double[101][2];
        exp[50][0] = 2;
        exp[50][1] = 3;
        // Truncated final line
        exp[100][0] = 0;
        exp[100][1] = Double.NaN;
        sb = new StringBuilder();
        for (int i = 0; i < 50; i++) sb.append("0").append(sep).append("0\n");
        sb.append("2").append(sep).append("3\n");
        for (int i = 0; i < 49; i++) sb.append("0").append(sep).append("0\n");
        // Truncated final line
        sb.append("0");
        k = ParserTest.makeByteVec(sb.toString());
        ParserTest.testParsed(ParseDataset.parse(Key.make(), k), exp, 101);
    }
    // Build 100000 zero's and some one's
    sb = new StringBuilder();
    exp = new double[100100][1];
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 1000; j++) sb.append("0\n");
        sb.append("1\n");
        exp[i * 1001 + 1000][0] = 1;
    }
    k = ParserTest.makeByteVec(sb.toString());
    ParserTest.testParsed(ParseDataset.parse(Key.make(), k), exp, 100100);
    // Build 100 zero's, then 100 mix of -1001 & 1001's (to force a
    // sparse-short, that finally inflates to a full dense-short).
    sb = new StringBuilder();
    for (int i = 0; i < 100; i++) sb.append("0\n");
    for (int i = 0; i < 100; i += 2) sb.append("-1001\n1001\n");
    exp = new double[200][1];
    for (int i = 0; i < 100; i += 2) {
        exp[i + 100][0] = -1001;
        exp[i + 101][0] = 1001;
    }
    k = ParserTest.makeByteVec(sb.toString());
    ParserTest.testParsed(ParseDataset.parse(Key.make(), k), exp, 200);
}
Also used : PrettyPrint(water.util.PrettyPrint) Key(water.Key) Test(org.junit.Test)

Example 80 with Key

use of water.Key in project h2o-3 by h2oai.

the class ParserTestARFF method testMultipleFilesString.

@Test
public void testMultipleFilesString() {
    String data1 = "@RELATION type\n" + "\n" + "@ATTRIBUTE num STRING\n" + "\n" + "@DATA\n" + "0\n" + "1.324e-13\n" + "-2\n";
    Key k1 = ParserTest.makeByteVec(data1);
    Key k2 = ParserTest.makeByteVec(data1);
    Key k3 = ParserTest.makeByteVec(data1);
    Key[] k = new Key[] { k1, k2, k3 };
    Frame fr = ParseDataset.parse(Key.make(), k);
    Assert.assertTrue(fr.anyVec().isString());
    Assert.assertFalse(fr.anyVec().isCategorical());
    Assert.assertFalse(fr.anyVec().isInt());
    BufferedString tmpStr = new BufferedString();
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 0).toString().equals("0"));
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 1).toString().equals("1.324e-13"));
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 2).toString().equals("-2"));
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 3).toString().equals("0"));
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 4).toString().equals("1.324e-13"));
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 5).toString().equals("-2"));
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 6).toString().equals("0"));
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 7).toString().equals("1.324e-13"));
    Assert.assertTrue(fr.anyVec().atStr(tmpStr, 8).toString().equals("-2"));
    fr.delete();
}
Also used : Frame(water.fvec.Frame) Key(water.Key) Test(org.junit.Test)

Aggregations

Key (water.Key)94 Frame (water.fvec.Frame)56 Test (org.junit.Test)42 Vec (water.fvec.Vec)21 File (java.io.File)18 NFSFileVec (water.fvec.NFSFileVec)17 Futures (water.Futures)10 Random (java.util.Random)7 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)6 ValFrame (water.rapids.vals.ValFrame)6 DateTimeZone (org.joda.time.DateTimeZone)5 Model (hex.Model)4 SplitFrame (hex.SplitFrame)4 DeepLearning (hex.deeplearning.DeepLearning)4 DeepLearningModel (hex.deeplearning.DeepLearningModel)4 AppendableVec (water.fvec.AppendableVec)4 NewChunk (water.fvec.NewChunk)4 Grid (hex.grid.Grid)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3