code: def test_sparse_aggregator():
      """aggregate sparse ndarray on muliple devices"""
  
      def check_sparse_aggregator(sparse_pull):
          stype = "row_sparse"
          kv = init_kv_with_str(stype)
  
          # devices
          num_devs = 4
          devs = [mx.Context("cpu", i) for i in range(num_devs)]
  
          # single
          vals = [
              rand_ndarray(shape, stype).copyto(devs[i])
              for i in range(num_devs)
          ]
          expected_sum = np.zeros(shape)
          for v in vals:
              expected_sum += v.asnumpy()
  
          # prepare row_ids
          kv.push("a", vals)
          if sparse_pull:
              all_rows = mx.nd.array(np.arange(shape[0]))
              kv.row_sparse_pull(
                  "a", out=vals, row_ids=[all_rows] * len(vals)
              )
          else:
              kv.pull("a", out=vals, ignore_sparse=False)
          result_sum = np.zeros(shape)
          for v in vals:
              result_sum += v.asnumpy()
          assert_almost_equal(result_sum, expected_sum * num_devs)
  
          # list
          vals = [
              [
                  rand_ndarray(shape, stype).copyto(devs[i])
                  for i in range(num_devs)
              ]
          ] * len(keys)
          expected_sum = np.zeros(shape)
          for v in vals[0]:
              expected_sum += v.asnumpy()
  
          kv.push(str_keys, vals)
          if sparse_pull:
              kv.row_sparse_pull(
                  str_keys,
                  out=vals,
                  row_ids=[[all_rows] * num_devs] * len(vals),
              )
          else:
              kv.pull(str_keys, out=vals, ignore_sparse=False)
          for vv in vals:
              result_sum = np.zeros(shape)
              for v in vv:
                  result_sum += v.asnumpy()
              assert_almost_equal(result_sum, expected_sum * num_devs)
  
      check_sparse_aggregator(False)
      check_sparse_aggregator(True)
  
imports: import mxnet
  import numpy
  import unittest
  from mxnet.test_utils import rand_ndarray, assert_almost_equal
  from common import assertRaises
  from mxnet.base import py_str, MXNetError
  import pytest
label_desc: Use image node_id 10 for calling a global function with example usage: test_sparse_aggregator() without return types