Builds a while loop. @param inputs the loop inputs @param cgBuilder WhileSubgraphBuilder to build the conditional subgraph @param bgBuilder WhileSubgraphBuilder to build the body subgraph @param name name for the loop @return list of loop outputs, of the same length as inputs
(
Output<?>[] inputs,
WhileSubgraphBuilder cgBuilder,
WhileSubgraphBuilder bgBuilder,
String name)
| 317 | * @return list of loop outputs, of the same length as {@code inputs} |
| 318 | */ |
| 319 | public Output<?>[] whileLoop( |
| 320 | Output<?>[] inputs, |
| 321 | WhileSubgraphBuilder cgBuilder, |
| 322 | WhileSubgraphBuilder bgBuilder, |
| 323 | String name) { |
| 324 | int ninputs = inputs.length; |
| 325 | long[] inputHandles = new long[ninputs]; |
| 326 | int[] inputIndices = new int[ninputs]; |
| 327 | Output<?>[] outputs = new Output<?>[ninputs]; |
| 328 | |
| 329 | synchronized (nativeHandleLock) { |
| 330 | try (Reference ref = ref()) { |
| 331 | |
| 332 | for (int i = 0; i < ninputs; i++) { |
| 333 | inputHandles[i] = inputs[i].getUnsafeNativeHandle(); |
| 334 | inputIndices[i] = inputs[i].index(); |
| 335 | } |
| 336 | |
| 337 | long[] outputHandlesAndIndices = |
| 338 | whileLoop(nativeHandle, inputHandles, inputIndices, name, cgBuilder, bgBuilder); |
| 339 | |
| 340 | for (int i = 0, j = ninputs; i < ninputs; ++i, ++j) { |
| 341 | Operation op = new GraphOperation(this, outputHandlesAndIndices[i]); |
| 342 | outputs[i] = op.output((int) outputHandlesAndIndices[j]); |
| 343 | } |
| 344 | } |
| 345 | return outputs; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | private final Object nativeHandleLock = new Object(); |
| 350 | private long nativeHandle; |