def test_differs_given_different_seed(self): sequence_1 = tf_utils._cmwc_random_sequence(100, tf.constant(123, tf.int64)) sequence_2 = tf_utils._cmwc_random_sequence( 100, tf.constant(1234, tf.int64)) sequence_1, sequence_2 = self.evaluate([sequence_1, sequence_2]) self.assertFalse(np.array_equal(sequence_1, sequence_2))
def test_deterministic_given_seed(self): sequence_1 = tf_utils._cmwc_random_sequence(10, tf.constant(123, tf.int64)) sequence_2 = tf_utils._cmwc_random_sequence( 10, tf.constant(120 + 3, tf.int64)) sequence_1, sequence_2 = self.evaluate([sequence_1, sequence_2]) self.assertAllEqual(sequence_1, sequence_2)
def test_approximately_uniform_distribution(self): sequence = tf_utils._cmwc_random_sequence(100000, tf.constant(123, tf.int64)) sequence = self.evaluate(sequence) bucket_counts, _ = np.histogram(sequence, bins=10, range=(0, 1)) self.assertAllGreaterEqual(bucket_counts, 9750) self.assertAllLessEqual(bucket_counts, 10250)
def test_expected_output_shape(self, num_elements): sequence = tf_utils._cmwc_random_sequence(num_elements, tf.constant(123, tf.int64)) self.assertAllEqual([num_elements], sequence.shape.as_list()) self.assertEqual(tf.float64, sequence.dtype) sequence = self.evaluate(sequence) self.assertAllGreaterEqual(sequence, 0.0) self.assertAllLessEqual(sequence, 1.0)
def test_tf_int32_seed_raises(self): with self.assertRaisesRegexp(TypeError, 'tf.int64 Tensor'): tf_utils._cmwc_random_sequence(10, tf.constant(123, tf.int32))
def test_python_seed_raises(self): with self.assertRaisesRegexp(TypeError, 'tf.int64 Tensor'): tf_utils._cmwc_random_sequence(10, 123)
def test_negative_num_elements_raises(self): with self.assertRaisesRegexp(ValueError, 'must be positive'): tf_utils._cmwc_random_sequence(-10, tf.constant(123, tf.int64))
def test_tensor_num_elements_raises(self): with self.assertRaisesRegexp(TypeError, 'must be a Python integer'): tf_utils._cmwc_random_sequence(tf.constant(10), tf.constant(123, tf.int64))