# ANeuralNetworksOperandType

[ANeuralNetworksOperandType](https://developer.android.com/ndk/reference/struct/a-neural-networks-operand-type#struct_a_neural_networks_operand_type) describes the type of an operand.

## Summary

This structure is used to describe both scalars and tensors.

A tensor operand type with all dimensions specified is "fully
specified". Whenever possible (i.e., whenever the dimensions are known at model construction time), a tensor operand type should be (but is not required to be) fully specified, in order to enable the best possible performance.

If a tensor operand's type is not fully specified, the dimensions of the operand are deduced from the operand types and values of the operation for which that operand is an output or from the corresponding [ANEURALNETWORKS_IF](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ggaabbe492c60331b13038e39d4207940e0ad9eb50679d1077710a6a4b3eb5207218) or [ANEURALNETWORKS_WHILE](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ggaabbe492c60331b13038e39d4207940e0afdc0927832c42f93845fd9a2361b35f9) operation input operand type in the case of referenced model input operands.

In the following situations, a tensor operand type must be fully specified:

- The operand has a constant value, set by [ANeuralNetworksModel_setOperandValue](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ga92fd1d7bdf40364620d72fdaaca991f3) (with a non-nullptr buffer) or [ANeuralNetworksModel_setOperandValueFromMemory](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ga0a1bcce272ba5ddfaa3c06a53ac7a6ec).
- The operand is a model input (see [ANeuralNetworksModel_identifyInputsAndOutputs](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gacef56268ac6e5e80fa0b4714f57772ce)) of the main model within a compilation. A fully specified tensor operand type must either be provided to [ANeuralNetworksModel_addOperand](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gabe3ab450ff498af8b3b4b88d5e256a36); or it must be provided to the corresponding [ANeuralNetworksExecution_setInput](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gac67f2c8f1ea2136d57bc871da2e6982f), or [ANeuralNetworksExecution_setInputFromMemory](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ga33a63f2ee1b1b17304f76ef8376af224). EXCEPTION: If the input is optional and omitted (by passing nullptr for buffer to [ANeuralNetworksExecution_setInput](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gac67f2c8f1ea2136d57bc871da2e6982f)) then it need not have a fully specified tensor operand type.
- The operand is a model output (see [ANeuralNetworksModel_identifyInputsAndOutputs](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gacef56268ac6e5e80fa0b4714f57772ce)) of the main model within a compilation and is to be used with [ANeuralNetworksExecution_startComputeWithDependencies](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ga371f25c6c44c05f8d267bb6f27ceeb3a). A fully specified tensor operand type must either be provided to [ANeuralNetworksModel_addOperand](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gabe3ab450ff498af8b3b4b88d5e256a36); or it must be provided to the corresponding [ANeuralNetworksExecution_setOutput](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ga7c25ad87c553d207efb257d09e62801e), or [ANeuralNetworksExecution_setOutputFromMemory](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gafcd74c997781e196e081f19108e2c441).

<br />

A tensor operand type of specified rank but some number of unspecified dimensions is represented by setting dimensionCount to the rank and each unspecified dimension to 0.

Available since NNAPI feature level 1.

Starting at NNAPI feature level 3, a tensor operand type of unspecified rank is represented by setting dimensionCount to 0 and dimensions to NULL (just as if it were a scalar operand type).

| ### Public attributes ||
|---|---|
| `https://developer.android.com/ndk/reference/struct/a-neural-networks-operand-type#struct_a_neural_networks_operand_type_1a8e9b0f8229777661e6005b9d1847f026` | `uint32_t` The number of dimensions (rank). |
| `https://developer.android.com/ndk/reference/struct/a-neural-networks-operand-type#struct_a_neural_networks_operand_type_1a6d70bf7a7ea5d2e61e674cf7b3393548` | `const uint32_t *` The dimensions of the tensor. |
| `https://developer.android.com/ndk/reference/struct/a-neural-networks-operand-type#struct_a_neural_networks_operand_type_1aee95637670d7b7179b28a9d5a22f621a` | `float` The quantization scale. |
| `https://developer.android.com/ndk/reference/struct/a-neural-networks-operand-type#struct_a_neural_networks_operand_type_1aebe0bf8514de064d1d68e8857a3dccfd` | `int32_t` The data type, e.g ANEURALNETWORKS_FLOAT32. |
| `https://developer.android.com/ndk/reference/struct/a-neural-networks-operand-type#struct_a_neural_networks_operand_type_1ad7e11ae6e4a5c0e338cfe5c9a1e9dbe8` | `int32_t` The quantization zero point. |

## Public attributes

### dimensionCount

Declared in `android/NeuralNetworksTypes.h`

```scdoc
uint32_t ANeuralNetworksOperandType::dimensionCount
```
The number of dimensions (rank).

Must be 0 for scalars.

### dimensions

Declared in `android/NeuralNetworksTypes.h`

```gdscript
const uint32_t * ANeuralNetworksOperandType::dimensions
```
The dimensions of the tensor.

Must be nullptr for scalars.

### scale

Declared in `android/NeuralNetworksTypes.h`

```text
float ANeuralNetworksOperandType::scale
```
The quantization scale.

Must be 0 when not applicable to an operand type.

See [OperandCode](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gaf06d1affd33f3bc698d0c04eceb23298).

### type

Declared in `android/NeuralNetworksTypes.h`

```carbon
int32_t ANeuralNetworksOperandType::type
```
The data type, e.g ANEURALNETWORKS_FLOAT32.

### zeroPoint

Declared in `android/NeuralNetworksTypes.h`

```scdoc
int32_t ANeuralNetworksOperandType::zeroPoint
```
The quantization zero point.

Must be 0 when not applicable to an operand type.

See [OperandCode](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1gaf06d1affd33f3bc698d0c04eceb23298).