tensorflow:: ops:: 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)

注:ビットキャストは低レベルのキャストとして実装されているため、エンディアン順序が異なるマシンでは結果が異なります。

議論:

返品:

  • Output :出力テンソル。

コンストラクターとデストラクタ

Bitcast (const :: tensorflow::Scope & scope, :: tensorflow::Input input, DataType type)

公開属性

operation
output

公的機能

node () const
::tensorflow::Node *
operator::tensorflow::Input () const
operator::tensorflow::Output () const

公開属性

手術

Operation operation

出力

::tensorflow::Output output

公的機能

ビットキャスト

 Bitcast(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  DataType type
)

ノード

::tensorflow::Node * node() const 

operator::tensorflow::Input

 operator::tensorflow::Input() const 

operator::tensorflow::Output

 operator::tensorflow::Output() const