Skip to content

Commit 5ca958d

Browse files
authored
Add graph walking functions to Graph and GraphOperation (#232)
1 parent 0f0c638 commit 5ca958d

File tree

7 files changed

+663
-181
lines changed

7 files changed

+663
-181
lines changed

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/AbstractOperation.java

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public Output<?>[] outputList(int idx, int length) {
3939

4040
@Override
4141
public <T extends TType> Output<T> output(int idx) {
42+
if (getUnsafeNativeHandle(idx) != null && !getUnsafeNativeHandle(idx).isNull()) {
43+
int numOutputs = this.numOutputs();
44+
if (idx >= numOutputs) {
45+
throw new IndexOutOfBoundsException(
46+
"Can't get output with index " + idx + ", this op only has " + numOutputs + " outputs.");
47+
}
48+
49+
if (idx < 0) {
50+
throw new IndexOutOfBoundsException("Can't get output with index < 0.");
51+
}
52+
}
4253
return new Output<>(this, idx);
4354
}
4455

0 commit comments

Comments
 (0)