code: def testSparseBasic(self):
      for dtype in [tf.half, tf.float32, tf.float64]:
          with self.cached_session():
              var0 = tf.Variable([[1.1], [2.1]], dtype=dtype)
              var1 = tf.Variable([[3.0], [4.0]], dtype=dtype)
              grads0 = tf.IndexedSlices(
                  tf.constant([0.1], shape=[1, 1], dtype=dtype),
                  tf.constant([0]),
                  tf.constant([2, 1]),
              )
              grads1 = tf.IndexedSlices(
                  tf.constant([0.01], shape=[1, 1], dtype=dtype),
                  tf.constant([1]),
                  tf.constant([2, 1]),
              )
              decay_rate = 0.1
              batch_size = 2
              total_num_examples = 10
              sgd_optimizer = variational_sgd.VariationalSGD(
                  batch_size,
                  total_num_examples,
                  max_learning_rate=3.0,
                  burnin=0,
                  preconditioner_decay_rate=decay_rate,
              )
              if not tf.executing_eagerly():
                  sgd_op = sgd_optimizer.apply_gradients(
                      zip([grads0, grads1], [var0, var1])
                  )
  
              self.evaluate(tf1.global_variables_initializer())
              # Fetch params to validate initial values
              self.assertAllCloseAccordingToType(
                  [[1.1], [2.1]], self.evaluate(var0)
              )
              self.assertAllCloseAccordingToType(
                  [[3.0], [4.0]], self.evaluate(var1)
              )
              # Run 1 step of sgd
              if not tf.executing_eagerly():
                  self.evaluate(sgd_op)
              else:
                  sgd_optimizer.apply_gradients(
                      zip([grads0, grads1], [var0, var1])
                  )
              # Validate updated params
              self.assertAllCloseAccordingToType(
                  [[1.1 - 3.0 * 0.1], [2.1]], self.evaluate(var0)
              )
              self.assertAllCloseAccordingToType(
                  [[3.0 - 3.0 * 0], [4.0 - 3.0 * 0.01]],
                  self.evaluate(var1),
              )
  
file_path: probability/tensorflow_probability/python/optimizer/variational_sgd_test.py
imports: import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.optimizer import variational_sgd
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 8 for calling the VariationalSGDTest obj's underlying member method code with example usage: obj.testSparseBasic() without return types