class_docstr: Tests for bluefog/torch/mpi_ops.py on one-sided communication.
code: def test_win_update_with_given_weights(self):
      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, torch.DoubleTensor]
      if TEST_ON_GPU:
          dtypes += [torch.cuda.FloatTensor, torch.cuda.DoubleTensor]
  
      dims = [1, 2, 3]
      for dtype, dim in itertools.product(dtypes, dims):
          tensor = (
              torch.FloatTensor(*([DIM_SIZE] * dim)).fill_(1).mul_(rank)
          )
          tensor = self.cast_and_place(tensor, dtype)
          window_name = "win_create_{}_{}".format(dim, dtype)
          is_created = bf.win_create(tensor, window_name)
          assert (
              is_created
          ), "bf.win_create do not create window object successfully."
  
          # Test simple average rule.
          weight = 1.0 / (len(bf.in_neighbor_ranks()) + 1)
          sync_result = bf.win_update(
              window_name,
              self_weight=weight,
              neighbor_weights={
                  x: weight for x in bf.in_neighbor_ranks()
              },
          )
          assert (
              list(sync_result.shape) == [DIM_SIZE] * dim
          ), "bf.win_update (weighted) produces wrong shape tensor."
          assert (sync_result.data - rank).abs().max() < EPSILON, (
              "bf.win_update (weighted) produces wrong tensor value "
              + "[{0}-{1}]!={2} at rank {2}.".format(
                  sync_result.min(), sync_result.max(), rank
              )
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import inspect
  import itertools
  import time
  import warnings
  import unittest
  from bluefog.common import topology_util
  import bluefog.torch
  import torch
  import numpy
label_desc: Use image node_id 8 for calling the WinOpsTests obj's underlying member method code with example usage: obj.test_win_update_with_given_weights() without return types