Tensor represents a single multi-dimensional array of data.
More...
#include <tensor.h>
Tensor represents a single multi-dimensional array of data.
At construction time, the dataType of the Tensor is undetermined, and memory to store its data is not allocated. The dataType is set by a call to Tensor::allocateStorage() or Tensor::fillData<T>, where T is the type of the incoming data. Afterwards, the underlying data array can be accessed with Tensor::data<T> (which will check that T matches the expected data type and assert-fail if not) and indexed using TensorIndexIterator.
Definition at line 344 of file tensor.h.
|
| Tensor (const std::string &_name, const TensorShape &_shape) |
| Construct a Tensor with the given name and shape.
|
|
| Tensor (const TensorProto &tensorProto, const TensorData &tensorData) |
| Constructs a Tensor from serialized protobufs. More...
|
|
TensorIndexIterator | startIndex () const |
| Returns an iterator starting at the beginning of the Tensor.
|
|
virtual bool | containsData () const |
|
template<typename T > |
void | fillData (T *externalData, int size) |
| Fills the Tensor with externalData. More...
|
|
template<typename T > |
void | fillData (std::initializer_list< T > externalData) |
| Fills the Tensor byte-by-byte from the given initializer list.
|
|
template<typename T > |
void | fillData (const google::protobuf::RepeatedField< T > &externalData) |
| Fills the Tensor byte-by-byte from a protobuf repeated field.
|
|
void | fillHalfData (const google::protobuf::RepeatedField< int > &externalData) |
| Fill the tensor with float16 data. More...
|
|
template<typename T > |
T * | allocateStorage () |
| Allocates memory to store Tensor data. More...
|
|
void | allocateStorage (DataType _dataType) |
| Allocates memory to store Tensor data. More...
|
|
TensorProto * | asTensorProto () |
| Serializes this Tensor to a TensorProto.
|
|
template<typename T > |
const T * | data () const |
| Returns a const pointer to the Tensor data.
|
|
template<typename T > |
T * | data () |
| Returns a non-const pointer to the Tensor data.
|
|
| TensorBase (const std::string &_name, const TensorShape &_shape) |
|
| TensorBase (const TensorProto &tensorProto) |
|
std::string | getName () const |
|
const TensorShape & | getShape () const |
|
int | ndims () const |
|
int | dim (int index) const |
|
int | getTotalDim (int index) const |
|
int | getDataStorageFormat () const |
|
DataType | getDataType () const |
|
int | getDataTypeSize () const |
|
bool | isDead () const |
|
void | setDead (bool _dead=true) |
|
|
std::ostream & | operator<< (std::ostream &os, const Tensor &tensor) |
| Prints the contents of the Tensor to the given ostream.
|
|
◆ Tensor()
smaug::Tensor::Tensor |
( |
const TensorProto & |
tensorProto, |
|
|
const TensorData & |
tensorData |
|
) |
| |
|
inline |
Constructs a Tensor from serialized protobufs.
- Parameters
-
tensorProto | Basic parameters of the Tensor. |
tensorData | The data contents of the Tensor. |
Definition at line 359 of file tensor.h.
◆ allocateStorage() [1/2]
template<typename T >
T* smaug::Tensor::allocateStorage |
( |
| ) |
|
|
inline |
Allocates memory to store Tensor data.
- Template Parameters
-
T | The type of data to store. |
Definition at line 473 of file tensor.h.
◆ allocateStorage() [2/2]
void smaug::Tensor::allocateStorage |
( |
DataType |
_dataType | ) |
|
|
inline |
Allocates memory to store Tensor data.
- Parameters
-
_dataType | The type of data to store. |
Definition at line 489 of file tensor.h.
◆ fillData()
template<typename T >
void smaug::Tensor::fillData |
( |
T * |
externalData, |
|
|
int |
size |
|
) |
| |
|
inline |
Fills the Tensor with externalData.
The contents of externalData are copied over byte by byte, without regard for padding zones.
Definition at line 400 of file tensor.h.
◆ fillHalfData()
void smaug::Tensor::fillHalfData |
( |
const google::protobuf::RepeatedField< int > & |
externalData | ) |
|
|
inline |
Fill the tensor with float16 data.
This special overload is required because the data stored in TensorProto packs two float16 into one int32.
Definition at line 452 of file tensor.h.
The documentation for this class was generated from the following files: