| AIfES 2 2.0.0

aimath_q31.h
Go to the documentation of this file.
1
87 #ifndef AIMATH_Q31
88 #define AIMATH_Q31
89
90 #include "core/aifes_math.h"
91 #include "basic/base/aimath/aimath_basic.h"
92
99 #define AITENSOR_2D_Q31(shape, params, data) {aiq31, 2, shape, params, data}
100
101
113 #define Q31_TO_FLOAT(Q, S, Z) ((float) ((int64_t)(Q) - (int64_t)(Z)) / (float) ((int64_t) 1ULL << (S)))
114
125 #define FLOAT_TO_Q31(F, S, Z) ((int32_t) ((int64_t)((F) * (1ULL << (S)) + ((F) >= 0 ? 0.5f : -0.5f)) + (int64_t)(Z)))
126
142 #define AISCALAR_Q31(F, S, Z) {FLOAT_TO_Q31(F, S, Z), S, Z}
143
144 typedef struct aimath_q31_params aimath_q31_params_t;
145 typedef struct aiscalar_q31 aiscalar_q31_t;
146
149 struct aimath_q31_params {
150 uint16_t shift;
151 int32_t zero_point;
152 };
153
156 struct aiscalar_q31 {
157 int32_t value;
158 uint16_t shift;
159 int32_t zero_point;
160 };
161
172 void aimath_q31_print_aitensor(const aitensor_t *tensor);
173
184 void aimath_q31_print_aiscalar(const void *scalar);
185
195 void aimath_q31_calc_q_params_from_f32(float min_value, float max_value, aimath_q31_params_t *q_params);
196
205 void aimath_q31_quantize_tensor_from_f32(const aitensor_t *tensor_f32, aitensor_t *tensor_q31);
206
211 extern const aimath_dtype_t *aiq31;
212
213 #endif // AIMATH_Q31
aifes_math.h
AIfES 2 math interface.
aimath_basic.h
Basic data-type independent math operations.
aimath_q31_calc_q_params_from_f32
void aimath_q31_calc_q_params_from_f32(float min_value, float max_value, aimath_q31_params_t *q_params)
Calculates the aimath_q31_params parameters.
aimath_q31_print_aitensor
void aimath_q31_print_aitensor(const aitensor_t *tensor)
Printing a Q31 tensor to console.
aimath_q31_print_aiscalar
void aimath_q31_print_aiscalar(const void *scalar)
Printing a Q31 scalar to console.
aimath_q31_quantize_tensor_from_f32
void aimath_q31_quantize_tensor_from_f32(const aitensor_t *tensor_f32, aitensor_t *tensor_q31)
Converts a float f32 tensor into a quantized q31 tensor.
aiq31
const aimath_dtype_t * aiq31
The Q31 data-type indicator.
aimath_dtype
Indicator for the used datatype.
Definition: aifes_math.h:44
aimath_q31_params
Parameters used for the quantized Q31 values, used as property of a tensor.
Definition: aimath_q31.h:149
aimath_q31_params::zero_point
int32_t zero_point
The zero point of the quantization.
Definition: aimath_q31.h:151
aimath_q31_params::shift
uint16_t shift
The scaling factor of the quantization (The total scale is calculated with )
Definition: aimath_q31.h:150
aiscalar_q31
Single quantized Q31 value/scalar.
Definition: aimath_q31.h:156
aiscalar_q31::value
int32_t value
Quantized value .
Definition: aimath_q31.h:157
aiscalar_q31::zero_point
int32_t zero_point
The zero point of the quantization.
Definition: aimath_q31.h:159
aiscalar_q31::shift
uint16_t shift
The scaling factor of the quantization (The total scale is calculated with )
Definition: aimath_q31.h:158
aitensor
A tensor in AIfES.
Definition: aifes_math.h:89