Search in sources :

Example 11 with FloatValue

use of com.baidu.hugegraph.computer.core.graph.value.FloatValue in project hugegraph-computer by hugegraph.

the class MockMasterComputation method assertAggregatedValueWithError.

private void assertAggregatedValueWithError(MasterComputationContext context) {
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM, new LongValue(7L));
    }, e -> {
        Assert.assertContains("Can't set long value '7' to int aggregator", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM, new IntValue(7));
    }, e -> {
        Assert.assertContains("Can't set int value '7' to long aggregator", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM, new FloatValue(7f));
    }, e -> {
        Assert.assertContains("Can't set float value '7.0' to double ", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN, null);
    }, e -> {
        Assert.assertContains("Can't set value to null for aggregator " + "'aggr_double_min'", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT, null);
    }, e -> {
        Assert.assertContains("Can't set value to null for aggregator " + "'aggr_int'", e.getMessage());
    });
    Assert.assertThrows(ClassCastException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT, new IntValue(7));
    }, e -> {
        Assert.assertContains("IntValue cannot be cast to", e.getMessage());
        Assert.assertContains("FloatValue", e.getMessage());
    });
}
Also used : LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 12 with FloatValue

use of com.baidu.hugegraph.computer.core.graph.value.FloatValue 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));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 13 with FloatValue

use of com.baidu.hugegraph.computer.core.graph.value.FloatValue 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));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 14 with FloatValue

use of com.baidu.hugegraph.computer.core.graph.value.FloatValue in project hugegraph-computer by hugegraph.

the class MockComputation method afterSuperstep.

@Override
public void afterSuperstep(WorkerContext context) {
    context.aggregateValue(MockMasterComputation.AGGR_CUSTOM_INT, this.aggrCustomInt.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_CUSTOM_FLOAT, this.aggrCustomFloat.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE, new FloatValue(3.14f));
    context.aggregateValue(MockMasterComputation.AGGR_INT_UNSTABLE, new IntValue(10 - context.superstep()));
    context.aggregateValue(MockMasterComputation.AGGR_INT_SUM, this.aggrIntSum.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_INT_MAX, this.aggrIntMax.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_LONG_SUM, this.aggrLongSum.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_LONG_MAX, this.aggrLongMax.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_FLOAT_SUM, this.aggrFloatSum.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_FLOAT_MIN, this.aggrFloatMin.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_DOUBLE_SUM, this.aggrDoubleSum.aggregatedValue());
    context.aggregateValue(MockMasterComputation.AGGR_DOUBLE_MIN, this.aggrDoubleMin.aggregatedValue());
    this.assertAggregateValueWithError(context);
}
Also used : FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 15 with FloatValue

use of com.baidu.hugegraph.computer.core.graph.value.FloatValue 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));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Aggregations

FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)17 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)15 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)13 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)12 Test (org.junit.Test)6 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)2 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)2 Id (com.baidu.hugegraph.computer.core.graph.id.Id)2 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)2 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)2 ListValue (com.baidu.hugegraph.computer.core.graph.value.ListValue)2 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)2 File (java.io.File)2 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)1 StringValue (com.baidu.hugegraph.computer.core.graph.value.StringValue)1 ImmutableList (com.google.common.collect.ImmutableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1