Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix formatting errors from mvn spotless:check
  • Loading branch information
ramon-garcia committed Jan 21, 2023
commit b07c9ab0e73d4f6cf419776ec7422eeec2513906
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ Pointer getUnsafeNativeHandle() {
return operation.getUnsafeNativeHandle(index);
}

/** Returns whether the underlying operation has no valid handle. Makes the opposite check as GraphOperation.requireHandle **/
/**
* Returns whether the underlying operation has no valid handle. Makes the opposite check as
* GraphOperation.requireHandle *
*/
public boolean isClosed() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this behave correctly on an EagerSession? Also it needs some javadoc and I think it'll fail the spotless check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the formatting problem.

I tried the following small example with EagerSession, and it appears to reply correctly false:

import org.tensorflow.EagerSession;
import org.tensorflow.op.Ops;
import org.tensorflow.framework.initializers.Zeros;
import org.tensorflow.types.TFloat32;

public class App {
    public static void main(String[] args) {
        try (EagerSession s = EagerSession.create()) {
            Ops tf = Ops.create(s);
            Zeros<TFloat32> zeroInit = new Zeros<>();
            // y = a*x + b
            var x = tf.constant(new float[] {1.0f, 3.0f, 4.0f});
            var y = tf.constant(new float[] {2.5f, 6.5f, 8.5f});
            var b = tf.constant(1.0f);
            var a = tf.constant(1.8f);
            var ypred = tf.math.add(tf.math.mul(a, x), tf.stopGradient(b));
            var loss_gen = new org.tensorflow.framework.losses.MeanSquaredError();
            var los = loss_gen.call(tf, ypred, y);
            System.out.println("IsClosed " + los.asOutput().isClosed());
        }
    }
}

Running it, the output is:
2023-01-06 16:32:31.701434: I external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
IsClosed false

So it appears to work correctly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Can you add the javadoc to the method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have just added the javadoc.

Pointer handle = operation.getUnsafeNativeHandle(index);
return handle == null || handle.isNull();
Expand Down