Skip to content

NullPointerException when calling matrixDiagV3 #406

Closed

Description

@frankfliu

The following code works fine with 0.3.1, but now I get NPE in 0.4.0:

        EagerSession eagerSession = EagerSession.options().async(true).build();
        Ops tf = Ops.create(eagerSession);
        Operand<TFloat32> diagonal = tf.fill(tf.constant(new long[]{2}), tf.constant(1f));
        Operand<TFloat32> value = tf.fill(tf.constant(new long[]{1}), tf.constant(0f));

        Operand<TFloat32> output =
                tf.linalg.matrixDiagV3(
                        diagonal, tf.constant(0), tf.constant(2), tf.constant(2), value);
        Tensor tensor = output.asTensor(); // exception here

I got exception on both macOS and Linux.

java.lang.NullPointerException
	at org.tensorflow.EagerOperation.resolveTensorHandle(EagerOperation.java:193)
	at org.tensorflow.EagerOperation.resolveTensor(EagerOperation.java:166)
	at org.tensorflow.EagerOperation.tensor(EagerOperation.java:152)
	at org.tensorflow.Output.asTensor(Output.java:97)
	at org.tensorflow.Operand.asTensor(Operand.java:65)

Activity

  1. changed the title [-]NullPointerException when calling [/-] [+]NullPointerException when calling matrixDiagV3[/+] on Jan 12, 2022
  2. karllessard commented on Jan 13, 2022

    @karllessard
    Collaborator

    Hi Frank,

    The way I understand it is that the value parameter (the last one in you matrixDiagV3 call) must be a scalar and not a vector. This snippet works for me:

        TFloat32 tensor = tf.linalg.matrixDiagV3(
            diagonal,
            tf.constant(0),
            tf.constant(2),
            tf.constant(2),
            tf.constant(0.0f)
        ).asTensor();
    

    Does that work for you too?

    This is a pure guess but maybe they've changed something in the MatrixDiagV3 kernel of TensorFlow 2.7 that does not allow you anymore to pass a vector, and if it was allowed before I think that was a bug since according to the doc, that value should be "a number":

    paddingValue – The number to fill the area outside the specified diagonal band with. Default is 0.

  3. frankfliu commented on Jan 13, 2022

    @frankfliu
    ContributorAuthor

    @karllessard

    You are absolutely correct, padding should be a scalar. I think earlier version didn't enforce that.

    But the NPE is bug in the code. I will create a PR to address that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions