code: def test_mst(self):
      # First, test some random cases as sanity checks.
      # No label case
      energy = numpy.random.rand(5, 5)
      heads, types = decode_mst(energy, 5, has_labels=False)
      assert not _find_cycle(heads, 5, [True] * 5)[0]
  
      # Labeled case
      energy = numpy.random.rand(3, 5, 5)
      heads, types = decode_mst(energy, 5)
  
      assert not _find_cycle(heads, 5, [True] * 5)[0]
      label_id_matrix = energy.argmax(axis=0)
  
      # Check that the labels correspond to the
      # argmax of the labels for the arcs.
      for child, parent in enumerate(heads):
          # The first index corresponds to the symbolic
          # head token, which won't necessarily have an
          # argmax type.
          if child == 0:
              continue
          assert types[child] == label_id_matrix[parent, child]
  
      # Check wrong dimensions throw errors
      with pytest.raises(ConfigurationError):
          energy = numpy.random.rand(5, 5)
          decode_mst(energy, 5, has_labels=True)
  
      with pytest.raises(ConfigurationError):
          energy = numpy.random.rand(3, 5, 5)
          decode_mst(energy, 5, has_labels=False)
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/nn/decoding/chu_liu_edmonds_test.py
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import numpy
  import pytest
  import torch
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.common.checks import ConfigurationError
  from allennlp.nn.decoding.chu_liu_edmonds import _find_cycle, decode_mst
label_desc: Use image node_id 2 for calling the ChuLiuEdmondsTest obj's underlying member method code with example usage: obj.test_mst() without return types