# TfLiteTensor


`#include <common.h>`

A tensor in the interpreter system which is a wrapper around a buffer of data including a dimensionality (or NULL if not currently defined).

## Summary

| ### Public attributes ||
|---|---|
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1ab5dcd15fd342f9365a599b37e7e5ee18` | `const void *` An opaque pointer to a tflite::MMapAllocation. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a4b21e89c9d432fcde19e5cecdcd18acf` | `TfLiteAllocationType` How memory is mapped kTfLiteMmapRo: Memory mapped read only. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a784b0cd1be5d43ea2292e75f6a15c11b` | `TfLiteBufferHandle` An integer buffer handle that can be handled by `delegate`. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a65082739eecbd6d52d7d339d43b87606` | `size_t` The number of bytes required to store the data of this Tensor. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a31678fd0752ef9e3b3debb11e7956fb0` | `https://developers.google.com/edge/api/tflite/c/union/tf-lite-ptr-union#union_tf_lite_ptr_union` A union of data pointers. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1abbb1c8fb4b382e3ffa1aec69f9a04619` | `bool` If the delegate uses its own buffer (e.g. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a9491f4d29e4e8423cdc1861ac2a4eb74` | `struct https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate *` The delegate which knows how to handle `buffer_handle`. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a9826437410d81b21035c89847d526c81` | `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-int-array#struct_tf_lite_int_array *` A pointer to a structure representing the dimensionality interpretation that the buffer should have. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1ace0611c9e0f0683e5075e4b2768d96b8` | `const https://developers.google.com/edge/api/tflite/c/struct/tf-lite-int-array#struct_tf_lite_int_array *` Optional. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a39290cf2770c0eebc8bd63faf12dac2f` | `bool` True if the tensor is a variable. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1adb13df6dd8e7223f9b3abf318a034209` | `const char *` Null-terminated name of this tensor. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1ad0fbad4e97f0be0a6e4bfa1b2be0e3fe` | `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-quantization-params#struct_tf_lite_quantization_params` Quantization information. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1aa4efa609d9ad9c78c5f53a592020de9e` | `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-quantization#struct_tf_lite_quantization` Quantization information. Replaces params field above. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a40010fa2bfbebd59bf060459d95b65c6` | `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-sparsity#struct_tf_lite_sparsity *` Parameters used to encode a sparse tensor. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-tensor#struct_tf_lite_tensor_1a24d579d439274a598ce79f0ec6bf6f50` | `TfLiteType` The data type specification for data stored in `data`. |

## Public attributes

### allocation

```
const void * TfLiteTensor::allocation
```
An opaque pointer to a tflite::MMapAllocation.

### allocation_type

```
TfLiteAllocationType TfLiteTensor::allocation_type
```
How memory is mapped kTfLiteMmapRo: Memory mapped read only.

i.e. weights kTfLiteArenaRw: Arena allocated read write memory (i.e. temporaries, outputs).

### buffer_handle

```
TfLiteBufferHandle TfLiteTensor::buffer_handle
```
An integer buffer handle that can be handled by `delegate`.

The value is valid only when delegate is not null.

WARNING: This is an experimental interface that is subject to change.

### bytes

```
size_t TfLiteTensor::bytes
```
The number of bytes required to store the data of this Tensor.

I.e. (bytes of each element) \* dims\[0\] \* ... \* dims\[n-1\]. For example, if type is kTfLiteFloat32 and dims = {3, 2} then bytes = sizeof(float) \* 3 \* 2 = 4 \* 3 \* 2 = 24.

### data

```
TfLitePtrUnion TfLiteTensor::data
```
A union of data pointers.

The appropriate type should be used for a typed tensor based on `type`.

### data_is_stale

```
bool TfLiteTensor::data_is_stale
```
If the delegate uses its own buffer (e.g.

GPU memory), the delegate is responsible to set data_is_stale to true. `delegate->CopyFromBufferHandle` can be called to copy the data from delegate buffer.

WARNING: This is an experimental interface that is subject to change.

### delegate

```
struct TfLiteDelegate * TfLiteTensor::delegate
```
The delegate which knows how to handle `buffer_handle`.

WARNING: This is an experimental interface that is subject to change.

### dims

```
TfLiteIntArray * TfLiteTensor::dims
```
A pointer to a structure representing the dimensionality interpretation that the buffer should have.

NOTE: the product of elements of `dims` and the element datatype size should be equal to `bytes` below.

### dims_signature

```
const TfLiteIntArray * TfLiteTensor::dims_signature
```
Optional.

Encodes shapes with unknown dimensions with -1. This field is only populated when unknown dimensions exist in a read-write tensor (i.e. an input or output tensor). (e.g. `dims` contains \[1, 1, 1, 3\] and `dims_signature` contains \[1, -1, -1, 3\]). If no unknown dimensions exist then `dims_signature` is either null, or set to an empty array. Use `TfLiteTensorGetDimsSignature` to get `dims_signature` if non-empty or otherwise fallback to `dims`. Note that this field only exists when TF_LITE_STATIC_MEMORY is not defined.

### is_variable

```
bool TfLiteTensor::is_variable
```
True if the tensor is a variable.

### name

```
const char * TfLiteTensor::name
```
Null-terminated name of this tensor.

### params

```
TfLiteQuantizationParams TfLiteTensor::params
```
Quantization information.

### quantization

```
TfLiteQuantization TfLiteTensor::quantization
```
Quantization information. Replaces params field above.

### sparsity

```
TfLiteSparsity * TfLiteTensor::sparsity
```
Parameters used to encode a sparse tensor.

This is optional. The field is NULL if a tensor is dense.

WARNING: This is an experimental interface that is subject to change.

### type

```
TfLiteType TfLiteTensor::type
```
The data type specification for data stored in `data`.

This affects what member of `data` union should be used.