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);
}
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();
}
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();
}
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);
}
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();
}
Aggregations