# tf.compat.v1.to_complex128

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/math_ops.py#L1342-L1379) |

Casts a tensor to type `complex128`. (deprecated)

    tf.compat.v1.to_complex128(
        x, name='ToComplex128'
    )

<br />

## Migrate to TF2

<br />

> [!CAUTION]
> **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.

This name was deprecated and removed in TF2, but has an exact replacement
[`tf.cast(..., tf.complex128)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/cast). There are no further issues with eager
execution or tf.function.

Before:

    tf.compat.v1.to_complex128(tf.constant(1. + 2.j, dtype=tf.complex64))
    <tf.Tensor: shape=(), dtype=complex128, numpy=(1+2j)>

After:

    tf.cast(tf.constant(1. + 2.j, dtype=tf.complex64), tf.complex128)
    <tf.Tensor: shape=(), dtype=complex128, numpy=(1+2j)>

<br />

<br />

## Description

> [!WARNING]
> **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use [`tf.cast`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/cast) instead.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | A `Tensor` or `SparseTensor` or `IndexedSlices`. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` or `SparseTensor` or `IndexedSlices` with same shape as `x` with type `complex128`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If `x` cannot be cast to the `complex128`. |

<br />