Search in sources :

Example 6 with FloatValue

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

the class FloatValueSumCombinerTest method testCombine.

@Test
public void testCombine() {
    FloatValue sum = new FloatValue(0.0f);
    FloatValueSumCombiner combiner = new FloatValueSumCombiner();
    for (int i = 1; i <= 10; i++) {
        FloatValue value = new FloatValue(i);
        combiner.combine(sum, value, sum);
    }
    Assert.assertEquals(55.0D, sum.value(), 0.0D);
}
Also used : FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) Test(org.junit.Test)

Example 7 with FloatValue

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

the class JsonStructGraphOutputTest method testWriteReadVertexWithProperties.

@Test
public void testWriteReadVertexWithProperties() throws IOException {
    UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "false", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "true", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false", ComputerOptions.OUTPUT_RESULT_NAME, "rank");
    ComputerContext context = context();
    GraphFactory factory = context.graphFactory();
    Id longId = BytesId.of(100L);
    IdListList idListList = new IdListList();
    IdList idList1 = new IdList();
    idList1.add(BytesId.of(66L));
    IdList idList2 = new IdList();
    idList2.add(BytesId.of(998L));
    idList2.add(BytesId.of(999L));
    idListList.add(idList1);
    idListList.add(idList2);
    Vertex vertex = factory.createVertex(longId, idListList);
    vertex.properties().put("boolean", new BooleanValue(true));
    vertex.properties().put("byte", new IntValue(127));
    vertex.properties().put("short", new IntValue(16383));
    vertex.properties().put("int", new IntValue(1000000));
    vertex.properties().put("long", new LongValue(10000000000L));
    vertex.properties().put("float", new FloatValue(0.1F));
    vertex.properties().put("double", new DoubleValue(-0.01D));
    vertex.properties().put("idvalue", longId);
    String fileName = "output.json";
    File file = new File(fileName);
    try {
        BufferedFileOutput dos = new BufferedFileOutput(file);
        StructGraphOutput output = (StructGraphOutput) IOFactory.createGraphOutput(context, OutputFormat.JSON, dos);
        output.writeVertex(vertex);
        dos.close();
        @SuppressWarnings("deprecation") String json = FileUtils.readFileToString(file);
        Assert.assertEquals("{\"id\":100,\"rank\":[[66],[998,999]]," + "\"properties\":{\"boolean\":true," + "\"byte\":127,\"double\":-0.01," + "\"short\":16383,\"idvalue\":100," + "\"float\":0.1,\"int\":1000000," + "\"long\":10000000000}}" + System.lineSeparator(), json);
    } finally {
        FileUtils.deleteQuietly(file);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BooleanValue(com.baidu.hugegraph.computer.core.graph.value.BooleanValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) File(java.io.File) Test(org.junit.Test)

Example 8 with FloatValue

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

the class CsvStructGraphOutputTest method testWriteReadVertexWithProperties.

@Test
public void testWriteReadVertexWithProperties() throws IOException {
    UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "false", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "true", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false");
    ComputerContext context = context();
    GraphFactory factory = context.graphFactory();
    Id longId = BytesId.of(100L);
    IdListList idListList = new IdListList();
    IdList idList1 = new IdList();
    idList1.add(BytesId.of(66L));
    IdList idList2 = new IdList();
    idList2.add(BytesId.of(998L));
    idList2.add(BytesId.of(999L));
    idListList.add(idList1);
    idListList.add(idList2);
    Vertex vertex = factory.createVertex(longId, idListList);
    vertex.properties().put("boolean", new BooleanValue(true));
    vertex.properties().put("byte", new IntValue(127));
    vertex.properties().put("short", new IntValue(16383));
    vertex.properties().put("int", new IntValue(1000000));
    vertex.properties().put("long", new LongValue(10000000000L));
    vertex.properties().put("float", new FloatValue(0.1F));
    vertex.properties().put("double", new DoubleValue(-0.01D));
    vertex.properties().put("idvalue", longId);
    String fileName = "output3.csv";
    File file = new File(fileName);
    try {
        BufferedFileOutput dos = new BufferedFileOutput(file);
        StructGraphOutput output = (StructGraphOutput) IOFactory.createGraphOutput(context, OutputFormat.CSV, dos);
        output.writeVertex(vertex);
        dos.close();
        @SuppressWarnings("deprecation") String text = FileUtils.readFileToString(file);
        Assert.assertEquals("100,[[66],[998,999]],{true,127,-0.01,16383," + "100,0.1,1000000,10000000000}" + System.lineSeparator(), text);
    } finally {
        FileUtils.deleteQuietly(file);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BooleanValue(com.baidu.hugegraph.computer.core.graph.value.BooleanValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) File(java.io.File) Test(org.junit.Test)

Example 9 with FloatValue

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

the class FloatValueSumCombinerTest method testCombineNull.

@Test
public void testCombineNull() {
    FloatValue value1 = new FloatValue(0.0f);
    FloatValue value2 = new FloatValue(0.0f);
    FloatValueSumCombiner combiner = new FloatValueSumCombiner();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(null, value2, value2);
    }, e -> {
        Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(value1, null, value2);
    }, e -> {
        Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(value1, value2, null);
    }, e -> {
        Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
    });
}
Also used : FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) Test(org.junit.Test)

Example 10 with FloatValue

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

the class MockMasterComputation method assertStep0Aggregators.

protected void assertStep0Aggregators(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(10), 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