AIfES 2  2.0.0
aimath_q7.h
Go to the documentation of this file.
1 
87 #ifndef AIMATH_Q7
88 #define AIMATH_Q7
89 
90 #include "core/aifes_math.h"
92 
99 #define AITENSOR_2D_Q7(shape, params, data) {aiq7, 2, shape, params, data}
100 
112 #define Q7_TO_FLOAT(Q, S, Z) ((float) ((int16_t)(Q) - (int16_t)(Z)) / (float) (1 << (S)))
113 
124 #define FLOAT_TO_Q7(F, S, Z) ((int8_t) ((int16_t)((F) * (1 << (S)) + ((F) >= 0 ? 0.5f : -0.5f)) + (int16_t)(Z)))
125 
141 #define AISCALAR_Q7(F, S, Z) {FLOAT_TO_Q7(F, S, Z), S, Z}
142 
143 typedef struct aimath_q7_params aimath_q7_params_t;
144 typedef struct aiscalar_q7 aiscalar_q7_t;
145 
149  uint16_t shift;
150  int8_t zero_point;
151 };
152 
155 struct aiscalar_q7 {
156  int8_t value;
157  uint16_t shift;
158  int8_t zero_point;
159 };
160 
172 
183 void aimath_q7_print_aiscalar(const void *scalar);
184 
194 void aimath_q7_calc_q_params_from_f32(float min_value, float max_value, aimath_q7_params_t *q_params);
195 
204 void aimath_q7_quantize_tensor_from_f32(const aitensor_t *tensor_f32, aitensor_t *tensor_q7);
205 
210 extern const aimath_dtype_t *aiq7;
211 
212 #endif // AIMATH_Q7
AIfES 2 math interface.
Basic data-type independent math operations.
void aimath_q7_quantize_tensor_from_f32(const aitensor_t *tensor_f32, aitensor_t *tensor_q7)
Converts a float f32 tensor into a quantized q7 tensor.
const aimath_dtype_t * aiq7
The Q7 data-type indicator.
void aimath_q7_print_aiscalar(const void *scalar)
Printing a Q7 scalar to console.
void aimath_q7_calc_q_params_from_f32(float min_value, float max_value, aimath_q7_params_t *q_params)
Calculates the aimath_q7_params parameters.
void aimath_q7_print_aitensor(const aitensor_t *tensor)
Printing a Q7 tensor to console.
Indicator for the used datatype.
Definition: aifes_math.h:44
Parameters used for the quantized Q7 values, used as property of a tensor.
Definition: aimath_q7.h:148
int8_t zero_point
The zero point of the quantization.
Definition: aimath_q7.h:150
uint16_t shift
The scaling factor of the quantization (The total scale is calculated with )
Definition: aimath_q7.h:149
Single quantized Q7 value/scalar.
Definition: aimath_q7.h:155
int8_t zero_point
The zero point of the quantization.
Definition: aimath_q7.h:158
uint16_t shift
The scaling factor of the quantization (The total scale is calculated with )
Definition: aimath_q7.h:157
int8_t value
Quantized value .
Definition: aimath_q7.h:156
A tensor in AIfES.
Definition: aifes_math.h:89