function cast_(x, dtype) {
    const $x = (0, _tensorUtilEnv.convertToTensor)(x, "x", "cast");
    // Sanity checks.
    if (!_util.isValidDtype(dtype)) throw new Error(`Failed to cast to unknown dtype ${dtype}`);
    if (dtype === "string" && $x.dtype !== "string" || dtype !== "string" && $x.dtype === "string") throw new Error("Only strings can be casted to strings");
    const inputs = {
        x: $x
    };
    const attrs = {
        dtype
    };
    return (0, _engine.ENGINE).runKernel((0, _kernelNames.Cast), inputs, attrs);
}
Casts a `tf.Tensor` to a new dtype.

```js
const x = tf.tensor1d([1.5, 2.5, 3]);
tf.cast(x, 'int32').print();
```
@param x The input tensor to be casted.
@param dtype The dtype to cast the input tensor to.

@doc {heading: 'Tensors', subheading: 'Transformations'}