code: def test_huffman_tree_hierarchy(self):
      workspace.GlobalInit(["caffe2"])
      labelSet = list(range(0, 6))
      counts = [1, 2, 3, 4, 5, 6]
      labels = sum([[l] * c for (l, c) in zip(labelSet, counts)], [])
      Y = np.array(labels).astype(np.int64)
      workspace.FeedBlob("labels", Y)
      arg = caffe2_pb2.Argument()
      arg.name = "num_classes"
      arg.i = 6
      op = core.CreateOperator(
          "HuffmanTreeHierarchy",
          ["labels"],
          ["huffman_tree"],
          "HuffmanTreeHierarchy",
          arg=[arg],
      )
      workspace.RunOperatorOnce(op)
      huffmanTreeOutput = workspace.FetchBlob("huffman_tree")
      treeOutput = hsm_pb2.TreeProto()
      treeOutput.ParseFromString(huffmanTreeOutput[0])
      treePathOutput = hsmu.create_hierarchy(treeOutput)
  
      label_to_path = {}
      for path in treePathOutput.paths:
          label_to_path[path.word_id] = path
  
      def checkPath(label, indices, code):
          path = label_to_path[label]
          self.assertEqual(len(path.path_nodes), len(code))
          self.assertEqual(len(path.path_nodes), len(code))
          for path_node, index, target in zip(
              path.path_nodes, indices, code
          ):
              self.assertEqual(path_node.index, index)
              self.assertEqual(path_node.target, target)
  
      checkPath(0, [0, 4, 6, 8], [1, 0, 0, 0])
      checkPath(1, [0, 4, 6, 8], [1, 0, 0, 1])
      checkPath(2, [0, 4, 6], [1, 0, 1])
      checkPath(3, [0, 2], [0, 0])
      checkPath(4, [0, 2], [0, 1])
      checkPath(5, [0, 4], [1, 1])
  
file_path: pytorch/caffe2/python/operator_test/hsm_test.py
imports: from hypothesis import given, settings
  import numpy
  import unittest
  from caffe2.proto import caffe2_pb2, hsm_pb2
  from caffe2.python import workspace, core, gradient_checker
  import caffe2.python.hypothesis_test_util
  import caffe2.python.hsm_util
label_desc: Use image node_id 5 for calling the TestHsm obj's underlying member method code with example usage: obj.test_huffman_tree_hierarchy() without return types