code: def test_clip_grad():
      a = np.array([1, 2, -3])
      b = np.array([4, 5, -6])
      clip = 2
      gscale = np.minimum(
          1.0,
          clip / np.sqrt(np.sum(np.square(a)) + np.sum(np.square(b))),
      )
      for lhs, rhs in zip(
          clip_grad(
              [nd.array(a), nd.array(b)],
              GradientClippingMethod.ClipByGlobalNorm,
              clip_val=clip,
          ),
          [a, b],
      ):
          assert np.allclose(lhs.asnumpy(), rhs * gscale)
      for lhs, rhs in zip(
          clip_grad(
              [nd.array(a), nd.array(b)],
              GradientClippingMethod.ClipByValue,
              clip_val=clip,
          ),
          [a, b],
      ):
          assert np.allclose(lhs.asnumpy(), np.clip(rhs, -clip, clip))
      for lhs, rhs in zip(
          clip_grad(
              [nd.array(a), nd.array(b)],
              GradientClippingMethod.ClipByNorm,
              clip_val=clip,
          ),
          [a, b],
      ):
          scale = np.minimum(
              1.0, clip / np.sqrt(np.sum(np.square(rhs)))
          )
          assert np.allclose(lhs.asnumpy(), rhs * scale)
  
imports: import pytest
  import mxnet
  from mxnet import nd
  import numpy
  from rl_coach.architectures.mxnet_components.utils import *
label_desc: Use image node_id 11 for calling a global function with example usage: test_clip_grad() without return types