Normalize + int8 quantize a float vector. Returns false if the vector is * effectively zero (magnitude below epsilon), in which case `dst` is left in * an indeterminate state and the caller should skip this keyword. */
| 12157 | * effectively zero (magnitude below epsilon), in which case `dst` is left in |
| 12158 | * an indeterminate state and the caller should skip this keyword. */ |
| 12159 | static bool vs_normalize_and_quantize(const float *src, int8_t *dst) { |
| 12160 | float mag = 0.0F; |
| 12161 | for (int d = 0; d < VS_VEC_DIM; d++) { |
| 12162 | mag += src[d] * src[d]; |
| 12163 | } |
| 12164 | mag = sqrtf(mag); |
| 12165 | if (mag < CBM_STORE_DENOM_EPS_F) { |
| 12166 | return false; |
| 12167 | } |
| 12168 | float inv = CBM_STORE_UNIT_POS_F / mag; |
| 12169 | for (int d = 0; d < VS_VEC_DIM; d++) { |
| 12170 | dst[d] = vs_clamp_int8(src[d] * inv * CBM_STORE_INT8_MAX); |
| 12171 | } |
| 12172 | return true; |
| 12173 | } |
| 12174 | |
| 12175 | /* Build int8 query vectors for each keyword. Returns the number of |
| 12176 | * successfully built vectors (may be less than keyword_count when some |
no test coverage detected