tensorflow ::テンソル
#include <tensor.h>
値のn次元配列を表します。
概要
コンストラクタとデストラクタ | |
---|---|
Tensor () 1次元、0要素のフロートテンソルを作成します。 | |
Tensor (DataType type, const TensorShape & shape) | |
Tensor (Allocator *a, DataType type, const TensorShape & shape) アロケータ a を使用して基になるバッファを割り当てることにより、入力type とshape でテンソルを作成します。 | |
Tensor (Allocator *a, DataType type, const TensorShape & shape, const AllocationAttributes & allocation_attr) アロケータ a と指定された「allocation_attr」を使用して基になるバッファを割り当てることにより、入力type とshape でテンソルを作成します。 | |
Tensor (DataType type, const TensorShape & shape, TensorBuffer *buf) 入力データ型、形状、およびbufを使用してテンソルを作成します。 | |
Tensor (DataType type) 指定されたデータ型の空のテンソルを作成します。 | |
Tensor (float scalar_value) | |
Tensor (double scalar_value) | |
Tensor (int32 scalar_value) | |
Tensor (uint32 scalar_value) | |
Tensor (uint16 scalar_value) | |
Tensor (uint8 scalar_value) | |
Tensor (int16 scalar_value) | |
Tensor (int8 scalar_value) | |
Tensor (tstring scalar_value) | |
Tensor (complex64 scalar_value) | |
Tensor (complex128 scalar_value) | |
Tensor (int64 scalar_value) | |
Tensor (uint64 scalar_value) | |
Tensor (bool scalar_value) | |
Tensor (qint8 scalar_value) | |
Tensor (quint8 scalar_value) | |
Tensor (qint16 scalar_value) | |
Tensor (quint16 scalar_value) | |
Tensor (qint32 scalar_value) | |
Tensor (bfloat16 scalar_value) | |
Tensor (Eigen::half scalar_value) | |
Tensor (ResourceHandle scalar_value) | |
Tensor (const char *scalar_value) | |
Tensor (const Tensor & other) コンストラクターをコピーします。 | |
Tensor ( Tensor && other) コンストラクターを移動します。 | |
~Tensor () |
パブリックファンクション | |
---|---|
AllocatedBytes () const | size_t |
AsProtoField (TensorProto *proto) const | void *this テンソルのコンテンツをproto に入力します。 |
AsProtoTensorContent (TensorProto *proto) const | void |
BitcastFrom (const Tensor & other, DataType dtype, const TensorShape & shape) | Status 他のテンソルをこのテンソルにコピーし、形状を変更して、バッファーのデータ型を再解釈します。 |
CopyFrom (const Tensor & other, const TensorShape & shape) TF_MUST_USE_RESULT | bool 他のテンソルをこのテンソルにコピーして、形状を変更します。 |
DebugString (int num_values) const | string デバッグに適したテンソルの人間が読める形式の要約。 |
DebugString () const | string |
DeviceSafeDebugString () const | string |
FillDescription (TensorDescription *description) const | void TensorDescription プロトに、監視とデバッグに役立つテンソルに関するメタデータを入力します。 |
FromProto (const TensorProto & other) TF_MUST_USE_RESULT | bool other を解析し、テンソルを構築します。 |
FromProto (Allocator *a, const TensorProto & other) TF_MUST_USE_RESULT | bool |
IsAligned () const | bool このテンソルが整列している場合はtrueを返します。 |
IsInitialized () const | bool 必要に応じて、このTensorは初期化されていますか? |
IsSameSize (const Tensor & b) const | bool |
NumElements () const | int64 テンソル形状の便利なアクセサ。 |
RefCountIsOne () const | bool |
SharesBufferWith (const Tensor & b) const | bool |
Slice (int64 dim0_start, int64 dim0_limit) const | このテンソルを1次元に沿ってスライスします。 |
SubSlice (int64 index) const | このテンソルから1次元に沿ってサブスライスを選択します。 |
SummarizeValue (int64 max_entries, bool print_v2) const | string *this の最初のmax_entries 値を文字列にレンダリングします。 |
TotalBytes () const | size_t このテンソルの推定メモリ使用量を返します。 |
UnsafeCopyFromInternal (const Tensor & other, DataType dtype, const TensorShape & shape) | void BitcastFromと同様ですが、前提条件が満たされない場合、CHECKは失敗します。 |
bit_casted_shaped (gtl::ArraySlice< int64 > new_sizes) | TTypes< T, NDIMS >:: Tensor new_sizesで指定された新しい形状の T Eigen::Tensor にテンソルデータを返し、新しいnew_sizes にキャストします。 |
bit_casted_shaped (gtl::ArraySlice< int64 > new_sizes) const | TTypes< T, NDIMS >::ConstTensor new_sizesで指定された新しい形状の T Eigen::Tensor にテンソルデータを返し、新しいnew_sizes にキャストします。 |
bit_casted_tensor () | TTypes< T, NDIMS >:: Tensor テンソルデータを、同じサイズでビット単位で指定されたdtypeTにキャストされた T Eigen::Tensor に返します。 |
bit_casted_tensor () const | TTypes< T, NDIMS >::ConstTensor テンソルデータを、同じサイズでビット単位で指定されたdtypeTにキャストされた T Eigen::Tensor に返します。 |
data () const | void * |
dim_size (int d) const | int64 テンソル形状の便利なアクセサ。 |
dims () const | int テンソル形状の便利なアクセサ。 |
dtype () const | DataType データ型を返します。 |
flat () | TTypes< T >::Flat テンソルデータを、データ型と指定された形状の Eigen::Tensor として返します。 |
flat () const | TTypes< T >::ConstFlat |
flat_inner_dims () | TTypes< T, NDIMS >:: Tensor データをNDIMSディメンションを持つEigen::Tensorとして返し、最後のNDIMS-1を除くすべてのTensorディメンションを結果の最初のディメンションに折りたたみます。 |
flat_inner_dims () const | TTypes< T, NDIMS >::ConstTensor |
flat_inner_outer_dims (int64 begin) | TTypes< T, NDIMS >:: Tensor |
flat_inner_outer_dims (int64 begin) const | TTypes< T, NDIMS >::ConstTensor |
flat_outer_dims () | TTypes< T, NDIMS >:: Tensor データをNDIMSディメンションを持つEigen::Tensorとして返し、最初のNDIMS-1を除くすべてのTensorディメンションを結果の最後のディメンションに折りたたみます。 |
flat_outer_dims () const | TTypes< T, NDIMS >::ConstTensor |
matrix () | TTypes< T >::Matrix |
matrix () const | TTypes< T >::ConstMatrix |
operator= (const Tensor & other) | Tensor & 演算子を割り当てます。このテンソルは、他の基盤となるストレージを共有します。 |
operator= ( Tensor && other) | Tensor & ムーブ演算子。詳細については、移動コンストラクターを参照してください。 |
reinterpret_last_dimension () | TTypes< T, NDIMS >:: Tensor テンソルデータを Eigen::Tensor に返し、最後の次元要素をより大きなタイプの単一要素に変換します。 |
reinterpret_last_dimension () const | TTypes< T, NDIMS >::ConstTensor テンソルデータを Eigen::Tensor に返し、最後の次元要素をより大きなタイプの単一要素に変換します。 |
scalar () | TTypes< T >::Scalar |
scalar () const | TTypes< T >::ConstScalar |
shape () const | const TensorShape & テンソルの形状を返します。 |
shaped (gtl::ArraySlice< int64 > new_sizes) | TTypes< T, NDIMS >:: Tensor |
shaped (gtl::ArraySlice< int64 > new_sizes) const | TTypes< T, NDIMS >::ConstTensor |
tensor () | TTypes< T, NDIMS >:: Tensor |
tensor () const | TTypes< T, NDIMS >::ConstTensor |
tensor_data () const | StringPiece 現在のテンソルのバッファをマッピングする StringPiece を返します。 |
unaligned_flat () | TTypes< T >::UnalignedFlat |
unaligned_flat () const | TTypes< T >::UnalignedConstFlat |
unaligned_shaped (gtl::ArraySlice< int64 > new_sizes) | TTypes< T, NDIMS >::UnalignedTensor |
unaligned_shaped (gtl::ArraySlice< int64 > new_sizes) const | TTypes< T, NDIMS >::UnalignedConstTensor |
vec () | TTypes< T >::Vec テンソルデータを、この Tensor のタイプとサイズを持つEigen::Tensor として返します。 |
vec () const | TTypes< T >::ConstVec 上記のすべてのメソッドのConstバージョン。 |
パブリックファンクション
AllocatedBytes
size_t AllocatedBytes() const
AsProtoField
void AsProtoField( TensorProto *proto ) const
*this
テンソルのコンテンツをproto
に入力します。
AsProtoField()
はproto.dtype()の繰り返しフィールドにproto.dtype()
し、 AsProtoTensorContent()
はproto.tensor_content()
()のコンテンツをコンパクトな形式でエンコードします。
AsProtoTensorContent
void AsProtoTensorContent( TensorProto *proto ) const
BitcastFrom
Status BitcastFrom( const Tensor & other, DataType dtype, const TensorShape & shape )
他のテンソルをこのテンソルにコピーし、形状を変更して、バッファーのデータ型を再解釈します。
Status :: OK()が返された場合、2つのテンソルは同じ基になるストレージを共有するようになります。
この呼び出しでは、 other
テンソルと指定されたタイプおよび形状が「互換性がある」(つまり、同じバイト数を占める)必要があります。
具体的には:
shape.num_elements()* DataTypeSize(type)
等しくなければならない
other.num_elements()* DataTypeSize(other.dtype())
さらに、この関数には次のものが必要です。
- DataTypeSize(other.dtype())!= 0
- DataTypeSize(type)!= 0
要件のいずれかが満たされていない場合、errors::InvalidArgumentが返されます。
CopyFrom
bool CopyFrom( const Tensor & other, const TensorShape & shape ) TF_MUST_USE_RESULT
他のテンソルをこのテンソルにコピーして、形状を変更します。
このテンソルは、他の基盤となるストレージを共有します。 other.shape()
が指定されたshape
の要素の数と同じである場合にtrue
を返します。
DebugString
string DebugString( int num_values ) const
デバッグに適したテンソルの人間が読める形式の要約。
DebugString
string DebugString() const
DeviceSafeDebugString
string DeviceSafeDebugString() const
FillDescription
void FillDescription( TensorDescription *description ) const
TensorDescription
プロトに、監視とデバッグに役立つテンソルに関するメタデータを入力します。
FromProto
bool FromProto( const TensorProto & other ) TF_MUST_USE_RESULT
other
を解析し、テンソルを構築します。
解析が成功した場合はtrue
を返します。解析が失敗した場合、 *this
の状態は変更されません。
FromProto
bool FromProto( Allocator *a, const TensorProto & other ) TF_MUST_USE_RESULT
IsAligned
bool IsAligned() const
このテンソルが整列している場合はtrueを返します。
IsInitialized
bool IsInitialized() const
必要に応じて、このTensorは初期化されていますか?
ゼロ要素テンソルは、割り当てられたことがなく、メモリが割り当てられていない場合でも、常に初期化されていると見なされます。
IsSameSize
bool IsSameSize( const Tensor & b ) const
NumElements
int64 NumElements() const
テンソル形状の便利なアクセサ。
RefCountIsOne
bool RefCountIsOne() const
SharesBufferWith
bool SharesBufferWith( const Tensor & b ) const
スライス
Tensor Slice( int64 dim0_start, int64 dim0_limit ) const
このテンソルを1次元に沿ってスライスします。
つまり、返されたテンソルはreturned [i、...] == this [dim0_start + i、...]を満たします。返されたテンソルは、基になるテンソルバッファーをこのテンソルと共有します。
注:形状によっては、返されるテンソルがこのテンソルと同じ位置合わせ要件を満たさない場合があります。呼び出し元は、アライメント要件を持つ特定のメソッド( flat()
、 tensor()
など)を呼び出す前に、返されたテンソルのアライメントを確認する必要があります。
注:N次元テンソルを使用すると、このメソッドはN次元のテンソルも返します。サブテンソルを選択する場合は、SubSliceを参照してください。
必要条件:dims dims()
> = 1必要条件: 0 <= dim0_start <= dim0_limit <= dim_size(0)
サブスライス
Tensor SubSlice( int64 index ) const
このテンソルから1次元に沿ってサブスライスを選択します。
N次元テンソルが供給されると、このメソッドはN-1次元のテンソルを返します。ここで、返されるテンソルは、最初の次元に沿った入力テンソルのサブスライスです。返されたテンソルのN-1次元は、入力テンソルの最後のN-1次元です。
注:形状によっては、返されるテンソルがこのテンソルと同じ位置合わせ要件を満たさない場合があります。呼び出し元は、アライメント要件を持つ特定のメソッド( flat()
、 tensor()
など)を呼び出す前に、返されたテンソルのアライメントを確認する必要があります。
必要条件:dims dims()
> = 1必要条件: 0 <= index < dim_size(0)
SummarizeValue
string SummarizeValue( int64 max_entries, bool print_v2 ) const
*this
の最初のmax_entries
値を文字列にレンダリングします。
テンソル
Tensor()
1次元、0要素のフロートテンソルを作成します。
返されるテンソルはスカラー(形状{})ではなく、代わりに空の1次元テンソル(形状{0}、 NumElements() == 0)です。要素がないため、値を割り当てる必要はなく、デフォルトで初期化されます( IsInitialized()はtrueです)。これが望ましくない場合は、初期化が必要な1要素のスカラーを作成することを検討してください。
Tensor(DT_FLOAT, TensorShape({}))
Tensor
Tensor( DataType type, const TensorShape & shape )
テンソル
Tensor( Allocator *a, DataType type, const TensorShape & shape )
テンソル
Tensor( Allocator *a, DataType type, const TensorShape & shape, const AllocationAttributes & allocation_attr )
アロケータa
と指定された「allocation_attr」を使用して基になるバッファを割り当てることにより、入力type
とshape
でテンソルを作成します。
カーネルとステップがわかっている場合は、allocation_attr.allocation_will_be_loggedをtrueに設定し、テンソルの構築後にLogMemory::RecordTensorAllocationを呼び出す必要があります。 Op内からTensorコンストラクターを直接呼び出すことは非推奨です。OpKernelConstruction/OpKernelContextallocate_*メソッドを使用して、カーネルとステップを記録する新しいテンソルを割り当てます。
このTensorの寿命よりも長生きa
必要があります。
テンソル
Tensor( DataType type, const TensorShape & shape, TensorBuffer *buf )
入力データ型、形状、およびbufを使用してテンソルを作成します。
このTensorに属するbufのrefを取得します。
テンソル
Tensor( DataType type )
指定されたデータ型の空のテンソルを作成します。
Tensor()と同様に、 IsInitialized()がTrueを返す1次元の0要素のTensorを返します。詳細については、 Tensor()のドキュメントを参照してください。
テンソル
Tensor( float scalar_value )
テンソル
Tensor( double scalar_value )
テンソル
Tensor( int32 scalar_value )
テンソル
Tensor( uint32 scalar_value )
テンソル
Tensor( uint16 scalar_value )
テンソル
Tensor( uint8 scalar_value )
テンソル
Tensor( int16 scalar_value )
テンソル
Tensor( int8 scalar_value )
テンソル
Tensor( tstring scalar_value )
テンソル
Tensor( complex64 scalar_value )
テンソル
Tensor( complex128 scalar_value )
テンソル
Tensor( int64 scalar_value )
テンソル
Tensor( uint64 scalar_value )
テンソル
Tensor( bool scalar_value )
テンソル
Tensor( qint8 scalar_value )
テンソル
Tensor( quint8 scalar_value )
テンソル
Tensor( qint16 scalar_value )
テンソル
Tensor( quint16 scalar_value )
テンソル
Tensor( qint32 scalar_value )
テンソル
Tensor( bfloat16 scalar_value )
テンソル
Tensor( Eigen::half scalar_value )
テンソル
Tensor( ResourceHandle scalar_value )
テンソル
Tensor( const char *scalar_value )
TotalBytes
size_t TotalBytes() const
このテンソルの推定メモリ使用量を返します。
UnsafeCopyFromInternal
void UnsafeCopyFromInternal( const Tensor & other, DataType dtype, const TensorShape & shape )
BitcastFromと同様ですが、前提条件が満たされない場合、CHECKは失敗します。
非推奨。代わりにBitcastFromを使用して、返されたステータスを確認してください。
bit_casted_shape
TTypes< T, NDIMS >::Tensor bit_casted_shaped( gtl::ArraySlice< int64 > new_sizes )
new_sizesで指定された新しい形状のT
Eigen::Tensor
にテンソルデータを返し、新しいnew_sizes
にキャストします。
ビットキャストの使用は、移動およびコピー操作に役立ちます。許可されるビットキャストは、 shaped()
との唯一の違いです。
bit_casted_shape
TTypes< T, NDIMS >::ConstTensor bit_casted_shaped( gtl::ArraySlice< int64 > new_sizes ) const
new_sizesで指定された新しい形状のT
Eigen::Tensor
にテンソルデータを返し、新しいnew_sizes
にキャストします。
ビットキャストの使用は、移動およびコピー操作に役立ちます。許可されるビットキャストは、 shaped()
との唯一の違いです。
bit_casted_tensor
TTypes< T, NDIMS >::Tensor bit_casted_tensor()
テンソルデータを、同じサイズでビット単位で指定されたdtypeTにキャストされたT
Eigen::Tensor
に返します。
ビットキャストの使用は、移動およびコピー操作に役立ちます。注:これは、ビットキャストが許可されていることを除いて、 tensor()
と同じです。
bit_casted_tensor
TTypes< T, NDIMS >::ConstTensor bit_casted_tensor() const
テンソルデータを、同じサイズでビット単位で指定されたdtypeTにキャストされたT
Eigen::Tensor
に返します。
ビットキャストの使用は、移動およびコピー操作に役立ちます。注:これは、ビットキャストが許可されていることを除いて、 tensor()
と同じです。
データ
void * data() const
dim_size
int64 dim_size( int d ) const
テンソル形状の便利なアクセサ。
薄暗い
int dims() const
テンソル形状の便利なアクセサ。
すべてのシェイプアクセサについては、 tensor_shape.h
のTensorShape
の関連メソッドに関するコメントを参照してください。
dtype
DataType dtype() const
データ型を返します。
平らな
TTypes< T >::Flat flat()
テンソルデータを、データ型と指定された形状のEigen::Tensor
として返します。
これらのメソッドを使用すると、選択したサイズとサイズでデータにアクセスできます。それらを呼び出すためにテンソルの次元数を知る必要はありません。ただし、タイプが一致し、要求されたディメンションがテンソルと同じ数の要素を持つCHECK
Eigen::Tensor
を作成することを確認します。
例:
typedef float T; Tensor my_ten(...built with Shape{planes: 4, rows: 3, cols: 5}...); // 1D Eigen::Tensor, size 60: auto flat = my_ten.flat(); // 2D Eigen::Tensor 12 x 5: auto inner = my_ten.flat_inner_dims (); // 2D Eigen::Tensor 4 x 15: auto outer = my_ten.shaped ({4, 15}); // CHECK fails, bad num elements: auto outer = my_ten.shaped ({4, 8}); // 3D Eigen::Tensor 6 x 5 x 2: auto weird = my_ten.shaped ({6, 5, 2}); // CHECK fails, type mismatch: auto bad = my_ten.flat ();
flat
TTypes< T >::ConstFlat flat() const
flat_inner_dims
TTypes< T, NDIMS >::Tensor flat_inner_dims()
flat_inner_dims
TTypes< T, NDIMS >::ConstTensor flat_inner_dims() const
flat_inner_outer_dims
TTypes< T, NDIMS >::Tensor flat_inner_outer_dims( int64 begin )
flat_inner_outer_dims
TTypes< T, NDIMS >::ConstTensor flat_inner_outer_dims( int64 begin ) const
flat_outer_dims
TTypes< T, NDIMS >::Tensor flat_outer_dims()
flat_outer_dims
TTypes< T, NDIMS >::ConstTensor flat_outer_dims() const
マトリックス
TTypes< T >::Matrix matrix()
マトリックス
TTypes< T >::ConstMatrix matrix() const
reinterpret_last_dimension
TTypes< T, NDIMS >::Tensor reinterpret_last_dimension()
テンソルデータをEigen::Tensor
に返し、最後の次元要素をより大きなタイプの単一要素に変換します。
たとえば、これはNCHW_VECT_Cint8テンソルをNCHWint32テンソルとして扱うことができるカーネルに役立ちます。 sizeof(T)は、元の要素タイプのサイズ*元の最後の次元のnum要素と同じである必要があります。 NDIMSは、元の次元数より1少ない数である必要があります。
reinterpret_last_dimension
TTypes< T, NDIMS >::ConstTensor reinterpret_last_dimension() const
テンソルデータをEigen::Tensor
に返し、最後の次元要素をより大きなタイプの単一要素に変換します。
たとえば、これはNCHW_VECT_Cint8テンソルをNCHWint32テンソルとして扱うことができるカーネルに役立ちます。 sizeof(T)は、元の要素タイプのサイズ*元の最後の次元のnum要素と同じである必要があります。 NDIMSは、元の次元数より1少ない数である必要があります。
スカラー
TTypes< T >::Scalar scalar()
スカラー
TTypes< T >::ConstScalar scalar() const
形
const TensorShape & shape() const
テンソルの形状を返します。
形
TTypes< T, NDIMS >::Tensor shaped( gtl::ArraySlice< int64 > new_sizes )
形
TTypes< T, NDIMS >::ConstTensor shaped( gtl::ArraySlice< int64 > new_sizes ) const
テンソル
TTypes< T, NDIMS >::Tensor tensor()
テンソル
TTypes< T, NDIMS >::ConstTensor tensor() const
tensor_data
StringPiece tensor_data() const
現在のテンソルのバッファをマッピングするStringPiece
を返します。
返されたStringPiece
は、CPUが直接アドレス指定できないデバイス上のメモリ位置を指している可能性があります。
注:基になるテンソルバッファーは再カウントされるため、 StringPiece
によってマップされたコンテンツの有効期間はバッファーの有効期間と一致します。呼び出し元は、 StringPiece
がまだ使用されている間、バッファーが破棄されないように調整する必要があります。
必要条件: DataTypeCanUseMemcpy(dtype())
。
unaligned_flat
TTypes< T >::UnalignedFlat unaligned_flat()
unaligned_flat
TTypes< T >::UnalignedConstFlat unaligned_flat() const
unaligned_shape
TTypes< T, NDIMS >::UnalignedTensor unaligned_shaped( gtl::ArraySlice< int64 > new_sizes )
unaligned_shape
l10n-placeholder89vec
l10n-placeholder90テンソルデータを、このテンソルのタイプとサイズを持つEigen::Tensorとして返します。
これらのメソッドは、Tensorのデータ型と次元数がわかっていて、Eigen::TensorがTensorサイズに自動的にサイズ変更されるようにする場合に使用します。タイプまたはサイズのいずれかが一致しない場合、実装チェックは失敗します。
例:
l10n-placeholder91
l10n-placeholder92
上記のすべてのメソッドのConstバージョン。
〜テンソル
l10n-placeholder93Except 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.