code: def test_pf_weight_norm_execution(g_rng, func):
      # python implementation
      def ref_weight_normalization(v, g, dim, eps=1e-12):
          # Use the same w in the initialization time.
          # Since unless we use the same magnitude of weights,
          # glorot/he initialization does not work as expected.
          return v
  
      dim = {"conv": 0, "affine": 1}[func]
  
      def wn_clbk(v):
          return PF.weight_normalization(v, dim=dim)
  
      x = nn.Variable.from_numpy_array(g_rng.randn(2, 4, 5, 5))
      if func == "conv":
          # assume channel first
          y = PF.convolution(x, 8, (3, 3), apply_w=wn_clbk)
      elif func == "affine":
          y = PF.affine(x, 8, apply_w=wn_clbk)
      else:
          raise ValueError("unexpected function name {}".format(func))
  
      # Setting
      y.forward()
      y.backward()
  
      params = nn.get_parameters()
      assert len(params) == 3  # w, b, g
  
      # Check values
      v = params["{}/W".format(func)]
      w = y.parent.inputs[1]
  
      v_np = v.d
      w_np = ref_weight_normalization(v_np, 1, dim)
  
      assert_allclose(w.d, w_np, atol=1e-2, rtol=1e-5)
  
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  import nnabla.parametric_functions
  import nnabla.initializer
  from nnabla.testing import assert_allclose
  from nbla_test_utils import list_context
label_desc: Use image node_id 31 for calling a global function with example usage: test_pf_weight_norm_execution(g_rng, func) and returns: v, PF