Package com.asakusafw.compiler.flow

Examples of com.asakusafw.compiler.flow.FlowGraphGenerator


    /**
     * {@link StageBlock#isEmpty()}
     */
    @Test
    public void isEmpty_hasMapper() {
        FlowGraphGenerator gen = new FlowGraphGenerator();
        gen.defineInput("in1");
        gen.defineOperator("op1", "in", "out");
        gen.defineOperator("op2", "in", "out");
        gen.defineOutput("out1");
        gen.connect("in1", "op1").connect("op1", "op2").connect("op2", "out1");
        FlowBlock bin = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                new ArrayList<FlowElementInput>(gen.inputs()),
                Arrays.asList(gen.output("in1")),
                gen.getAsSet("in1"));
        FlowBlock b1 = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("op1")),
                Arrays.asList(gen.output("op2")),
                gen.getAsSet("op1", "op2"));
        FlowBlock bout = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("out1")),
                new ArrayList<FlowElementOutput>(gen.outputs()),
                gen.getAsSet("out1"));
        FlowBlock.connect(b1.getBlockOutputs().get(0), bout.getBlockInputs().get(0));
        FlowBlock.connect(bin.getBlockOutputs().get(0), b1.getBlockInputs().get(0));
        bin.detach();
        b1.detach();
        bout.detach();
View Full Code Here


    /**
     * {@link StageBlock#isEmpty()}
     */
    @Test
    public void isEmpty_hasReducer() {
        FlowGraphGenerator gen = new FlowGraphGenerator();
        gen.defineInput("in1");
        gen.defineOperator("op1", "in", "out");
        gen.defineOperator("op2", "in", "out", FlowBoundary.SHUFFLE);
        gen.defineOutput("out1");
        gen.connect("in1", "op1").connect("op1", "op2").connect("op2", "out1");
        FlowBlock bin = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                new ArrayList<FlowElementInput>(gen.inputs()),
                Arrays.asList(gen.output("in1")),
                gen.getAsSet("in1"));
        FlowBlock b1 = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("op1")),
                Arrays.asList(gen.output("op1")),
                gen.getAsSet("op1"));
        FlowBlock b2 = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("op2")),
                Arrays.asList(gen.output("op2")),
                gen.getAsSet("op2"));
        FlowBlock bout = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("out1")),
                new ArrayList<FlowElementOutput>(gen.outputs()),
                gen.getAsSet("out1"));
        FlowBlock.connect(bin.getBlockOutputs().get(0), b1.getBlockInputs().get(0));
        FlowBlock.connect(b1.getBlockOutputs().get(0), b2.getBlockInputs().get(0));
        FlowBlock.connect(b2.getBlockOutputs().get(0), bout.getBlockInputs().get(0));
        bin.detach();
        b1.detach();
View Full Code Here

    /**
     * {@link StageBlock#compaction()}
     */
    @Test
    public void compaction_stable() {
        FlowGraphGenerator gen = new FlowGraphGenerator();
        gen.defineInput("in1");
        gen.defineOperator("op1", "in", "out");
        gen.defineOutput("out1");
        gen.connect("in1", "op1").connect("op1", "out1");
        FlowBlock bin = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                new ArrayList<FlowElementInput>(gen.inputs()),
                Arrays.asList(gen.output("in1")),
                gen.getAsSet("in1"));
        FlowBlock b1 = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("op1")),
                Arrays.asList(gen.output("op1")),
                gen.getAsSet("op1"));
        FlowBlock bout = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("out1")),
                new ArrayList<FlowElementOutput>(gen.outputs()),
                gen.getAsSet("out1"));
        FlowBlock.connect(bin.getBlockOutputs().get(0), b1.getBlockInputs().get(0));
        FlowBlock.connect(b1.getBlockOutputs().get(0), bout.getBlockInputs().get(0));
        bin.detach();
        b1.detach();
        bout.detach();
View Full Code Here

    /**
     * {@link StageBlock#compaction()}
     */
    @Test
    public void compaction_hasReducer() {
        FlowGraphGenerator gen = new FlowGraphGenerator();
        gen.defineInput("in1");
        gen.definePseud("op1");
        gen.defineOperator("op2", "in", "out", FlowBoundary.SHUFFLE);
        gen.defineOutput("out1");
        gen.connect("in1", "op1").connect("op1", "op2").connect("op2", "out1");
        FlowBlock bin = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                new ArrayList<FlowElementInput>(gen.inputs()),
                Arrays.asList(gen.output("in1")),
                gen.getAsSet("in1"));
        FlowBlock b1 = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("op1")),
                Arrays.asList(gen.output("op1")),
                gen.getAsSet("op1"));
        FlowBlock b2 = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("op2")),
                Arrays.asList(gen.output("op2")),
                gen.getAsSet("op2"));
        FlowBlock bout = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("out1")),
                new ArrayList<FlowElementOutput>(gen.outputs()),
                gen.getAsSet("out1"));
        FlowBlock.connect(bin.getBlockOutputs().get(0), b1.getBlockInputs().get(0));
        FlowBlock.connect(b1.getBlockOutputs().get(0), b2.getBlockInputs().get(0));
        FlowBlock.connect(b2.getBlockOutputs().get(0), bout.getBlockInputs().get(0));
        bin.detach();
        b1.detach();
