public synchronized Set completeSubgraph()

in tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Graph.java [244:297]


  public synchronized Set<GraphOperation> completeSubgraph(
      Set<Operand<?>> inputs, Set<Operand<?>> outputs) {

    if (inputs == null) {
      throw new IllegalArgumentException("Inputs can't be null.");
    }

    if (outputs == null) {
      throw new IllegalArgumentException("Outputs can't be null.");
    }

    Queue<GraphOperation> currents = new ArrayDeque<>(outputs.size());
    Set<GraphOperation> seen = new LinkedHashSet<>(inputs.size());
    Set<GraphOperation> inputOps = new LinkedHashSet<>(inputs.size());

    for (Operand<?> input : inputs) {
      if (input.op().numOutputs() > 1) {
        throw new IllegalStateException(
            "Only ops with one output are supported as subgraph inputs");
      }
      GraphOperation op = graphOp(input);
      inputOps.add(op);
      seen.add(op);
    }

    for (Operand<?> operand : outputs) {
      GraphOperation op = graphOp(operand);
      currents.add(op);
    }

    while (!currents.isEmpty()) {
      GraphOperation op = currents.poll();

      // skip if already present
      if (!seen.add(op)) {
        continue;
      }

      for (GraphOperation control : op.controlInputs()) {
        if (!inputOps.contains(control)) {
          currents.add(control);
        }
      }

      for (Operand<?> input : op.inputs()) {
        GraphOperation inputOp = graphOp(input);
        if (!inputOps.contains(inputOp)) {
          currents.add(inputOp);
        }
      }
    }

    return seen;
  }