code: def _random_fill(t, scale, mode, distribution):
      """Fill the tensor with values sampled from a distribution.
  
      With `distribution="normal"`, samples are drawn from a normal
      distribution centered on zero, with `stddev = sqrt(scale / n)` where n is:
          - number of input units in the weight tensor, if mode = "fan_in"
          - number of output units, if mode = "fan_out"
          - average of the numbers of input and output units, if mode = "fan_avg"
  
      With `distribution="uniform"`,
      samples are drawn from a uniform distribution
      within [-limit, limit], with `limit = sqrt(3 * scale / n)`.
  
  
      Args:
          t (Tensor): Tensor to be filled
          scale (float): scale factor
          mode (str): "fan_in" or "fan_out" or "fan_avg"
          distribution (str): "normal" or "uniform"
  
      Raises:
          ValueError: In case of an invalid value for scale, mode or distribution
      """
      if scale <= 0.0:
          raise ValueError(
              "`scale` must be a positive float. Got:", scale
          )
      mode = mode.lower()
      if mode not in {"fan_in", "fan_out", "fan_avg"}:
          raise ValueError(
              "Invalid `mode` argument: "
              'expected on of {"fan_in", "fan_out", "fan_avg"} '
              "but got",
              mode,
          )
      distribution = distribution.lower()
      if distribution not in {"normal", "uniform"}:
          raise ValueError(
              "Invalid `distribution` argument: "
              'expected one of {"normal", "uniform"} '
              "but got",
              distribution,
          )
  
      fan_in, fan_out = _compute_fans(t.shape)
      if mode == "fan_in":
          scale /= max(1.0, fan_in)
      elif mode == "fan_out":
          scale /= max(1.0, fan_out)
      else:
          scale /= max(1.0, float(fan_in + fan_out) / 2)
      if distribution == "normal":
          # 0.879... = scipy.stats.truncnorm.std(a=-2, b=2, loc=0., scale=1.)
          # stddev = np.sqrt(scale) / .87962566103423978
          t.gaussian(0.0, np.sqrt(scale))
      else:
          limit = np.sqrt(3.0 * scale)
          t.uniform(-limit, limit)
  
file_path: singa/python/singa/initializer.py
imports: from __future__ import division
  import math
  import numpy
  from deprecated import deprecated
label_desc: Use image node_id 14 for calling a global function with example usage: _random_fill(t, scale, mode, distribution) without return types