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"
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 
145 typedef struct aiscalar_q31 aiscalar_q31_t;
146 
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 
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 2 math interface.
Basic data-type independent math operations.
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.
void aimath_q31_print_aitensor(const aitensor_t *tensor)
Printing a Q31 tensor to console.
void aimath_q31_print_aiscalar(const void *scalar)
Printing a Q31 scalar to console.
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.
const aimath_dtype_t * aiq31
The Q31 data-type indicator.
Indicator for the used datatype.
Definition: aifes_math.h:44
Parameters used for the quantized Q31 values, used as property of a tensor.
Definition: aimath_q31.h:149
int32_t zero_point
The zero point of the quantization.
Definition: aimath_q31.h:151
uint16_t shift
The scaling factor of the quantization (The total scale is calculated with )
Definition: aimath_q31.h:150
Single quantized Q31 value/scalar.
Definition: aimath_q31.h:156
int32_t value
Quantized value .
Definition: aimath_q31.h:157
int32_t zero_point
The zero point of the quantization.
Definition: aimath_q31.h:159
uint16_t shift
The scaling factor of the quantization (The total scale is calculated with )
Definition: aimath_q31.h:158
A tensor in AIfES.
Definition: aifes_math.h:89