Пример #1
0
  def testBasic(self):

    for dtype in [dtypes.float32, dtypes.float64]:
      one = constant_op.constant([1], dtype=dtype)
      two = constant_op.constant([2], dtype=dtype)
      zero = constant_op.constant([0], dtype=dtype)
      nan = constant_op.constant([np.nan], dtype=dtype)

      eps = constant_op.constant([np.finfo(dtype.as_numpy_dtype).eps],
                                 dtype=dtype)

      self.assertAllEqual(math_ops.nextafter(one, two) - one, eps)
      self.assertAllLess(math_ops.nextafter(one, zero) - one, 0)
      self.assertAllEqual(math_ops.is_nan(math_ops.nextafter(nan, one)), [True])
      self.assertAllEqual(math_ops.is_nan(math_ops.nextafter(one, nan)), [True])
      self.assertAllEqual(math_ops.nextafter(one, one), one)
Пример #2
0
 def testBroadcastingWithGradientChecker(self):
   for dtype in [dtypes.float32, dtypes.float64]:
     with self.cached_session():
       x1 = np.array([-1, 0, 1, 2, 3], dtype=dtype.as_numpy_dtype)
       x2 = np.array([2], dtype=dtype.as_numpy_dtype)
       err = gradient_checker_v2.max_error(
           *gradient_checker_v2.compute_gradient(
               lambda x: math_ops.nextafter(x, x2), [x1]))  # pylint: disable=cell-var-from-loop
       self.assertLess(err, 1e-3)
Пример #3
0
  def testBasic(self):

    for dtype in [dtypes.float32, dtypes.float64]:
      one = constant_op.constant([1], dtype=dtype)
      two = constant_op.constant([2], dtype=dtype)
      zero = constant_op.constant([0], dtype=dtype)
      nan = constant_op.constant([np.nan], dtype=dtype)

      eps = constant_op.constant([np.finfo(dtype.as_numpy_dtype).eps],
                                 dtype=dtype)

      self.assertAllEqual(math_ops.nextafter(one, two) - one, eps)
      self.assertAllLess(math_ops.nextafter(one, zero) - one, 0)
      self.assertAllEqual(
          math_ops.is_nan(math_ops.nextafter(nan, one)), [True])
      self.assertAllEqual(
          math_ops.is_nan(math_ops.nextafter(one, nan)), [True])
      self.assertAllEqual(math_ops.nextafter(one, one), one)
Пример #4
0
    def testBroadcasting(self):

        for dtype in [dtypes.float32, dtypes.float64]:
            one = constant_op.constant([1, 1], dtype=dtype)
            two = constant_op.constant([2], dtype=dtype)

            eps = np.finfo(dtype.as_numpy_dtype).eps

            eps_const = constant_op.constant([eps, eps], dtype=dtype)

            self.assertAllEqual(math_ops.nextafter(one, two) - one, eps_const)
Пример #5
0
  def testBroadcasting(self):

    for dtype in [dtypes.float32, dtypes.float64]:
      one = constant_op.constant([1, 1], dtype=dtype)
      two = constant_op.constant([2], dtype=dtype)

      eps = np.finfo(dtype.as_numpy_dtype).eps

      eps_const = constant_op.constant([eps, eps], dtype=dtype)

      self.assertAllEqual(math_ops.nextafter(one, two) - one, eps_const)
Пример #6
0
 def _nextafter_gradient(self, x1, x2):
   with backprop.GradientTape() as tape:
     tape.watch(x1)
     tape.watch(x2)
     y = math_ops.nextafter(x1, x2)
     return tape.gradient(y, [x1, x2])