use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class MockMasterComputation method assertStep1Aggregators.
protected void assertStep1Aggregators(MasterComputationContext context) {
Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
Assert.assertEquals(new FloatValue(5.2f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
Assert.assertEquals(new FloatValue(3.14f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
Assert.assertEquals(new IntValue(9), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
Assert.assertEquals(new LongValue(5L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
Assert.assertEquals(new DoubleValue(10.4), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class MockMasterComputation2 method assertStep1Aggregators.
@Override
protected void assertStep1Aggregators(MasterComputationContext context) {
Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
Assert.assertEquals(new FloatValue(6.28f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
Assert.assertEquals(new IntValue(9), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
Assert.assertEquals(new LongValue(10L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
Assert.assertEquals(new FloatValue(20.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
Assert.assertEquals(new DoubleValue(20.8), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class MockComputation method assertStep1Aggregators.
protected void assertStep1Aggregators(WorkerContext context) {
Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
Assert.assertEquals(new FloatValue(5.2f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
Assert.assertEquals(new FloatValue(8.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
Assert.assertEquals(new IntValue(888), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
Assert.assertEquals(new LongValue(5L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
Assert.assertEquals(new DoubleValue(10.4), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class ComputeMessageRecvPartitionTest method checkTenCombineMessages.
public static void checkTenCombineMessages(PeekableIterator<KvEntry> it) throws IOException {
Assert.assertTrue(it.hasNext());
KvEntry lastEntry = it.next();
Id lastId = ReceiverUtil.readId(lastEntry.key());
DoubleValue lastSumValue = new DoubleValue();
ReceiverUtil.readValue(lastEntry.value(), lastSumValue);
while (it.hasNext()) {
KvEntry currentEntry = it.next();
Id currentId = ReceiverUtil.readId(currentEntry.key());
DoubleValue currentValue = new DoubleValue();
ReceiverUtil.readValue(lastEntry.value(), currentValue);
if (lastId.equals(currentId)) {
lastSumValue.value(lastSumValue.value() + currentValue.value());
} else {
Assert.assertEquals((Long) lastId.asObject() * 2.0D, lastSumValue.value(), 0.0D);
}
}
Assert.assertEquals((Long) lastId.asObject() * 2.0D, lastSumValue.value(), 0.0D);
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class WriteBufferTest method testWriteVertexWithEdgeFreq.
@Test
public void testWriteVertexWithEdgeFreq() throws IOException {
GraphFactory graphFactory = context.graphFactory();
Vertex vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
vertex.addEdge(graphFactory.createEdge("watch", "2222", BytesId.of(4L)));
WriteBuffer buffer;
UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "SINGLE");
buffer = new WriteBuffer(ComputerContext.instance(), 100, 110);
buffer.writeEdges(vertex);
long position1 = buffer.output().position();
Assert.assertGt(0L, position1);
UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "SINGLE_PER_LABEL");
// Pass a new context object, because config has updated
buffer = new WriteBuffer(ComputerContext.instance(), 100, 110);
buffer.writeEdges(vertex);
long position2 = buffer.output().position();
Assert.assertGte(position1, position2);
UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "MULTIPLE");
// Pass a new context object, because config has updated
buffer = new WriteBuffer(ComputerContext.instance(), 100, 110);
buffer.writeEdges(vertex);
long position3 = buffer.output().position();
Assert.assertGte(position2, position3);
}
Aggregations