import tensorflow as tf

          atol=0)
      # Test interval (-1, 0], <--> index 0.
      self.assertAllClose(
          np.log(sm_normal.cdf(0) - sm_normal.cdf(-1)),
          qdist.log_prob(0.).eval(),
          atol=0)
      # Test interval (1, inf), <--> index 2.
      self.assertAllClose(
          np.log(1. - sm_normal.cdf(1)),
          qdist.log_prob(2.).eval(),
          atol=0)

  def test_log_prob_and_grad_gives_finite_results(self):
    with self.test_session():
      for dtype in [np.float32, np.float64]:
        mu = tf.Variable(0., name="mu", dtype=dtype)
        sigma = tf.Variable(1., name="sigma", dtype=dtype)
        qdist = distributions.QuantizedDistribution(
            base_dist_cls=distributions.Normal,
            mu=mu,
            sigma=sigma)
        x = np.arange(-100, 100, 2).astype(dtype)

        tf.initialize_all_variables().run()

        proba = qdist.log_prob(x)
        grads = tf.gradients(proba, [mu, sigma])

        self._assert_all_finite(proba.eval())
        self._assert_all_finite(grads[0].eval())
