Skip to content

Commit

Permalink
Fix tf.test.compute_gradients to exercise imaginary parts
Browse files Browse the repository at this point in the history
Previously, if x_init_value was not specified, it was set to a random real
value.  This is bad if the dtype is complex, since the imaginary part is left
zero.
Change: 148368889
  • Loading branch information
girving authored and tensorflower-gardener committed Feb 23, 2017
1 parent d58dd2d commit 7b8115f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions tensorflow/python/ops/gradient_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,9 @@ def _compute_gradient(x,
x_shape, i_shape)
x_data = x_init_value
else:
if t == dtypes.float16:
dtype = np.float16
elif t == dtypes.float32:
dtype = np.float32
else:
dtype = np.float64
x_data = np.asfarray(np.random.random_sample(x_shape), dtype=dtype)
x_data = np.random.random_sample(x_shape).astype(t.as_numpy_dtype)
if t.is_complex:
x_data.imag = np.random.random_sample(x_shape)

jacob_t = _compute_theoretical_jacobian(
x, x_shape, x_data, dy, y_shape, dx, extra_feed_dict=extra_feed_dict)
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/python/ops/gradient_checker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def testComplexConj(self):
size)
correct = np.array([[1, 0], [0, -1]])
self.assertAllEqual(correct, analytical)
self.assertAllClose(correct, numerical, rtol=3e-6)
self.assertAllClose(correct, numerical, rtol=2e-5)
self.assertLess(
gradient_checker.compute_gradient_error(x, size, y, size), 2e-5)

Expand Down

0 comments on commit 7b8115f

Please sign in to comment.