Example #1
0
 def testUniform(self):
   minval = 0.43
   maxval = 3.10
   shape = [13, 34, 29]
   atol = 0.1
   outputs = extensions.uniform(123, shape, minval=minval, maxval=maxval)
   self.assertAllClose((minval + maxval) / 2.0, np.mean(outputs), atol=atol)
Example #2
0
File: math.py Project: zzszmyf/trax
def tf_randint(key, shape, minval, maxval, dtype=onp.int32):
  """Sample uniform random values in [minval, maxval) with given shape/dtype.

  Args:
    key: a PRNGKey used as the random key.
    shape: a tuple of nonnegative integers representing the shape.
    minval: int or array of ints broadcast-compatible with ``shape``, a minimum
      (inclusive) value for the range.
    maxval: int or array of ints broadcast-compatible with  ``shape``, a maximum
      (exclusive) value for the range.
    dtype: optional, an int dtype for the returned values (default int32).

  Returns:
    A random array with the specified shape and dtype.
  """
  return tf_np_extensions.uniform(key, shape, minval=minval, maxval=maxval,
                                  dtype=dtype)