# Bitcast

public final class **Bitcast** Bitcasts a tensor from one type to another without copying data.


Given a tensor \`input\`, this operation returns a tensor that has the same buffer
data as \`input\` with datatype \`type\`.


If the input datatype \`T\` is larger than the output datatype \`type\` then the
shape changes from \[...\] to \[..., sizeof(\`T\`)/sizeof(\`type\`)\].


If \`T\` is smaller than \`type\`, the operator requires that the rightmost
dimension be equal to sizeof(\`type\`)/sizeof(\`T\`). The shape then goes from
\[..., sizeof(\`type\`)/sizeof(\`T\`)\] to \[...\].


tf.bitcast() and tf.cast() work differently when real dtype is casted as a complex dtype
(e.g. tf.complex64 or tf.complex128) as tf.cast() make imaginary part 0 while tf.bitcast()
gives module error.
For example,


Example 1:


\>\>\> a = \[1., 2., 3.\]
\>\>\> equality_bitcast = tf.bitcast(a, tf.complex128)
Traceback (most recent call last):
...
InvalidArgumentError: Cannot bitcast from 1 to 18 \[Op:Bitcast\]
\>\>\> equality_cast = tf.cast(a, tf.complex128)
\>\>\> print(equality_cast)
tf.Tensor(\[1.+0.j 2.+0.j 3.+0.j\], shape=(3,), dtype=complex128)


Example 2:


\>\>\> tf.bitcast(tf.constant(0xffffffff, dtype=tf.uint32), tf.uint8)


Example 3:


\>\>\> x = \[1., 2., 3.\]
\>\>\> y = \[0., 2., 3.\]
\>\>\> equality= tf.equal(x,y)
\>\>\> equality_cast = tf.cast(equality,tf.float32)
\>\>\> equality_bitcast = tf.bitcast(equality_cast,tf.uint8)
\>\>\> print(equality)
tf.Tensor(\[False True True\], shape=(3,), dtype=bool)
\>\>\> print(equality_cast)
tf.Tensor(\[0. 1. 1.\], shape=(3,), dtype=float32)
\>\>\> print(equality_bitcast)
tf.Tensor(
\[\[ 0 0 0 0\]
\[ 0 0 128 63\]
\[ 0 0 128 63\]\], shape=(3, 4), dtype=uint8)


*NOTE*: Bitcast is implemented as a low-level cast, so machines with different
endian orderings will give different results. A copy from input buffer to output
buffer is made on BE machines when types are of different sizes in order to get
the same casting results as on LE machines.

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

### Public Methods

|---|---|
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/Bitcast#asOutput())() Returns the symbolic handle of a tensor. |
| static \<U, T\> [Bitcast](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/Bitcast)\<U\> | [create](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/Bitcast#create(org.tensorflow.op.Scope,%20org.tensorflow.Operand<T>,%20java.lang.Class<U>))([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> input, Class\<U\> type) Factory method to create a class wrapping a new Bitcast operation. |
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\> | [output](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/Bitcast#output())() |

### Inherited Methods

From class [org.tensorflow.op.PrimitiveOp](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp)

|---|---|
| final boolean | [equals](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#equals(java.lang.Object))(Object obj) |
| final int | [hashCode](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#hashCode())() |
| [Operation](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation) | [op](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#op())() Returns the underlying `https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation` |
| final String | [toString](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#toString())() |

From class java.lang.Object

|---|---|
| boolean | equals(Object arg0) |
| final Class\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| String | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

From interface [org.tensorflow.Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)

|---|---|
| abstract [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand#asOutput())() Returns the symbolic handle of a tensor. |

## Public Methods

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\>
**asOutput**
()

Returns the symbolic handle of a tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is
used to obtain a symbolic handle that represents the computation of the input.

<br />

#### public static [Bitcast](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/Bitcast)\<U\>
**create**
([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> input, Class\<U\> type)

Factory method to create a class wrapping a new Bitcast operation.

##### Parameters

| scope | current scope |
|---|---|

##### Returns

- a new instance of Bitcast

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<U\>
**output**
()

<br />