@@ -188,13 +188,15 @@ Tensor tensor(int outputIdx) {
188
188
* Get the number of inputs to the op, not including control inputs.
189
189
*/
190
190
public int numInputs () {
191
+ requireHandle (unsafeNativeHandle );
191
192
return TF_OperationNumInputs (getUnsafeNativeHandle ());
192
193
}
193
194
194
195
/**
195
196
* Get the op's inputs, not including control inputs.
196
197
*/
197
198
public List <Operand <?>> inputs () {
199
+ requireHandle (unsafeNativeHandle );
198
200
try (PointerScope scope = new PointerScope ()) {
199
201
int numInputs = numInputs ();
200
202
TF_Output handles = new TF_Output (numInputs );
@@ -219,6 +221,7 @@ public List<Operand<?>> inputs() {
219
221
* @param index the output to look for usages of
220
222
*/
221
223
public int numConsumers (int index ) {
224
+ requireHandle (unsafeNativeHandle );
222
225
try (PointerScope scope = new PointerScope ()) {
223
226
TF_Output output = new TF_Output ().oper (getUnsafeNativeHandle ()).index (index );
224
227
return TF_OperationOutputNumConsumers (output );
@@ -231,6 +234,7 @@ public int numConsumers(int index) {
231
234
* @param index the output to look for usages of
232
235
*/
233
236
public Set <GraphOperation > consumers (int index ) {
237
+ requireHandle (unsafeNativeHandle );
234
238
try (PointerScope scope = new PointerScope ()) {
235
239
TF_Output output = new TF_Output ().oper (getUnsafeNativeHandle ()).index (index );
236
240
int numConsumers = numConsumers (index );
@@ -253,6 +257,7 @@ public Set<GraphOperation> consumers(int index) {
253
257
* Get the number of ops that use any of this op's outputs as an input, not including control dependencies.
254
258
*/
255
259
public int numConsumers () {
260
+ requireHandle (unsafeNativeHandle );
256
261
int all = 0 ;
257
262
for (int i = 0 ; i < numOutputs (); i ++) {
258
263
all += numConsumers (i );
@@ -265,6 +270,7 @@ public int numConsumers() {
265
270
* Get the ops that use any of this op's outputs as an input, not including control dependencies.
266
271
*/
267
272
public Set <GraphOperation > consumers () {
273
+ requireHandle (unsafeNativeHandle );
268
274
Set <GraphOperation > all = new LinkedHashSet <>();
269
275
for (int i = 0 ; i < numOutputs (); i ++) {
270
276
all .addAll (consumers (i ));
@@ -276,6 +282,7 @@ public Set<GraphOperation> consumers() {
276
282
* Get the number of control inputs for this op.
277
283
*/
278
284
public int numControlInputs () {
285
+ requireHandle (unsafeNativeHandle );
279
286
try (PointerScope scope = new PointerScope ()) {
280
287
return TF_OperationNumControlInputs (getUnsafeNativeHandle ());
281
288
}
@@ -285,6 +292,7 @@ public int numControlInputs() {
285
292
* Get the control inputs of this op.
286
293
*/
287
294
public Set <GraphOperation > controlInputs () {
295
+ requireHandle (unsafeNativeHandle );
288
296
try (PointerScope scope = new PointerScope ()) {
289
297
int numInputs = numControlInputs ();
290
298
PointerPointer <TF_Operation > handles = new PointerPointer <>(numInputs );
@@ -305,6 +313,7 @@ public Set<GraphOperation> controlInputs() {
305
313
* Get the number of ops with this op as a control dependency.
306
314
*/
307
315
public int numControlConsumers () {
316
+ requireHandle (unsafeNativeHandle );
308
317
try (PointerScope scope = new PointerScope ()) {
309
318
return TF_OperationNumControlOutputs (getUnsafeNativeHandle ());
310
319
}
@@ -314,6 +323,7 @@ public int numControlConsumers() {
314
323
* Get the ops with this op as a control dependency.
315
324
*/
316
325
public Set <GraphOperation > controlConsumers () {
326
+ requireHandle (unsafeNativeHandle );
317
327
try (PointerScope scope = new PointerScope ()) {
318
328
int numConsumers = numControlConsumers ();
319
329
PointerPointer <TF_Operation > handles = new PointerPointer <>(numConsumers );
0 commit comments