View Full Code Here

    /**
     * {@link StageBlock#compaction()}
     */
    @Test
    public void compaction_bypass() {
        FlowGraphGenerator gen = new FlowGraphGenerator();
        gen.defineInput("in1");
        gen.definePseud("id");
        gen.defineOperator("op1", "in", "out");
        gen.defineOutput("out1");
        gen.connect("in1", "id").connect("id", "out1");
        gen.connect("in1", "op1").connect("op1", "out1");
        FlowBlock bin = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                new ArrayList<FlowElementInput>(gen.inputs()),
                Arrays.asList(gen.output("in1")),
                gen.getAsSet("in1"));
        FlowBlock b1 = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("op1"), gen.input("id")),
                Arrays.asList(gen.output("op1"), gen.output("id")),
                gen.getAsSet("op1", "id"));
        FlowBlock bout = FlowBlock.fromPorts(
                0,
                gen.toGraph(),
                Arrays.asList(gen.input("out1")),
                new ArrayList<FlowElementOutput>(gen.outputs()),
                gen.getAsSet("out1"));
        FlowBlock.connect(bin.getBlockOutputs().get(0), b1.getBlockInputs().get(0));
        FlowBlock.connect(bin.getBlockOutputs().get(0), b1.getBlockInputs().get(1));
        FlowBlock.connect(b1.getBlockOutputs().get(0), bout.getBlockInputs().get(0));
        FlowBlock.connect(b1.getBlockOutputs().get(1), bout.getBlockInputs().get(0));
        bin.detach();
        b1.detach();
        bout.detach();

        StageBlock stage = new StageBlock(set(b1), set());
        assertThat(stage.compaction(), is(true));
        assertThat(stage.getMapBlocks().size(), is(1));

        assertThat(b1.getBlockInputs().size(), is(1));
        assertThat(b1.getBlockOutputs().size(), is(1));

        assertThat(b1.getBlockInputs().get(0).getElementPort().getDescription(),
                is(gen.input("op1").getDescription()));
        assertThat(b1.getBlockOutputs().get(0).getElementPort().getDescription(),
                is(gen.output("op1").getDescription()));

        FlowBlock.Output binOut = bin.getBlockOutputs().get(0);
        FlowBlock.Input boutIn = bout.getBlockInputs().get(0);
        assertThat(binOut.getConnections().size(), is(2));
        assertThat(boutIn.getConnections().size(), is(2));
View Full Code Here

    /**
     * {@link FlowPath#transposeIntersect(FlowPath)}
     */
    @Test
    public void transposeIntersect() {
        FlowGraphGenerator gen = new FlowGraphGenerator();
        gen.defineInput("in1");
        gen.defineInput("in2");
        gen.defineOutput("out1");
        gen.defineOutput("out2");
        gen.definePseud("a", FlowBoundary.STAGE);
        gen.definePseud("b", FlowBoundary.STAGE);
        gen.definePseud("c", FlowBoundary.STAGE);
        gen.definePseud("d", FlowBoundary.STAGE);
        gen.definePseud("e", FlowBoundary.STAGE);
        gen.defineOperator("op1", "in", "out");
        gen.defineOperator("op2", "in", "out");

        gen.connect("in1", "a").connect("a", "op1").connect("op1", "c").connect("c", "out1");
        gen.connect("in2", "b").connect("b", "op2").connect("op2", "d").connect("d", "out2");
        gen.connect("op1", "e").connect("e", "out2");

        FlowPath a = FlowGraphUtil.getSucceedBoundaryPath(gen.get("a"));
        FlowPath b = FlowGraphUtil.getPredeceaseBoundaryPath(gen.get("e"));

        FlowPath path = a.transposeIntersect(b);
        assertThat(path.getStartings(), is(gen.getAsSet("a")));
        assertThat(path.getPassings(), is(gen.getAsSet("op1")));
        assertThat(path.getArrivals(), is(gen.getAsSet("e")));
    }
