return new PrimitiveSubgraph(GraphType.Cycle, new int[]{pivot}); return new PrimitiveSubgraph(GraphType.Cycle, deque2array(positions)); return processGraph(pivot); return new PrimitiveSubgraph(GraphType.Cycle, deque2array(positions)); return new PrimitiveSubgraph(GraphType.Line, deque2array(positions));
private PrimitiveSubgraph processGraph(int pivot) { IntArrayList positions = new IntArrayList(); positions.add(pivot); IntArrayList stack = new IntArrayList(); stack.push(pivot); used.set(pivot); long[] contractions; Indices indices; int currentPivot, index, toTensorIndex; while (!stack.isEmpty()) { currentPivot = stack.pop(); indices = pc.get(currentPivot).getIndices(); contractions = fcs.contractions[currentPivot]; for (int i = contractions.length - 1; i >= 0; --i) { index = indices.get(i); if (getType(index) != type.getType()) continue; toTensorIndex = getToTensorIndex(contractions[i]); if (toTensorIndex == -1 || used.get(toTensorIndex)) continue; used.set(toTensorIndex); positions.add(toTensorIndex); stack.push(toTensorIndex); } } return new PrimitiveSubgraph(GraphType.Graph, positions.toArray()); }