@Override protected Integer getValue(IntValue value) { return value.getValue(); } }
@Override public void aggregate(IntValue value) { agg += value.getValue(); }
@Override public int compareTo(Result<T> o) { // exact comparison of a/b with x/y using only integer math: // a/b <?> x/y == a*y <?> b*x long ay = sharedNeighborCount.getValue() * (long) o.distinctNeighborCount.getValue(); long bx = distinctNeighborCount.getValue() * (long) o.sharedNeighborCount.getValue(); return Long.compare(ay, bx); }
@Override public IntValue copy(IntValue from, IntValue reuse) { reuse.setValue(from.getValue()); return reuse; }
/** * Get the Jaccard Index score, equal to the number of shared neighbors * of the source and target vertices divided by the number of distinct * neighbors. * * @return Jaccard Index score */ public double getJaccardIndexScore() { return getSharedNeighborCount().getValue() / (double) getDistinctNeighborCount().getValue(); }
@Override public boolean filter(Tuple2<IntValue, IntValue> value) throws Exception { return (value.f0.getValue() % 2) == 0; } });
@Override public boolean add(IntValue value) { int newPosition = position + 1; if (newPosition > data.length) { if (isBounded) { return false; } else { ensureCapacity(newPosition); } } data[position] = value.getValue(); position = newPosition; return true; }
@Override public void flatMap(Tuple4<IntValue, T, T, FloatValue> value, Collector<Tuple4<IntValue, T, T, FloatValue>> out) throws Exception { int spans = value.f0.getValue(); for (int idx = 0; idx < spans; idx++) { value.f0.setValue(idx); out.collect(value); } } }
@Override public LongValueWithProperHashCode translate(IntValue value, LongValueWithProperHashCode reuse) throws Exception { if (reuse == null) { reuse = new LongValueWithProperHashCode(); } reuse.setValue(0xffffffffL & (long) value.getValue()); return reuse; } }
@Override public void flatMap(Tuple4<IntValue, T, T, IntValue> value, Collector<Tuple4<IntValue, T, T, IntValue>> out) throws Exception { int spans = value.f0.getValue(); for (int idx = 0; idx < spans; idx++) { value.f0.setValue(idx); out.collect(value); } } }
@Override public void reduce(Iterable<Tuple3<T, T, IntValue>> values, Collector<Result<T>> out) throws Exception { int count = 0; Tuple3<T, T, IntValue> edge = null; for (Tuple3<T, T, IntValue> next : values) { edge = next; count += 1; } int distinctNeighbors = edge.f2.getValue() - count; if (unboundedScores || (count * minimumScoreDenominator >= distinctNeighbors * minimumScoreNumerator && count * maximumScoreDenominator <= distinctNeighbors * maximumScoreNumerator)) { output.setVertexId0(edge.f0); output.setVertexId1(edge.f1); output.setSharedNeighborCount(count); output.setDistinctNeighborCount(distinctNeighbors); out.collect(output); } } }
assertEquals(111, ((IntValue) values[0]).getValue()); assertEquals(222, ((IntValue) values[1]).getValue()); assertEquals(333, ((IntValue) values[2]).getValue()); assertEquals(444, ((IntValue) values[3]).getValue()); assertEquals(555, ((IntValue) values[4]).getValue()); assertEquals(666, ((IntValue) values[0]).getValue()); assertEquals(777, ((IntValue) values[1]).getValue()); assertEquals(888, ((IntValue) values[2]).getValue()); assertEquals(999, ((IntValue) values[3]).getValue()); assertEquals(000, ((IntValue) values[4]).getValue());
assertEquals(111, ((IntValue) values[0]).getValue()); assertEquals(444, ((IntValue) values[1]).getValue()); assertEquals(888, ((IntValue) values[2]).getValue()); assertEquals(000, ((IntValue) values[0]).getValue()); assertEquals(777, ((IntValue) values[1]).getValue()); assertEquals(333, ((IntValue) values[2]).getValue());
assertEquals(111, ((IntValue) values[0]).getValue()); assertEquals(444, ((IntValue) values[1]).getValue()); assertEquals(888, ((IntValue) values[2]).getValue()); assertEquals(000, ((IntValue) values[0]).getValue()); assertEquals(777, ((IntValue) values[1]).getValue()); assertEquals(333, ((IntValue) values[2]).getValue());
public void testReduce(ExecutionEnvironment env) throws Exception { /* * Test ChainedAllReduceDriver */ LOG.info("Testing reduce"); env.getConfig().enableObjectReuse(); Tuple2<IntValue, IntValue> enabledResult = getDataSet(env) .reduce(new OverwriteObjectsReduce(false)) .collect() .get(0); env.getConfig().disableObjectReuse(); Tuple2<IntValue, IntValue> disabledResult = getDataSet(env) .reduce(new OverwriteObjectsReduce(false)) .collect() .get(0); Assert.assertEquals(NUMBER_OF_ELEMENTS, enabledResult.f1.getValue()); Assert.assertEquals(NUMBER_OF_ELEMENTS, disabledResult.f1.getValue()); Assert.assertEquals(disabledResult, enabledResult); }
@Test public void testClear() throws IOException { try { Record record = new Record(new IntValue(42)); record.write(this.out); Assert.assertEquals(42, record.getField(0, IntValue.class).getValue()); record.setField(0, new IntValue(23)); record.write(this.out); Assert.assertEquals(23, record.getField(0, IntValue.class).getValue()); record.clear(); Assert.assertEquals(0, record.getNumFields()); Record record2 = new Record(new IntValue(42)); record2.read(in); Assert.assertEquals(42, record2.getField(0, IntValue.class).getValue()); record2.read(in); Assert.assertEquals(23, record2.getField(0, IntValue.class).getValue()); } catch (Throwable t) { Assert.fail("Test failed due to an exception: " + t.getMessage()); } }