def doTestBasic(self, use_callable_params=False):
    for (i, dtype) in enumerate([dtypes.half, dtypes.float32, dtypes.float64]):
        with self.session(graph=ops.Graph()):
            (m0, v0, m1, v1) = (0.0, 0.0, 0.0, 0.0)
            var0_np = np.array([1.0, 2.0], dtype=dtype.as_numpy_dtype)
            grads0_np = np.array([0.1, 0.1], dtype=dtype.as_numpy_dtype)
            var1_np = np.array([3.0, 4.0], dtype=dtype.as_numpy_dtype)
            grads1_np = np.array([0.01, 0.01], dtype=dtype.as_numpy_dtype)
            var0 = resource_variable_ops.ResourceVariable(var0_np, name=('var0_%d' % i))
            var1 = resource_variable_ops.ResourceVariable(var1_np, name=('var1_%d' % i))
            grads0 = constant_op.constant(grads0_np)
            grads1 = constant_op.constant(grads1_np)
            learning_rate = (lambda : 0.001)
            beta1 = (lambda : 0.9)
            beta2 = (lambda : 0.999)
            epsilon = (lambda : 1e-08)
            if (not use_callable_params):
                learning_rate = learning_rate()
                beta1 = beta1()
                beta2 = beta2()
                epsilon = epsilon()
            opt = adam.Adam(learning_rate=learning_rate)
            if (not context.executing_eagerly()):
                update = opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
            self.evaluate(variables.global_variables_initializer())
            for t in range(3):
                (beta_1_power, beta_2_power) = get_beta_accumulators(opt, dtype)
                self.assertAllCloseAccordingToType((0.9 ** (t + 1)), self.evaluate(beta_1_power))
                self.assertAllCloseAccordingToType((0.999 ** (t + 1)), self.evaluate(beta_2_power))
                if (not context.executing_eagerly()):
                    self.evaluate(update)
                else:
                    opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
                (var0_np, m0, v0) = adam_update_numpy(var0_np, grads0_np, t, m0, v0)
                (var1_np, m1, v1) = adam_update_numpy(var1_np, grads1_np, t, m1, v1)
                self.assertAllCloseAccordingToType(var0_np, self.evaluate(var0))
                self.assertAllCloseAccordingToType(var1_np, self.evaluate(var1))
def doTestBasic(self, use_callable_params=False):
    for (i, dtype) in enumerate([dtypes.half, dtypes.float32, dtypes.float64]):
        with self.session(graph=ops.Graph()):
            (m0, v0, m1, v1) = (0.0, 0.0, 0.0, 0.0)
            var0_np = np.array([1.0, 2.0], dtype=dtype.as_numpy_dtype)
            grads0_np = np.array([0.1, 0.1], dtype=dtype.as_numpy_dtype)
            var1_np = np.array([3.0, 4.0], dtype=dtype.as_numpy_dtype)
            grads1_np = np.array([0.01, 0.01], dtype=dtype.as_numpy_dtype)
            var0 = resource_variable_ops.ResourceVariable(var0_np, name=('var0_%d' % i))
            var1 = resource_variable_ops.ResourceVariable(var1_np, name=('var1_%d' % i))
            grads0 = constant_op.constant(grads0_np)
            grads1 = constant_op.constant(grads1_np)
            learning_rate = (lambda : 0.001)
            beta1 = (lambda : 0.9)
            beta2 = (lambda : 0.999)
            epsilon = (lambda : 1e-08)
            if (not use_callable_params):
                learning_rate = learning_rate()
                beta1 = beta1()
                beta2 = beta2()
                epsilon = epsilon()
            opt = adam.Adam(learning_rate=learning_rate)
            if (not context.executing_eagerly()):
                update = opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
            self.evaluate(variables.global_variables_initializer())
            for t in range(3):
                (beta_1_power, beta_2_power) = get_beta_accumulators(opt, dtype)
                self.assertAllCloseAccordingToType((0.9 ** (t + 1)), self.evaluate(beta_1_power))
                self.assertAllCloseAccordingToType((0.999 ** (t + 1)), self.evaluate(beta_2_power))
                if (not context.executing_eagerly()):
                    self.evaluate(update)
                else:
                    opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
                (var0_np, m0, v0) = adam_update_numpy(var0_np, grads0_np, t, m0, v0)
                (var1_np, m1, v1) = adam_update_numpy(var1_np, grads1_np, t, m1, v1)
                self.assertAllCloseAccordingToType(var0_np, self.evaluate(var0))
                self.assertAllCloseAccordingToType(var1_np, self.evaluate(var1))