class_docstr: Testing rig.
class_docstr_tok: ["Testing","rig","."]
docstr: Tests the MST max score gradient.
docstr_tok: ["Tests","the","MST","max","score","gradient","."]
code: def testMaximumSpanningTreeGradient(self):
      """Tests the MST max score gradient."""
      with self.test_session() as session:
          num_nodes = constant_op.constant([4, 3], dtypes.int32)
          scores = constant_op.constant(
              [
                  [
                      [0, 0, 0, 0],
                      [1, 0, 0, 0],
                      [1, 2, 0, 0],
                      [1, 2, 3, 4],
                  ],
                  [
                      [4, 3, 2, 9],
                      [0, 0, 2, 9],
                      [0, 0, 0, 9],
                      [9, 9, 9, 9],
                  ],
              ],
              dtypes.int32,
          )  # pyformat: disable
  
          mst_ops.max_spanning_tree(
              num_nodes, scores, forest=False, name="MST"
          )
          mst_op = session.graph.get_operation_by_name("MST")
  
          d_loss_d_max_scores = constant_op.constant(
              [3, 7], dtypes.float32
          )
          (
              d_loss_d_num_nodes,
              d_loss_d_scores,
          ) = mst_ops.max_spanning_tree_gradient(
              mst_op, d_loss_d_max_scores
          )
  
          # The num_nodes input is non-differentiable.
          self.assertIs(d_loss_d_num_nodes, None)
          self.assertAllEqual(
              d_loss_d_scores.eval(),
              [
                  [
                      [0, 0, 0, 3],
                      [3, 0, 0, 0],
                      [0, 3, 0, 0],
                      [0, 0, 0, 3],
                  ],
                  [
                      [7, 0, 0, 0],
                      [0, 0, 7, 0],
                      [7, 0, 0, 0],
                      [0, 0, 0, 0],
                  ],
              ],
          )
  
file_path: text/tensorflow_text/python/ops/mst_ops_test.py
imports: import numpy
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import test_util
  from tensorflow.python.platform import test
  from tensorflow_text.python.ops import mst_ops
label_desc: Use image node_id 2 for calling the MstOpsTest obj's underlying member method code with example usage: obj.testMaximumSpanningTreeGradient() without return types