# helia_aot.air.utils

## helia_aot.air.utils.quantize_multiplier

`function` · `python`

```python
quantize_multiplier(real_multiplier: float) -> tuple[int, int]
```

Convert a floating point multiplier into a fixed-point multiplier and shift.

Given a real multiplier, this function computes a pair (quantized_multiplier, shift)
such that the fixed-point multiplication approximates the real multiplier:

    real_multiplier ~ quantized_multiplier / (2^(31 - shift))

This is typically used in quantized inference to convert floating-point scaling
factors to fixed-point representation.

The CMSIS-NN ``arm_nn_divide_by_power_of_two`` function only supports
exponent values in [0, 31], so the resulting shift is clamped to [-31, 30].
When the real multiplier is so small that the shift would fall below -31
the contribution is negligible and the multiplier is flushed to zero.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| real_multiplier | float | Required | The floating-point multiplier. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
| tuple | tuple[int, int] | (quantized_multiplier, shift) |

Source: `helia_aot/air/utils.py:8`

## helia_aot.air.utils.compute_fused_activation_range

`function` · `python`

```python
compute_fused_activation_range(
    activation_function: AirActivationType,
    output_zero_point: int = 0,
    output_scale: float = 1.0,
    qmin: int = -128,
    qmax: int = 127,
) -> tuple[int, int]
```

Compute the activation min and max values based on the fused activation function.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| activation_function | litert.ActivationFunctionType | Required | The activation function type. |
| output_zero_point | int | 0 | The zero point for the output tensor. Defaults to 0. |
| output_scale | float | 1.0 | The scale for the output tensor. Defaults to 1.0. |
| qmin | int | -128 | Minimum quantized value. Defaults to -128. |
| qmax | int | 127 | Maximum quantized value. Defaults to 127. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | tuple[int, int] | tuple[int, int]: The activation min and max values. |

Source: `helia_aot/air/utils.py:68`

## helia_aot.air.utils.compute_padding_with_offset

`function` · `python`

```python
compute_padding_with_offset(
    in_size: int,
    filter_size: int,
    stride: int,
    dilation_rate: int = 1,
    padding_type: int = AirPaddingType.SAME,
) -> tuple[int, int]
```

Computes a single padding value (top/left) for one dimension with offset.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| in_size | int | Required | Input dimension (height or width). |
| filter_size | int | Required | Kernel dimension (height or width). |
| stride | int | Required | Stride for that dimension. |
| dilation_rate | int | 1 | Dilation rate for that dimension (default is 1). |
| padding_type | int | AirPaddingType.SAME | 0 for SAME padding, 1 for VALID padding (default is SAME). |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
| int | tuple[int, int] | The computed top or left padding value. |

Source: `helia_aot/air/utils.py:111`

## helia_aot.air.utils.compute_padding

`function` · `python`

```python
compute_padding(
    in_size: int,
    filter_size: int,
    stride: int,
    dilation_rate: int = 1,
    padding_type: int = AirPaddingType.SAME,
) -> int
```

Computes a single padding value (top/left) for one dimension.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| in_size | int | Required | Input dimension (height or width). |
| filter_size | int | Required | Kernel dimension (height or width). |
| stride | int | Required | Stride for that dimension. |
| dilation_rate | int | 1 | Dilation rate for that dimension (default is 1). |
| padding_type | int | AirPaddingType.SAME | 0 for SAME padding, 1 for VALID padding (default is SAME). |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
| int | int | The computed top or left padding value. |

Source: `helia_aot/air/utils.py:140`

## helia_aot.air.utils.reduce_multiplier_q31_to_q15

`function` · `python`

```python
reduce_multiplier_q31_to_q15(multiplier: int) -> int
```

Reduce a multiplier value for int16 quantization.

Certain CMSIS functions for int16 quantized models require the
multiplier to be reduced from Q31 format to Q15 format. This function
performs that reduction.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| multiplier | int | Required | The original multiplier value. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
| int | int | The reduced multiplier value. |

Source: `helia_aot/air/utils.py:185`
