use of water.fvec.NewChunk in project h2o-3 by h2oai.
the class AstBinOp method frame_op_row.
private ValFrame frame_op_row(Frame lf, Frame row) {
final double[] rawRow = new double[row.numCols()];
for (int i = 0; i < rawRow.length; ++i) // is numberlike, if not then NaN
rawRow[i] = row.vec(i).isNumeric() || row.vec(i).isTime() ? row.vec(i).at(0) : Double.NaN;
Frame res = new MRTask() {
@Override
public void map(Chunk[] chks, NewChunk[] cress) {
for (int c = 0; c < cress.length; c++) {
Chunk clf = chks[c];
NewChunk cres = cress[c];
for (int r = 0; r < clf._len; ++r) {
if (clf.vec().isString())
// TODO: improve
cres.addNum(Double.NaN);
else
cres.addNum(op(clf.atd(r), rawRow[c]));
}
}
}
}.doAll(lf.numCols(), Vec.T_NUM, lf).outputFrame(lf._names, null);
return cleanCategorical(lf, res);
}
use of water.fvec.NewChunk in project h2o-3 by h2oai.
the class AstBinOp method frame_op_scalar.
/**
* Auto-widen the scalar to every element of the frame
*/
public ValFrame frame_op_scalar(Frame fr, final double d) {
Frame res = new MRTask() {
@Override
public void map(Chunk[] chks, NewChunk[] cress) {
for (int c = 0; c < chks.length; c++) {
Chunk chk = chks[c];
NewChunk cres = cress[c];
for (int i = 0; i < chk._len; i++) cres.addNum(op(chk.atd(i), d));
}
}
}.doAll(fr.numCols(), Vec.T_NUM, fr).outputFrame(fr._names, null);
// Cleanup categorical misuse
return cleanCategorical(fr, res);
}
use of water.fvec.NewChunk in project h2o-3 by h2oai.
the class AstRectangleConditionalAssignTest method makeTestFrame.
private Frame makeTestFrame() {
Frame fr = null;
Vec v = ivec(1, 2, 3, 4, 5);
try {
fr = new MRTask() {
@Override
public void map(Chunk[] cs, NewChunk[] ncs) {
for (int i = 0; i < cs[0]._len; i++) {
int r = (int) cs[0].atd(i);
ncs[0].addNum(r);
ncs[1].addNum(11.2 * r);
ncs[2].addUUID(r, r * 10);
ncs[3].addStr("row" + r);
ncs[4].addCategorical(r % 2 == 0 ? 0 : 1);
}
}
}.doAll(new byte[] { Vec.T_NUM, Vec.T_NUM, Vec.T_UUID, Vec.T_STR, Vec.T_CAT }, v).outputFrame(Key.make("data"), new String[] { "v1", "v2", "v3", "v4", "v5" }, new String[][] { null, null, null, null, new String[] { "a", "b" } });
} finally {
v.remove();
}
assert fr != null;
return fr;
}
use of water.fvec.NewChunk in project h2o-3 by h2oai.
the class ShuffleSplitFrameTest method testShuffleSplitWithMultipleColumns.
@Test
public /* this test makes sure that the rows of the split frames are preserved (including UUID) */
void testShuffleSplitWithMultipleColumns() {
long[] chunkLayout = ar(2L, 2L, 3L);
String[][] data = ar(ar("1", "2"), ar(null, "3"), ar("4", "5", "6"));
Frame f = null;
Frame tmpFrm = createFrame("test1.hex", chunkLayout, data);
try {
f = new MRTask() {
@Override
public void map(Chunk[] cs, NewChunk[] ncs) {
for (int i = 0; i < cs[0]._len; i++) {
BufferedString bs = cs[0].atStr(new BufferedString(), i);
int val = bs == null ? 0 : Integer.parseInt(bs.toString());
ncs[0].addStr(bs);
ncs[1].addNum(val);
ncs[2].addNum(i);
ncs[3].addUUID(i, val);
}
}
}.doAll(new byte[] { Vec.T_STR, Vec.T_NUM, Vec.T_NUM, Vec.T_UUID }, tmpFrm).outputFrame();
} finally {
tmpFrm.delete();
}
testScenario(f, flat(data), new MRTask() {
@Override
public void map(Chunk[] cs) {
for (int i = 0; i < cs[0]._len; i++) {
BufferedString bs = cs[0].atStr(new BufferedString(), i);
int expectedVal = bs == null ? 0 : Integer.parseInt(bs.toString());
int expectedIndex = (int) cs[2].atd(i);
Assert.assertEquals((double) expectedVal, cs[1].atd(i), 0.00001);
Assert.assertEquals(expectedIndex, (int) cs[3].at16l(i));
Assert.assertEquals(expectedVal, (int) cs[3].at16h(i));
}
}
});
}
use of water.fvec.NewChunk in project h2o-3 by h2oai.
the class SVMLightFVecParseWriter method addColumns.
private void addColumns(int newColCnt) {
int oldColCnt = _vecs.length;
if (newColCnt > oldColCnt) {
_nvs = Arrays.copyOf(_nvs, newColCnt);
_vecs = Arrays.copyOf(_vecs, newColCnt);
for (int i = oldColCnt; i < newColCnt; ++i) {
_vecs[i] = new AppendableVec(_vg.vecKey(i + _vecIdStart), _vecs[0]._tmp_espc, Vec.T_NUM, _vecs[0]._chunkOff);
_nvs[i] = new NewChunk(_vecs[i], _cidx, true);
}
_nCols = newColCnt;
}
}
Aggregations