'Update the parameters.
Parameters
index : int
An unique integer key used to index the parameters
weight : NDArray
weight ndarray
grad : NDArray
grad ndarray
state : NDArray or other objects returned by init_state
The auxiliary state used in optimization.'

def update(self, index, weight, grad, state):

    lr = self._get_lr(index)
    wd = self._get_wd(index)
    self._update_count(index)
    use_multi_precision = (isinstance(state, list) or isinstance(state, tuple))
    if (not use_multi_precision):
        if (self.momentum == 0.0):
            if (self.clip_gradient is not None):
                weight[:] = (((1 - (lr * wd)) * weight) - (lr * mx.nd.clip((grad * self.rescale_grad), (- self.clip_gradient), self.clip_gradient)))
            else:
                weight[:] = (((1 - (lr * wd)) * weight) - ((lr * self.rescale_grad) * grad))
        else:
            mom = state
            if (self.clip_gradient is not None):
                mom[:] = (((self.momentum * mom) - ((lr * wd) * weight)) - (lr * mx.nd.clip((grad * self.rescale_grad), (- self.clip_gradient), self.clip_gradient)))
                weight += mom
            else:
                mom[:] = (((self.momentum * mom) - ((lr * wd) * weight)) - ((lr * self.rescale_grad) * grad))
                weight += mom
    else:
        grad32 = array(grad, ctx=grad.context, dtype=np.float32)
        mom = state[0]
        weight32 = state[1]
        if (self.momentum == 0.0):
            if (self.clip_gradient is not None):
                weight32[:] = (((1 - (lr * wd)) * weight32) - (lr * mx.nd.clip((grad32 * self.rescale_grad), (- self.clip_gradient), self.clip_gradient)))
            else:
                weight32[:] = (((1 - (lr * wd)) * weight32) - ((lr * self.rescale_grad) * grad32))
        elif (self.clip_gradient is not None):
            mom[:] = (((self.momentum * mom) - ((lr * wd) * weight32)) - (lr * mx.nd.clip((grad32 * self.rescale_grad), (- self.clip_gradient), self.clip_gradient)))
            weight32 += mom
        else:
            mom[:] = (((self.momentum * mom) - ((lr * wd) * weight32)) - ((lr * self.rescale_grad) * grad32))
            weight32 += mom
        tmp = weight32.astype(weight.dtype)
        tmp.copyto(weight)
