class_docstr: Spectral Normalization link hook implementation.
  
  This hook normalizes a weight using max singular value and this value
  is computed via power iteration method. Currently, this hook is supposed to
  be added to :class:`chainer.links.Linear`, :class:`chainer.links.EmbedID`,
  :class:`chainer.links.Convolution2D`, :class:`chainer.links.ConvolutionND`,
  :class:`chainer.links.Deconvolution2D`,
  and :class:`chainer.links.DeconvolutionND`. However, you can use this to
  other links like RNNs by specifying ``weight_name``.
  It is highly recommended to add this hook before optimizer setup because
  this hook add a scaling parameter ``gamma`` if ``use_gamma`` is True.
  Otherwise, the registered ``gamma`` will not be updated.
  
  .. math::
  
     \bar{\mathbf{W}} &=& \dfrac{\mathbf{W}}{\sigma(\mathbf{W})} \\
     \text{, where} \ \sigma(\mathbf{W}) &:=&
      \max_{\mathbf{h}: \mathbf{h} \ne 0}
     \dfrac{\|\mathbf{W} \mathbf{h}\|_2}{\|\mathbf{h}\|_2}
      = \max_{\|\mathbf{h}\|_2 \le 1} \|\mathbf{W}\mathbf{h}\|_2
  
  See: T. Miyato et. al., `Spectral Normalization for Generative Adversarial
  Networks <https://arxiv.org/abs/1802.05957>`_
  
  Args:
      n_power_iteration (int): Number of power iteration.
          The default value is 1.
      eps (float): Numerical stability in norm calculation.
          The default value is 1e-6 for the compatibility with
          mixed precision training. The value used in the author's
          implementation is 1e-12.
      use_gamma (bool): If ``True``, weight scaling parameter gamma which is
          initialized by initial weight's max singular value is introduced.
      factor (float, None): Scaling parameter to divide maximum singular
          value.  The default value is 1.0.
      weight_name (str): Link's weight name to apply this hook. The default
          value is ``'W'``.
      name (str or None): Name of this hook. The default value is
          ``'SpectralNormalization'``.
  
  Attributes:
      vector_name (str): Name of the approximate first left singular vector
          registered in the target link.
          the target link.
      axis (int): Axis of weight represents the number of output
          feature maps or output units (``out_channels`` and
          ``out_size``, respectively).
  
  .. admonition:: Example
  
      There are almost the same but 2 ways to apply spectral normalization
      (SN) hook to links.
  
      1. Initialize link and SN separately. This makes it easy to handle
      buffer and parameter of links registered by SN hook.
  
          >>> l = L.Convolution2D(3, 5, 3)
          >>> hook = chainer.link_hooks.SpectralNormalization()
          >>> _ = l.add_hook(hook)
          >>> # Check the shape of the first left singular vector.
          >>> getattr(l, hook.vector_name).shape
          (5,)
          >>> # Delete SN hook from this link.
          >>> l.delete_hook(hook.name)
  
      2. Initialize both link and SN hook at one time. This makes it easy to
      define your original :class:`~chainer.Chain`.
  
          >>> # SN hook handles lazy initialization!
          >>> layer = L.Convolution2D(
          ...     5, 3, stride=1, pad=1).add_hook(
          ...         chainer.link_hooks.SpectralNormalization())
code: def added(self, link):
      # Define axis and register ``u`` if the weight is initialized.
      if not hasattr(link, self.weight_name):
          raise ValueError(
              "Weight '{}' does not exist!".format(self.weight_name)
          )
      if isinstance(link, (L.Deconvolution2D, L.DeconvolutionND)):
          self.axis = 1
      if getattr(link, self.weight_name).array is not None:
          self._prepare_parameters(link)
  
imports: import chainer
  from chainer import backend
  from chainer import configuration
  import chainer.functions
  from chainer import link_hook
  import chainer.links
  from chainer import variable
  import chainerx
label_desc: Use image node_id 4 for calling the SpectralNormalization obj's underlying member method code with example usage: obj.added(link) without return types