code: def ref_spectral_norm(
      w, u, dim=0, itr=1, eps=1e-12, test=False, output_u=False
  ):
      w_shape = w.shape
      if dim != 0:
          dims_transpose = [dim] + [
              i for i in range(len(w_shape)) if i != dim
          ]
          w = w.transpose(*dims_transpose)
          w_shape = w.shape
      d0, d1 = w_shape[0], np.prod(w_shape[1:])  # [Out, In]
      w = w.reshape((d0, d1))
      u_original = u
      for i in range(itr):
          v = np.dot(w.T, u)
          v = v / np.sqrt(np.sum(v**2) + eps)
          u = np.dot(w, v)
          u = u / np.sqrt(np.sum(u**2) + eps)
      sigma = np.dot(u.T, np.dot(w, v))
      w_sn = w / sigma
      w_sn = w_sn.reshape(w_shape)
      if dim != 0:
          dims_transpose = (
              [i for i in range(1, dim + 1)]
              + [0]
              + [i for i in range(dim + 1, len(w_shape))]
          )
          w_sn = w_sn.transpose(*dims_transpose)
  
      if output_u:
          return w_sn, u_original
      else:
          return w_sn
  
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 1 for calling a global function with example usage: ref_spectral_norm(w, u, dim, itr, eps, test, output_u) and returns: w_sn,  u_original, w_sn