Skip to content

Commit

Permalink
Remove tf.complex_abs from the TensorFlow Python API. tf.abs should b…
Browse files Browse the repository at this point in the history
…e used for both real and complex tensors.

Change: 142316271
  • Loading branch information
tensorflower-gardener committed Dec 17, 2016
1 parent 6b7b584 commit 1829cf1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 47 deletions.
3 changes: 2 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
made `tf.sparse_split` require keyword arguments.
* Deprecated `tf.concat` operator. Please switch to use `tf.concat_v2` for now.
In the Beta release, we will update `tf.concat` to match argument order of
`tf.concat_v2.
`tf.concat_v2`.
* `tf.complex_abs` has been removed. `tf.abs` should be used instead.

# Release 0.12.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,7 @@ def _log_abs_determinant(self):
if self._is_spd:
diag = array_ops.matrix_diag_part(self._chol)
return 2 * math_ops.reduce_sum(math_ops.log(diag), reduction_indices=[-1])

if self.dtype.is_complex:
abs_det = math_ops.complex_abs(self.determinant())
else:
abs_det = math_ops.abs(self.determinant())
abs_det = math_ops.abs(self.determinant())
return math_ops.log(abs_det)

def _solve(self, rhs, adjoint=False):
Expand Down
8 changes: 1 addition & 7 deletions tensorflow/contrib/linalg/python/ops/linear_operator_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ def assert_no_entries_with_modulus_zero(
with ops.name_scope(name, values=[x]):
x = ops.convert_to_tensor(x, name="x")
dtype = x.dtype.base_dtype

if dtype.is_complex:
should_be_nonzero = math_ops.complex_abs(x)
else:
should_be_nonzero = math_ops.abs(x)

should_be_nonzero = math_ops.abs(x)
zero = ops.convert_to_tensor(0, dtype=dtype.real_dtype)

return check_ops.assert_less(zero, should_be_nonzero, message=message)


Expand Down
4 changes: 2 additions & 2 deletions tensorflow/python/kernel_tests/cwise_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def testComplex64Basic(self):
x = np.complex(1, 1) * np.arange(-3, 3).reshape(1, 3,
2).astype(np.complex64)
y = x + 0.5 # no zeros
self._compareCpu(x, np.abs, math_ops.complex_abs)
self._compareCpu(x, np.abs, math_ops.abs)
self._compareCpu(x, np.abs, _ABS)
self._compareCpu(x, np.negative, math_ops.neg)
self._compareCpu(x, np.negative, _NEG)
Expand Down Expand Up @@ -1932,7 +1932,7 @@ def _compareBroadcastGradient(self, x):
epsilon = 1e-3
with self.test_session():
for args in [(x_, 0.), (0., x_)]:
z = math_ops.reduce_sum(math_ops.complex_abs(math_ops.complex(*args)))
z = math_ops.reduce_sum(math_ops.abs(math_ops.complex(*args)))
jacob_t, jacob_n = gradient_checker.compute_gradient(
x_, list(x.shape), z, [1], x_init_value=x, delta=epsilon)
self.assertAllClose(jacob_t, jacob_n, rtol=epsilon, atol=epsilon)
Expand Down
5 changes: 1 addition & 4 deletions tensorflow/python/ops/math_grad_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ def _testGrad(self, shape, dtype=None, max_error=None, bias=None, sigma=None):
dtype=dtype)

with self.test_session(use_gpu=True):
if dtype in (tf.complex64, tf.complex128):
output = tf.complex_abs(value)
else:
output = tf.abs(value)
output = tf.abs(value)
error = tf.test.compute_gradient_error(
value, shape, output, output.get_shape().as_list())
self.assertLess(error, max_error)
Expand Down
30 changes: 2 additions & 28 deletions tensorflow/python/ops/math_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
functions to your graph.
@@complex
@@complex_abs
@@conj
@@imag
@@real
Expand Down Expand Up @@ -292,8 +291,8 @@ def abs(x, name=None):
\\\\(y = |x|\\\\).
Args:
x: A `Tensor` or `SparseTensor` of type `float32`, `float64`, `int32`, or
`int64`.
x: A `Tensor` or `SparseTensor` of type `float16`, `float32`, `float64`,
`complex64`, `complex128`, `int32`, `int64`,
name: A name for the operation (optional).
Returns:
Expand Down Expand Up @@ -439,31 +438,6 @@ def erf(x, name=None):
return gen_math_ops.erf(x, name=name)


def complex_abs(x, name=None):
r"""Computes the complex absolute value of a tensor.
Given a tensor `x` of complex numbers, this operation returns a tensor of type
`float32` or `float64` that is the absolute value of each element in `x`. All
elements in `x` must be complex numbers of the form \\(a + bj\\). The
absolute value is computed as \\( \sqrt{a^2 + b^2}\\).
For example:
```
# tensor 'x' is [[-2.25 + 4.75j], [-3.25 + 5.75j]]
tf.complex_abs(x) ==> [5.25594902, 6.60492229]
```
Args:
x: A `Tensor` of type `complex64` or `complex128`.
name: A name for the operation (optional).
Returns:
A `Tensor` of type `float32` or `float64`.
"""
return gen_math_ops._complex_abs(x, Tout=x.dtype.real_dtype, name=name)


def scalar_mul(scalar, x):
"""Multiplies a scalar times a `Tensor` or `IndexedSlices` object.
Expand Down

0 comments on commit 1829cf1

Please sign in to comment.