code: def ref_grad_spectral_norm(
      w, u, dy, du, dim, itr, eps, test, output_u, need_grad_flags
  ):
      # We need this function for using `function_tester`
      # because the numerical gradient of `w` will not be calculated correctly.
      # The reason is there are some intermediate variables with `need_grad == false`
      # which are connected to the input `w` in the function composite implementation.
  
      cpu_context = nn.Context(["cpu:float"])
      with nn.context_scope(cpu_context):
          w = nn.Variable.from_numpy_array(w)
          u = nn.Variable.from_numpy_array(u)
          w.need_grad = True
          w.grad.zero()
          w_sn = PF._spectral_norm_v1(
              w,
              u_init=u.data.get_data("r"),
              dim=dim,
              itr=itr,
              test=test,
          )
  
          w_sn.forward(clear_no_need_grad=True)
          w_sn.backward(dy, clear_buffer=True)
  
      return w.grad.get_data("r").flatten()
  
file_path: nnabla/python/test/function/test_spectral_norm.py
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  import nnabla.parametric_functions
  from nbla_test_utils import list_context
label_desc: Use image node_id 2 for calling a global function with example usage: ref_grad_spectral_norm(w, u, dy, du, dim, itr, eps, test, output_u, need_grad_flags) and returns: w