class_docstr: Tests for bluefog/torch/mpi_ops.py
class_docstr_tok: ["Tests","for","bluefog\/torch\/mpi_ops.py"]
docstr: Test neighbor_allgather gives correct order of collected value by default
code: def test_neighbor_allgather_order(self):
      """Test neighbor_allgather gives correct order of collected value by default"""
      size = bf.size()
      rank = bf.rank()
      if size <= 1:
          fname = inspect.currentframe().f_code.co_name
          warnings.warn("Skip {} due to size 1".format(fname))
          return
      dtypes = [torch.FloatTensor]
      if TEST_ON_GPU:
          dtypes += [torch.cuda.FloatTensor]
      for dtype in dtypes:
          tensor = torch.FloatTensor([rank])
          tensor = self.cast_and_place(tensor, dtype)
          gathered = bf.neighbor_allgather(tensor)
          # The order of gathered value is always the same as the in_neighbor_ranks.
          np.testing.assert_allclose(
              gathered.cpu().numpy(), bf.in_neighbor_ranks()
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import inspect
  import itertools
  import unittest
  import warnings
  import numpy
  import pytest
  import torch
  import networkx
  import bluefog.torch
  from bluefog.common import topology_util
  from common import is_openmpi_built
label_desc: Use image node_id 36 for calling the OpsTests obj's underlying member method code with example usage: obj.test_neighbor_allgather_order() without return types