@@ -188,13 +188,15 @@ Tensor tensor(int outputIdx) {
188188 * Get the number of inputs to the op, not including control inputs.
189189 */
190190 public int numInputs () {
191+ requireHandle (unsafeNativeHandle );
191192 return TF_OperationNumInputs (getUnsafeNativeHandle ());
192193 }
193194
194195 /**
195196 * Get the op's inputs, not including control inputs.
196197 */
197198 public List <Operand <?>> inputs () {
199+ requireHandle (unsafeNativeHandle );
198200 try (PointerScope scope = new PointerScope ()) {
199201 int numInputs = numInputs ();
200202 TF_Output handles = new TF_Output (numInputs );
@@ -219,6 +221,7 @@ public List<Operand<?>> inputs() {
219221 * @param index the output to look for usages of
220222 */
221223 public int numConsumers (int index ) {
224+ requireHandle (unsafeNativeHandle );
222225 try (PointerScope scope = new PointerScope ()) {
223226 TF_Output output = new TF_Output ().oper (getUnsafeNativeHandle ()).index (index );
224227 return TF_OperationOutputNumConsumers (output );
@@ -231,6 +234,7 @@ public int numConsumers(int index) {
231234 * @param index the output to look for usages of
232235 */
233236 public Set <GraphOperation > consumers (int index ) {
237+ requireHandle (unsafeNativeHandle );
234238 try (PointerScope scope = new PointerScope ()) {
235239 TF_Output output = new TF_Output ().oper (getUnsafeNativeHandle ()).index (index );
236240 int numConsumers = numConsumers (index );
@@ -253,6 +257,7 @@ public Set<GraphOperation> consumers(int index) {
253257 * Get the number of ops that use any of this op's outputs as an input, not including control dependencies.
254258 */
255259 public int numConsumers () {
260+ requireHandle (unsafeNativeHandle );
256261 int all = 0 ;
257262 for (int i = 0 ; i < numOutputs (); i ++) {
258263 all += numConsumers (i );
@@ -265,6 +270,7 @@ public int numConsumers() {
265270 * Get the ops that use any of this op's outputs as an input, not including control dependencies.
266271 */
267272 public Set <GraphOperation > consumers () {
273+ requireHandle (unsafeNativeHandle );
268274 Set <GraphOperation > all = new LinkedHashSet <>();
269275 for (int i = 0 ; i < numOutputs (); i ++) {
270276 all .addAll (consumers (i ));
@@ -276,6 +282,7 @@ public Set<GraphOperation> consumers() {
276282 * Get the number of control inputs for this op.
277283 */
278284 public int numControlInputs () {
285+ requireHandle (unsafeNativeHandle );
279286 try (PointerScope scope = new PointerScope ()) {
280287 return TF_OperationNumControlInputs (getUnsafeNativeHandle ());
281288 }
@@ -285,6 +292,7 @@ public int numControlInputs() {
285292 * Get the control inputs of this op.
286293 */
287294 public Set <GraphOperation > controlInputs () {
295+ requireHandle (unsafeNativeHandle );
288296 try (PointerScope scope = new PointerScope ()) {
289297 int numInputs = numControlInputs ();
290298 PointerPointer <TF_Operation > handles = new PointerPointer <>(numInputs );
@@ -305,6 +313,7 @@ public Set<GraphOperation> controlInputs() {
305313 * Get the number of ops with this op as a control dependency.
306314 */
307315 public int numControlConsumers () {
316+ requireHandle (unsafeNativeHandle );
308317 try (PointerScope scope = new PointerScope ()) {
309318 return TF_OperationNumControlOutputs (getUnsafeNativeHandle ());
310319 }
@@ -314,6 +323,7 @@ public int numControlConsumers() {
314323 * Get the ops with this op as a control dependency.
315324 */
316325 public Set <GraphOperation > controlConsumers () {
326+ requireHandle (unsafeNativeHandle );
317327 try (PointerScope scope = new PointerScope ()) {
318328 int numConsumers = numControlConsumers ();
319329 PointerPointer <TF_Operation > handles = new PointerPointer <>(numConsumers );
0 commit comments