TableSummarizer extends BaseSummarizer { public static TableSummarizer merge(TableSummarizer left, TableSummarizer right) { if (right.count == 0) { return left; } if (left.count == 0) { return right.copy(); } left.count += right.count; left.numMissingValue.plusEqual(right.numMissingValue); left.sum.plusEqual(right.sum); left.squareSum.plusEqual(right.squareSum); left.normL1.plusEqual(right.normL1); MatVecOp.apply(left.min, right.min, left.min, Math::min); MatVecOp.apply(left.max, right.max, left.max, Math::max); if (left.outerProduct != null && right.outerProduct != null) { left.outerProduct.plusEquals(right.outerProduct); left.xSum.plusEquals(right.xSum); left.xSquareSum.plusEquals(right.xSquareSum); left.xyCount.plusEquals(right.xyCount); } else if (left.outerProduct == null && right.outerProduct != null) { left.outerProduct = right.outerProduct.clone(); left.xSum = right.xSum.clone(); left.xSquareSum = right.xSquareSum.clone(); left.xyCount = right.xyCount.clone(); } return left; } private  TableSummarizer();  TableSummarizer(String[] selectedColNames, int[] numericalColIndices, boolean calculateOuterProduct); BaseSummarizer visit(Row row); static TableSummarizer merge(TableSummarizer left, TableSummarizer right); @Override String toString(); TableSummary toSummary(); @Override CorrelationResult correlation(); @Override DenseMatrix covariance(); public String[] colNames; }
@Test public void testMerge() { TableSummarizer summarizer = testWithMerge(false); Assert.assertEquals(4, summarizer.count); Assert.assertArrayEquals(new double[]{3.0, 3.0, 1.0}, summarizer.sum.getData(), 10e-4); Assert.assertArrayEquals(new double[]{5.0, 5.0, 17.0}, summarizer.squareSum.getData(), 10e-4); Assert.assertArrayEquals(new double[]{0.0, 0.0, -3.0}, summarizer.min.getData(), 10e-4); Assert.assertArrayEquals(new double[]{2.0, 2.0, 2.0}, summarizer.max.getData(), 10e-4); }