جریان تنسور:: عملیات:: بیت کست
#include <array_ops.h>
یک تانسور را از یک نوع به نوع دیگر بدون کپی کردن داده ارسال می کند.
خلاصه
با توجه به input
تانسور، این عملیات تانسوری را برمیگرداند که دادههای بافری مشابه input
با type
داده دارد.
اگر نوع داده ورودی T
بزرگتر از type
داده خروجی باشد، شکل از [...] به [..., sizeof( T
)/sizeof( type
)] تغییر می کند.
اگر T
کوچکتر از type
باشد، عملگر می خواهد که سمت راست ترین بعد برابر با sizeof( type
)/sizeof( T
) باشد. سپس شکل از [..., sizeof( type
)/sizeof( T
)] به [...] می رود.
زمانی که dtype واقعی به عنوان یک dtype پیچیده (مثلا tf.complex64 یا tf.complex128) ریخته می شود، tf.bitcast () و tf.cast () متفاوت عمل می کنند، زیرا tf.cast() قسمت خیالی 0 را می سازد در حالی که tf.bitcast() ماژول را می دهد. خطا به عنوان مثال،
مثال 1:
a = [1., 2., 3.]quality_bitcast = tf.bitcast(a, tf.complex128) Traceback (آخرین تماس اخیر): ... InvalidArgumentError: نمی توان از 1 تا 18 بیتکست کرد [Op: Bitcast ]quality_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)
مثال 3:
x = [1., 2., 3.] y = [0., 2., 3.] برابری= tf.equal(x,y)quality_cast = tf.cast(equality,tf.float32)quality_bitcast = tf. bitcast(equality_cast,tf.uint8) print(equality) tf.Tensor([False 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)
توجه : بیتکست بهعنوان یک بازیگر سطح پایین پیادهسازی میشود، بنابراین ماشینهایی با سفارشهای اندیان متفاوت نتایج متفاوتی خواهند داشت.
استدلال ها:
برمیگرداند:
صفات عمومی
عملیات
Operation operation
خروجی
::tensorflow::Output output
توابع عمومی
بیت کست
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 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-26 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-26 بهوقت ساعت هماهنگ جهانی."],[],[],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\na = \\[1., 2., 3.\\] equality_bitcast = tf.bitcast(a, tf.complex128) Traceback (most recent call last): ... InvalidArgumentError: Cannot bitcast from 1 to 18 \\[Op:[Bitcast](/versions/r2.1/api_docs/cc/class/tensorflow/ops/bitcast#classtensorflow_1_1ops_1_1_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)\n\nExample 2:\n\ntf.bitcast(tf.constant(0xffffffff, dtype=tf.uint32), tf.uint8)\n\nExample 3:\n\nx = \\[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)\n\n*NOTE* : [Bitcast](/versions/r2.1/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.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.1/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.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.1/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.1/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_bitcast_1a4b3a50f16d6247d11bfe2d42f5a438fd) | `::`[tensorflow::Output](/versions/r2.1/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```"]]