tensorflow:: אופס:: Bitcast
#include <array_ops.h>
מעביר טנזור מסוג אחד לאחר מבלי להעתיק נתונים.
תַקצִיר
בהינתן input
טנזור, פעולה זו מחזירה טנזור בעל אותם נתוני חיץ כמו input
עם type
נתונים.
אם סוג נתוני הקלט T
גדול יותר type
הנתונים הפלט, הצורה משתנה מ- [...] ל-[..., sizeof( T
)/sizeof( type
)].
אם T
קטן מ- type
, האופרטור דורש שהממד הימני ביותר יהיה שווה ל-sizeof( type
)/sizeof( T
). לאחר מכן, הצורה עוברת מ-[..., sizeof( type
)/sizeof( T
)] ל- [...].
tf.bitcast() ו-tf.cast() פועלים בצורה שונה כאשר dtype אמיתי נוצק כ-dtype מורכב (למשל tf.complex64 או tf.complex128) שכן tf.cast() הופכים את החלק הדמיוני ל-0 בעוד tf.bitcast() נותן מודול שְׁגִיאָה. לְדוּגמָה,
דוגמה 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)
דוגמה 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)>
דוגמה 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)
הערה : Bitcast מיושם כקאסט ברמה נמוכה, כך שמכונות עם סדרי אנדיאנים שונים יתנו תוצאות שונות.
טיעונים:
החזרות:
תכונות ציבוריות
מִבצָע
Operation operation
תְפוּקָה
::tensorflow::Output output
תפקידים ציבוריים
Bitcast
Bitcast(
const ::tensorflow::Scope & scope,
::tensorflow::Input input,
DataType type
)
צוֹמֶת
::tensorflow::Node * node() const
operator::tensorflow::Input() const
אופרטור::tensorflow::פלט
operator::tensorflow::Output() const
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-25 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-25 (שעון 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/r2.0/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/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.0/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/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.0/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/r2.0/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_bitcast_1a4b3a50f16d6247d11bfe2d42f5a438fd) | `::`[tensorflow::Output](/versions/r2.0/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```"]]