Loop and rename
@@ -69,7 +69,19 @@ public class DimensionRenamer {
private Map<String, Integer> solve(int maxIterations) {
Map<String, Integer> solution = solveWithOrWithoutSoftConstraints(maxIterations);
- if ( solution == null) {
+ int renamesTried = 0;
+ while (solution == null && renamesTried++ < dimensions.size()) {
+ boolean inserted = insertRenameOperation();
+ if ( ! inserted ) break;
+ solution = solveWithOrWithoutSoftConstraints(maxIterations);
+ }
+ if ( solution == null)
+ throw new IllegalArgumentException("Could not find a dimension naming solution " +
+ "given constraints\n" + constraintsToString(constraints));
+ return solution;
+ }
+
+ private boolean insertRenameOperation() {
IntermediateOperation operation = graph.operations().get("dense_out/MatMul");
if (operation instanceof MatMul) {
IntermediateOperation arg0 = operation.inputs().get(0);
@@ -84,15 +96,9 @@ public class DimensionRenamer {
}
addDimension("renamed_0");
newOperation.addDimensionNameConstraints(this);
-
- solution = solveWithOrWithoutSoftConstraints(maxIterations);
- }
- }
- if ( solution == null) {
- throw new IllegalArgumentException("Could not find a dimension naming solution " +
- "given constraints\n" + constraintsToString(constraints));
+ return true;
}
- return solution;
+ return false;
}
private Map<String, Integer> solveWithOrWithoutSoftConstraints(int maxIterations) {
