def METHOD_NAME(self, tol):
    """Tests that adagrad optimizer takes one and two steps correctly
    for multivariate functions."""
    stepsize = 0.1
    adag_opt = AdagradOptimizer(stepsize)
    multivariate_funcs = [
        lambda x: np.sin(x[0]) + np.cos(x[1]),
        lambda x: np.exp(x[0] / 3) * np.tanh(x[1]),
        lambda x: np.sum([x_**2 for x_ in x]),
    ]
    grad_multi_funcs = [
        lambda x: (np.array([np.cos(x[0]), -np.sin(x[1])]),),
        lambda x: (
            np.array(
                [
                    np.exp(x[0] / 3) / 3 * np.tanh(x[1]),
                    np.exp(x[0] / 3) * (1 - np.tanh(x[1]) ** 2),
                ]
            ),
        ),
        lambda x: (np.array([2 * x_ for x_ in x]),),
    ]
    x_vals = np.linspace(-10, 10, 16, endpoint=False)
    for gradf, f in zip(grad_multi_funcs, multivariate_funcs):
        for jdx in range(len(x_vals[:-1])):
            adag_opt.reset()
            x_vec = x_vals[jdx : jdx + 2]
            x_onestep = adag_opt.step(f, x_vec)
            past_grads = gradf(x_vec)[0] * gradf(x_vec)[0]
            adapt_stepsize = stepsize / np.sqrt(past_grads + 1e-8)
            x_onestep_target = x_vec - gradf(x_vec)[0] * adapt_stepsize
            assert np.allclose(x_onestep, x_onestep_target, atol=tol)
            x_twosteps = adag_opt.step(f, x_onestep)
            past_grads = (
                gradf(x_vec)[0] * gradf(x_vec)[0] + gradf(x_onestep)[0] * gradf(x_onestep)[0]
            )
            adapt_stepsize = stepsize / np.sqrt(past_grads + 1e-8)
            x_twosteps_target = x_onestep - gradf(x_onestep)[0] * adapt_stepsize
            assert np.allclose(x_twosteps, x_twosteps_target, atol=tol)