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

Function complex

tensorflow/python/ops/math_ops.py:465–505  ·  view source on GitHub ↗

r"""Converts two real numbers to a complex number. Given a tensor `real` representing the real part of a complex number, and a tensor `imag` representing the imaginary part of a complex number, this operation returns complex numbers elementwise of the form \\(a + bj\\), where *a* represents

(real, imag, name=None)

Source from the content-addressed store, hash-verified

463@tf_export("dtypes.complex", "complex")
464@dispatch.add_dispatch_support
465def complex(real, imag, name=None):
466 r"""Converts two real numbers to a complex number.
467
468 Given a tensor `real` representing the real part of a complex number, and a
469 tensor `imag` representing the imaginary part of a complex number, this
470 operation returns complex numbers elementwise of the form \\(a + bj\\), where
471 *a* represents the `real` part and *b* represents the `imag` part.
472
473 The input tensors `real` and `imag` must have the same shape.
474
475 For example:
476
477 ```python
478 real = tf.constant([2.25, 3.25])
479 imag = tf.constant([4.75, 5.75])
480 tf.complex(real, imag) # [[2.25 + 4.75j], [3.25 + 5.75j]]
481 ```
482
483 Args:
484 real: A `Tensor`. Must be one of the following types: `float32`, `float64`.
485 imag: A `Tensor`. Must have the same type as `real`.
486 name: A name for the operation (optional).
487
488 Returns:
489 A `Tensor` of type `complex64` or `complex128`.
490
491 Raises:
492 TypeError: Real and imag must be correct types
493 """
494 real = ops.convert_to_tensor(real, name="real")
495 imag = ops.convert_to_tensor(imag, name="imag")
496 with ops.name_scope(name, "Complex", [real, imag]) as name:
497 input_types = (real.dtype, imag.dtype)
498 if input_types == (dtypes.float64, dtypes.float64):
499 Tout = dtypes.complex128
500 elif input_types == (dtypes.float32, dtypes.float32):
501 Tout = dtypes.complex64
502 else:
503 raise TypeError("real and imag have incorrect types: "
504 "{} {}".format(real.dtype.name, imag.dtype.name))
505 return gen_math_ops._complex(real, imag, Tout=Tout, name=name)
506
507
508@tf_export("math.real", v1=["math.real", "real"])

Callers 7

testComplexMethod · 0.85
MakeNdarrayFunction · 0.85
testComplexOpsMethod · 0.85
tensor.goFile · 0.85
TestNewTensorFunction · 0.85
TestTensorSerializationFunction · 0.85

Calls 2

name_scopeMethod · 0.45
formatMethod · 0.45

Tested by 5

testComplexMethod · 0.68
testComplexOpsMethod · 0.68
TestNewTensorFunction · 0.68
TestTensorSerializationFunction · 0.68