MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / abs

Function abs

tensorflow/python/ops/math_ops.py:247–278  ·  view source on GitHub ↗

r"""Computes the absolute value of a tensor. Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input. Given a tensor `x` of complex numbers, this operation

(x, name=None)

Source from the content-addressed store, hash-verified

245@tf_export("math.abs", "abs")
246@dispatch.add_dispatch_support
247def abs(x, name=None): # pylint: disable=redefined-builtin
248 r"""Computes the absolute value of a tensor.
249
250 Given a tensor of integer or floating-point values, this operation returns a
251 tensor of the same type, where each element contains the absolute value of the
252 corresponding element in the input.
253
254 Given a tensor `x` of complex numbers, this operation returns a tensor of type
255 `float32` or `float64` that is the absolute value of each element in `x`. All
256 elements in `x` must be complex numbers of the form \\(a + bj\\). The
257 absolute value is computed as \\( \sqrt{a^2 + b^2}\\). For example:
258 ```python
259 x = tf.constant([[-2.25 + 4.75j], [-3.25 + 5.75j]])
260 tf.abs(x) # [5.25594902, 6.60492229]
261 ```
262
263 Args:
264 x: A `Tensor` or `SparseTensor` of type `float16`, `float32`, `float64`,
265 `int32`, `int64`, `complex64` or `complex128`.
266 name: A name for the operation (optional).
267
268 Returns:
269 A `Tensor` or `SparseTensor` the same size, type, and sparsity as `x` with
270 absolute values.
271 Note, for `complex64` or `complex128` input, the returned `Tensor` will be
272 of type `float32` or `float64`, respectively.
273 """
274 with ops.name_scope(name, "Abs", [x]) as name:
275 x = ops.convert_to_tensor(x, name="x")
276 if x.dtype.is_complex:
277 return gen_math_ops.complex_abs(x, Tout=x.dtype.real_dtype, name=name)
278 return gen_math_ops._abs(x, name=name)
279
280
281# pylint: enable=g-docstring-has-escape

Callers 15

_runnerMethod · 0.70
_SvdGradFunction · 0.70
_range_testMethod · 0.70
_preluMethod · 0.50
_preluMethod · 0.50
get_fae_expvMethod · 0.50
SparsifyWeightsFunction · 0.50
QuantizeWeightsFunction · 0.50
RoundWeightsFunction · 0.50
rotate_transposeFunction · 0.50
_calc_hash_func_numMethod · 0.50

Calls 1

name_scopeMethod · 0.45

Tested by 15

_runnerMethod · 0.56
_range_testMethod · 0.56
ops_testMethod · 0.40
_assertRecentMethod · 0.40
testOperatorOverrideMethod · 0.40
testTrainNetworkMethod · 0.40
testTrainNetworkMethod · 0.40