def testXdivyWithZero(self): for dtype in [dtypes.float16, dtypes.float32, dtypes.float64]: x = constant_op.constant(np.zeros((2, 3)), dtype=dtype) y = constant_op.constant([[0.1, 0.2, 3.5], [0., 1., 2.]], dtype=dtype) with self.cached_session(use_gpu=True): xdivy_tf_np = self.evaluate(math_ops.xdivy(x, y)) zeros_np = self.evaluate(array_ops.zeros_like(y)) self.assertAllClose(xdivy_tf_np, zeros_np)
def testXdivyNoZero(self): for dtype in [dtypes.float16, dtypes.float32, dtypes.float64]: x = constant_op.constant([[0.1, 0.2, 3.5], [-2., -5., 30.]], dtype=dtype) y = constant_op.constant([[0.1, 0.2, 3.5], [3.1, 4., 2.]], dtype=dtype) with self.cached_session(use_gpu=True): xdivy = self.evaluate(math_ops.xdivy(x, y)) x_over_y = self.evaluate(x / y) self.assertAllClose(xdivy, x_over_y)
def testXdivyNoZero(self): for dtype in [dtypes.float16, dtypes.float32, dtypes.float64]: x = constant_op.constant([[0.1, 0.2, 3.5], [-2., -5., 30.]], dtype=dtype) y = constant_op.constant([[0.1, 0.2, 3.5], [3.1, 4., 2.]], dtype=dtype) with test_util.use_gpu(): xdivy = self.evaluate(math_ops.xdivy(x, y)) x_over_y = self.evaluate(x / y) self.assertAllClose(xdivy, x_over_y)
def testXdivyWithZero(self): for dtype in [dtypes.float16, dtypes.float32, dtypes.float64]: x = constant_op.constant(np.zeros((2, 3)), dtype=dtype) y = constant_op.constant([[0.1, 0.2, 3.5], [0., 1., 2.]], dtype=dtype) with self.cached_session(use_gpu=True): xdivy_tf_np = self.evaluate(math_ops.xdivy(x, y)) zeros_np = self.evaluate(array_ops.zeros_like(y)) self.assertAllClose(xdivy_tf_np, zeros_np)
def testXdivyWithZeroBroadcast(self): for dtype in [dtypes.float16, dtypes.float32, dtypes.float64]: x = constant_op.constant([[0.], [1.]], dtype=dtype) y = constant_op.constant([[0.1, 0.2, 3.5], [0., 1., 2.]], dtype=dtype) with test_util.use_gpu(): xdivy_tf_np = self.evaluate(math_ops.xdivy(x, y)) zeros_np = self.evaluate(array_ops.zeros_like(y[0])) x_over_y = self.evaluate(1 / y[1]) self.assertAllClose(zeros_np, xdivy_tf_np[0]) self.assertAllClose(x_over_y, xdivy_tf_np[1])
def testXdivyWithZeroBroadcast(self): for dtype in [dtypes.float16, dtypes.float32, dtypes.float64]: x = constant_op.constant([[0.], [1.]], dtype=dtype) y = constant_op.constant([[0.1, 0.2, 3.5], [0., 1., 2.]], dtype=dtype) with self.cached_session(use_gpu=True): xdivy_tf_np = self.evaluate(math_ops.xdivy(x, y)) zeros_np = self.evaluate(array_ops.zeros_like(y[0])) x_over_y = self.evaluate(1 / y[1]) self.assertAllClose(zeros_np, xdivy_tf_np[0]) self.assertAllClose(x_over_y, xdivy_tf_np[1])
def _xdivy_gradients(self, x, y): xdivy_xgrad = self.evaluate(gradients.gradients(math_ops.xdivy(x, y), x)[0]) xdivy_ygrad = self.evaluate(gradients.gradients(math_ops.xdivy(x, y), y)[0]) return xdivy_xgrad, xdivy_ygrad