import tensorflow as tf

      expected_cdf[x < 1] = 0.
      expected_cdf[x > 10] = 1.
      self.assertAllClose(expected_cdf, qdist.cdf(x).eval())

  def test_sampling_from_batch_of_normals(self):
    batch_shape = (2,)
    with self.test_session():
      qdist = distributions.QuantizedDistribution(
          base_dist_cls=distributions.Normal,
          lower_cutoff=0.,
          upper_cutoff=None,
          mu=tf.zeros(
              batch_shape, dtype=tf.float32),
          sigma=tf.ones(
              batch_shape, dtype=tf.float32))

      samps = qdist.sample_n(n=5000, seed=42)
      samps_v = samps.eval()

      # With lower_cutoff = 0, the interval j=0 is (-infty, 0], which holds 1/2
      # of the mass of the normals.
      # rtol chosen to be 2x as large as necessary to pass.
      self.assertAllClose([0.5, 0.5], (samps_v == 0).mean(axis=0), rtol=0.03)

      # The interval j=1 is (0, 1], which is from the mean to one standard
      # deviation out.  This should contain 0.6827 / 2 of the mass.
