class_docstr: Tests optimization.
      
docstr: Tests get_gradient_clip_fn.
          
code: def test_get_gradient_clip_fn(
      self,
  ):  # pylint: disable=too-many-locals
      """Tests get_gradient_clip_fn."""
      default_grad_clip_fn = opt.get_gradient_clip_fn(
          opt.default_optimization_hparams()["gradient_clip"]
      )
      self.assertIsNone(default_grad_clip_fn)
  
      grads = [tf.random_uniform([10, 10], -1.0, 1.0) for _ in range(5)]
      grads_and_vars = list(zip(grads, range(5)))
  
      hparams = {
          "type": "clip_by_global_norm",
          "kwargs": {"clip_norm": 0.1},
      }
      gn_grad_clip_fn = opt.get_gradient_clip_fn(hparams)
      gn_grads_and_vars = gn_grad_clip_fn(grads_and_vars)
      gn_grads, _ = zip(*gn_grads_and_vars)
      gn_grads_true, _ = tf.clip_by_global_norm(
          grads, hparams["kwargs"]["clip_norm"]
      )
  
      hparams = {
          "type": "clip_by_value",
          "kwargs": {"clip_value_min": -0.01, "clip_value_max": 0.01},
      }
      v_grad_clip_fn = opt.get_gradient_clip_fn(hparams)
      v_grads_and_vars = v_grad_clip_fn(grads_and_vars)
      v_grads, _ = zip(*v_grads_and_vars)
      v_grads_true = tf.clip_by_value(
          grads,
          hparams["kwargs"]["clip_value_min"],
          hparams["kwargs"]["clip_value_max"],
      )
  
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          gn_grads_, gn_grads_true_, v_grads_, v_grads_true_ = sess.run(
              [gn_grads, gn_grads_true, v_grads, v_grads_true]
          )
          np.testing.assert_array_equal(gn_grads_, gn_grads_true_)
          np.testing.assert_array_equal(v_grads_, v_grads_true_)
  
file_path: texar/tests/core/optimization_test.py
imports: import numpy
  import tensorflow
  import texar.tf.core.optimization
  from texar.tf.utils import utils
label_desc: Use image node_id 3 for calling the OptimizationTest obj's underlying member method code with example usage: obj.test_get_gradient_clip_fn() without return types