class_docstr: Updater for kvstore.
docstr: Updates weight given gradient and index.
docstr_tok: ["Updates","weight","given","gradient","and","index","."]
code: def __call__(self, index, grad, weight):
      """Updates weight given gradient and index."""
      allow_np = (
          self.optimizer.allow_np_array
          if hasattr(self.optimizer, "allow_np_array")
          else is_np_array()
      )
      if not isinstance(index, (list, tuple)):
          indices = [index]
          grads = [_as_classic(grad, allow_np)]
          weights = [_as_classic(weight, allow_np)]
      else:
          indices = index
          grads = _as_classic(grad, allow_np)
          weights = _as_classic(weight, allow_np)
      if weights:
          self.optimizer._set_current_device(
              weights[0].context.device_id
          )
      for i, idx in enumerate(indices):
          # convert ctypes.char_p.value back to python str if needed
          if isinstance(idx, bytes):
              indices[i] = py_str(idx)
              idx = indices[i]
          if idx not in self.states:
              with profiler_scope("updater:optimizer_state"):
                  self.states[
                      idx
                  ] = self.optimizer.create_state_multi_precision(
                      idx, weights[i]
                  )
              self.states_synced[idx] = True
          elif not self.states_synced[idx]:
              self.states[idx] = self.sync_state_context(
                  self.states[idx], weights[i].context
              )
              self.states_synced[idx] = True
      if self.aggregate_updates:
          # segregate values based on type
          if self.optimizer.aggregate_num is not numpy.inf:
              type_map = {}
              for i, w, g in zip(indices, weights, grads):
                  if w.dtype in type_map:
                      type_map[w.dtype].append((i, w, g))
                  else:
                      type_map[w.dtype] = [(i, w, g)]
              for idx in type_map:
                  current_index = 0
                  indices, weights, grads = zip(*type_map[idx])
                  while current_index < len(indices):
                      states = []
                      step = min(
                          self.optimizer.aggregate_num,
                          len(indices) - current_index,
                      )
                      for j in range(step):
                          states.append(
                              self.states[indices[current_index + j]]
                          )
                      self.optimizer.update_multi_precision(
                          indices[
                              current_index : current_index
                              + self.optimizer.aggregate_num
                          ],
                          weights[
                              current_index : current_index
                              + self.optimizer.aggregate_num
                          ],
                          grads[
                              current_index : current_index
                              + self.optimizer.aggregate_num
                          ],
                          states,
                      )
                      current_index += self.optimizer.aggregate_num
          else:
              states = [self.states[i] for i in indices]
              self.optimizer.update_multi_precision(
                  indices, weights, grads, states
              )
      else:
          for i, w, g in zip(indices, weights, grads):
              self.optimizer.update_multi_precision(
                  [i], [w], [g], [self.states[i]]
              )
  
file_path: mxnet/python/mxnet/optimizer/updater.py
imports: from __future__ import absolute_import
  import pickle
  import numpy
  from ..base import py_str
  from ..ndarray import NDArray
  from ..profiler import scope
  from ..util import is_np_array
  from .utils import _as_classic
label_desc: Use image node_id 2 for calling the Updater obj's underlying member method code with example usage: obj.__call__(index, grad, weight) without return types