@test_util.run_deprecated_v1
def testSparse(self):
    for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
        with self.cached_session():
            (m0, v0, m1, v1) = (0.0, 0.0, 0.0, 0.0)
            var0_np = np.array([1.0, 1.0, 2.0], dtype=dtype.as_numpy_dtype)
            grads0_np = np.array([0.1, 0.0, 0.1], dtype=dtype.as_numpy_dtype)
            var1_np = np.array([3.0, 3.0, 4.0], dtype=dtype.as_numpy_dtype)
            grads1_np = np.array([0.01, 0.0, 0.01], dtype=dtype.as_numpy_dtype)
            var0 = resource_variable_ops.ResourceVariable(var0_np)
            var1 = resource_variable_ops.ResourceVariable(var1_np)
            grads0_np_indices = np.array([0, 2], dtype=np.int32)
            grads0 = ops.IndexedSlices(constant_op.constant(grads0_np[grads0_np_indices]), constant_op.constant(grads0_np_indices), constant_op.constant([3]))
            grads1_np_indices = np.array([0, 2], dtype=np.int32)
            grads1 = ops.IndexedSlices(constant_op.constant(grads1_np[grads1_np_indices]), constant_op.constant(grads1_np_indices), constant_op.constant([3]))
            opt = adam.Adam()
            update = opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
            variables.global_variables_initializer().run()
            self.assertAllClose([1.0, 1.0, 2.0], self.evaluate(var0))
            self.assertAllClose([3.0, 3.0, 4.0], self.evaluate(var1))
            (beta_1_power, beta_2_power) = get_beta_accumulators(opt, dtype)
            for t in range(3):
                self.assertAllCloseAccordingToType((0.9 ** (t + 1)), self.evaluate(beta_1_power))
                self.assertAllCloseAccordingToType((0.999 ** (t + 1)), self.evaluate(beta_2_power))
                update.run()
                (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))
@test_util.run_deprecated_v1
def testSparse(self):
    for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
        with self.cached_session():
            (m0, v0, m1, v1) = (0.0, 0.0, 0.0, 0.0)
            var0_np = np.array([1.0, 1.0, 2.0], dtype=dtype.as_numpy_dtype)
            grads0_np = np.array([0.1, 0.0, 0.1], dtype=dtype.as_numpy_dtype)
            var1_np = np.array([3.0, 3.0, 4.0], dtype=dtype.as_numpy_dtype)
            grads1_np = np.array([0.01, 0.0, 0.01], dtype=dtype.as_numpy_dtype)
            var0 = resource_variable_ops.ResourceVariable(var0_np)
            var1 = resource_variable_ops.ResourceVariable(var1_np)
            grads0_np_indices = np.array([0, 2], dtype=np.int32)
            grads0 = ops.IndexedSlices(constant_op.constant(grads0_np[grads0_np_indices]), constant_op.constant(grads0_np_indices), constant_op.constant([3]))
            grads1_np_indices = np.array([0, 2], dtype=np.int32)
            grads1 = ops.IndexedSlices(constant_op.constant(grads1_np[grads1_np_indices]), constant_op.constant(grads1_np_indices), constant_op.constant([3]))
            opt = adam.Adam()
            update = opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
            variables.global_variables_initializer().run()
            self.assertAllClose([1.0, 1.0, 2.0], self.evaluate(var0))
            self.assertAllClose([3.0, 3.0, 4.0], self.evaluate(var1))
            (beta_1_power, beta_2_power) = get_beta_accumulators(opt, dtype)
            for t in range(3):
                self.assertAllCloseAccordingToType((0.9 ** (t + 1)), self.evaluate(beta_1_power))
                self.assertAllCloseAccordingToType((0.999 ** (t + 1)), self.evaluate(beta_2_power))
                update.run()
                (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))