VectorBinaryAggregate { public abstract double aggregate(Vector x, Vector y, DoubleDoubleFunction fa, DoubleDoubleFunction fc);  abstract boolean isValid(Vector x, Vector y, DoubleDoubleFunction fa, DoubleDoubleFunction fc); abstract double estimateCost(Vector x, Vector y, DoubleDoubleFunction fa, DoubleDoubleFunction fc); abstract double aggregate(Vector x, Vector y, DoubleDoubleFunction fa, DoubleDoubleFunction fc); static VectorBinaryAggregate getBestOperation(Vector x, Vector y, DoubleDoubleFunction fa,
                                                       DoubleDoubleFunction fc); static double aggregateBest(Vector x, Vector y, DoubleDoubleFunction fa, DoubleDoubleFunction fc); static final VectorBinaryAggregate[] OPERATIONS; }
@Test public void testSelf() { Vector x = first.like(); Vector xBase = new DenseVector(CARDINALITY); List<Double> items = Lists.newArrayList(); for (int i = 0; i < x.size(); ++i) { items.add(r.nextDouble()); } for (int i = 1; i < x.size(); ++i) { x.setQuick(i, items.get(i)); xBase.setQuick(i, items.get(i)); } Vector y = second.like().assign(x); Vector yBase = new DenseVector(x); System.out.printf("aggregator %s; combiner %s; operation %s\n", aggregator, combiner, operation); double expectedResult = combiner.apply(0, 0); for (int i = 1; i < x.size(); ++i) { expectedResult = aggregator.apply(expectedResult, combiner.apply(items.get(i), items.get(i))); } double result = operation.aggregate(x, y, aggregator, combiner); double resultBase = operation.aggregate(xBase, yBase, aggregator, combiner); assertEquals(expectedResult, result, 0.0); assertEquals(resultBase, result, 0.0); }
@Test public void testSeparate() { List<Double> items1 = Lists.newArrayList(); List<Double> items2 = Lists.newArrayList(); for (int i = 0; i < CARDINALITY; ++i) { items1.add(r.nextDouble()); items2.add(r.nextDouble()); } Vector x = first.like(); Vector xBase = new DenseVector(CARDINALITY); for (int i = 0; i < x.size(); ++i) { x.setQuick(i, items1.get(i)); xBase.setQuick(i, items1.get(i)); } Vector y = second.like(); Vector yBase = new DenseVector(CARDINALITY); for (int i = 0; i < y.size(); ++i) { y.setQuick(i, items2.get(i)); yBase.setQuick(i, items2.get(i)); } System.out.printf("aggregator %s; combiner %s; operation %s\n", aggregator, combiner, operation); double expectedResult = combiner.apply(items1.get(0), items2.get(0)); for (int i = 1; i < x.size(); ++i) { expectedResult = aggregator.apply(expectedResult, combiner.apply(items1.get(i), items2.get(i))); } double result = operation.aggregate(x, y, aggregator, combiner); double resultBase = operation.aggregate(xBase, yBase, aggregator, combiner); assertEquals(expectedResult, result, 0.0); assertEquals(resultBase, result, 0.0); }