View Full Code Here

    /**
     * {@link FlowPath#createBlock(FlowGraph, int, boolean, boolean)}
     */
    @Test
    public void createBlock_includeIn_includeOut() {
        FlowGraphGenerator gen = graph();
        FlowPath a = FlowGraphUtil.getSucceedBoundaryPath(gen.get("a"));
        FlowPath b = FlowGraphUtil.getSucceedBoundaryPath(gen.get("b"));
        FlowPath c = FlowGraphUtil.getSucceedBoundaryPath(gen.get("c"));
        FlowPath in3 = FlowGraphUtil.getSucceedBoundaryPath(gen.get("in3"));
        FlowPath path = a.union(b).union(c).union(in3);
        FlowBlock block = path.createBlock(gen.toGraph(), 0, true, true);

        assertThat(block.getElements(),
            is(gen.getAsSet("a", "b", "c", "d", "e", "f", "op1", "op2", "in3", "out3")));
        Set<FlowElementInput> inputs = input(block.getBlockInputs());
        Set<FlowElementOutput> outputs = output(block.getBlockOutputs());
        assertThat(inputs, is(gen.inputs("a", "b", "c")));
        assertThat(outputs, is(gen.outputs("d", "e", "f")));
    }
View Full Code Here

    /**
     * {@link FlowPath#createBlock(FlowGraph, int, boolean, boolean)}
     */
    @Test
    public void createBlock_excludeIn_includeOut() {
        FlowGraphGenerator gen = graph();
        FlowPath a = FlowGraphUtil.getSucceedBoundaryPath(gen.get("a"));
        FlowPath b = FlowGraphUtil.getSucceedBoundaryPath(gen.get("b"));
        FlowPath c = FlowGraphUtil.getSucceedBoundaryPath(gen.get("c"));
        FlowPath in3 = FlowGraphUtil.getSucceedBoundaryPath(gen.get("in3"));
        FlowPath path = a.union(b).union(c).union(in3);
        FlowBlock block = path.createBlock(gen.toGraph(), 0, false, true);

        assertThat(block.getElements(),
            is(gen.getAsSet("d", "e", "f", "op1", "op2", "out3")));
        Set<FlowElementInput> inputs = input(block.getBlockInputs());
        Set<FlowElementOutput> outputs = output(block.getBlockOutputs());
        assertThat(inputs, is(gen.inputs("op1", "op2")));
        assertThat(outputs, is(gen.outputs("d", "e", "f")));
    }
View Full Code Here

    /**
     * {@link FlowPath#createBlock(FlowGraph, int, boolean, boolean)}
     */
    @Test
    public void createBlock_includeIn_excludeOut() {
        FlowGraphGenerator gen = graph();
        FlowPath a = FlowGraphUtil.getSucceedBoundaryPath(gen.get("a"));
        FlowPath b = FlowGraphUtil.getSucceedBoundaryPath(gen.get("b"));
        FlowPath c = FlowGraphUtil.getSucceedBoundaryPath(gen.get("c"));
        FlowPath in3 = FlowGraphUtil.getSucceedBoundaryPath(gen.get("in3"));
        FlowPath path = a.union(b).union(c).union(in3);
        FlowBlock block = path.createBlock(gen.toGraph(), 0, true, false);

        assertThat(block.getElements(),
            is(gen.getAsSet("a", "b", "c", "op1", "op2", "in3")));
        Set<FlowElementInput> inputs = input(block.getBlockInputs());
        Set<FlowElementOutput> outputs = output(block.getBlockOutputs());
        assertThat(inputs, is(gen.inputs("a", "b", "c")));
        assertThat(outputs, is(gen.outputs("op1", "op2")));
    }
View Full Code Here

    /**
     * {@link FlowPath#createBlock(FlowGraph, int, boolean, boolean)}
     */
    @Test
    public void createBlock_excludeIn_excludeOut() {
        FlowGraphGenerator gen = graph();
        FlowPath a = FlowGraphUtil.getSucceedBoundaryPath(gen.get("a"));
        FlowPath b = FlowGraphUtil.getSucceedBoundaryPath(gen.get("b"));
        FlowPath c = FlowGraphUtil.getSucceedBoundaryPath(gen.get("c"));
        FlowPath in3 = FlowGraphUtil.getSucceedBoundaryPath(gen.get("in3"));
        FlowPath path = a.union(b).union(c).union(in3);
        FlowBlock block = path.createBlock(gen.toGraph(), 0, false, false);

        assertThat(block.getElements(), is(gen.getAsSet("op1", "op2")));
        Set<FlowElementInput> inputs = input(block.getBlockInputs());
        Set<FlowElementOutput> outputs = output(block.getBlockOutputs());
        assertThat(inputs, is(gen.inputs("op1", "op2")));
        assertThat(outputs, is(gen.outputs("op1", "op2")));
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.compiler.flow.FlowGraphGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.