Stay organized with collections
Save and categorize content based on your preferences.
tensorflow::ops::Bitcast
#include <array_ops.h>
Bitcasts a tensor from one type to another without copying data.
Summary
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)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot bitcast from float to complex128: shape [3] [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)
<tf.Tensor: ... shape=(4,), dtype=uint8, numpy=array([255, 255, 255, 255], dtype=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.
Arguments:
Returns:
Public attributes
Public functions
node
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-04-20 UTC.
[null,null,["Last updated 2020-04-20 UTC."],[],[],null,["# tensorflow::ops::Bitcast Class Reference\n\ntensorflow::ops::Bitcast\n========================\n\n`#include \u003carray_ops.h\u003e`\n\nBitcasts a tensor from one type to another without copying data.\n\nSummary\n-------\n\nGiven a tensor `input`, this operation returns a tensor that has the same buffer data as `input` with datatype `type`.\n\nIf the input datatype `T` is larger than the output datatype `type` then the shape changes from \\[...\\] to \\[..., sizeof(`T`)/sizeof(`type`)\\].\n\nIf `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 \\[...\\].\n\ntf.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,\n\nExample 1: \n\n```carbon\n\u003e\u003e\u003e a = [1., 2., 3.]\n\u003e\u003e\u003e equality_bitcast = tf.bitcast(a,tf.complex128)\ntensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot bitcast from float to complex128: shape [3] [Op:Bitcast]\n\u003e\u003e\u003e equality_cast = tf.cast(a,tf.complex128)\n\u003e\u003e\u003e print(equality_cast)\ntf.Tensor([1.+0.j 2.+0.j 3.+0.j], shape=(3,), dtype=complex128)\n```\nExample 2: \n\n```gdscript\n\u003e\u003e\u003e tf.bitcast(tf.constant(0xffffffff, dtype=tf.uint32), tf.uint8)\n\u003ctf.Tensor: ... shape=(4,), dtype=uint8, numpy=array([255, 255, 255, 255], dtype=uint8)\u003e\n```\nExample 3: \n\n```carbon\n\u003e\u003e\u003e x = [1., 2., 3.]\n\u003e\u003e\u003e y = [0., 2., 3.]\n\u003e\u003e\u003e equality= tf.equal(x,y)\n\u003e\u003e\u003e equality_cast = tf.cast(equality,tf.float32)\n\u003e\u003e\u003e equality_bitcast = tf.bitcast(equality_cast,tf.uint8)\n\u003e\u003e\u003e print(equality)\ntf.Tensor([False True True], shape=(3,), dtype=bool)\n\u003e\u003e\u003e print(equality_cast)\ntf.Tensor([0. 1. 1.], shape=(3,), dtype=float32)\n\u003e\u003e\u003e print(equality_bitcast)\ntf.Tensor(\n[[ 0 0 0 0]\n [ 0 0 128 63]\n [ 0 0 128 63]], shape=(3, 4), dtype=uint8)\n```\n\n\u003cbr /\u003e\n\n*NOTE* : [Bitcast](/versions/r1.15/api_docs/cc/class/tensorflow/ops/bitcast#classtensorflow_1_1ops_1_1_bitcast) is implemented as a low-level cast, so machines with different endian orderings will give different results.\n\nArguments:\n\n- scope: A [Scope](/versions/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): The output tensor.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [Bitcast](#classtensorflow_1_1ops_1_1_bitcast_1a05bc5afdb6742a02847bb3a8d621b149)`(const ::`[tensorflow::Scope](/versions/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, DataType type)` ||\n\n| ### Public attributes ||\n|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_bitcast_1a73096d45a2f9d4344e1129af8152435c) | [Operation](/versions/r1.15/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_bitcast_1a4b3a50f16d6247d11bfe2d42f5a438fd) | `::`[tensorflow::Output](/versions/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|-------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_bitcast_1a999d383445adeaf4c5306b84acc32444)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_bitcast_1a26b9e16d876ed44fa37352c733696aec)`() const ` | ` ` ` ` |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_bitcast_1ad3b38ccb536d06b4ce4f2f48af30b1f5)`() const ` | ` ` ` ` |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### output\n\n```text\n::tensorflow::Output output\n``` \n\nPublic functions\n----------------\n\n### Bitcast\n\n```gdscript\n Bitcast(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n DataType type\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n```"]]