| 405 | template <typename T, typename TP> |
| 406 | inline T ex_bits_code( |
| 407 | const T* residual, size_t dim, size_t ex_bits, TP* ex_code, double t_const = -1 |
| 408 | ) { |
| 409 | ConstRowMajorArrayMap<T> res_arr(residual, 1, dim); |
| 410 | |
| 411 | // get normalized abs residual for plus code |
| 412 | RowMajorArray<T> abs_res = res_arr.rowwise().normalized().abs(); |
| 413 | |
| 414 | // quantize data |
| 415 | T ipnorm_inv = 1; |
| 416 | if (t_const > 0) { |
| 417 | ipnorm_inv = faster_quantize_ex(abs_res.data(), ex_code, dim, ex_bits, t_const); |
| 418 | } else { |
| 419 | ipnorm_inv = quantize_ex(abs_res.data(), ex_code, dim, ex_bits); |
| 420 | } |
| 421 | |
| 422 | // revert codes for negative dims |
| 423 | int32_t mask = (1 << ex_bits) - 1; |
| 424 | for (size_t j = 0; j < dim; ++j) { |
| 425 | if (res_arr.data()[j] < 0) { |
| 426 | TP tmp = ex_code[j]; |
| 427 | ex_code[j] = (~tmp) & mask; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | return ipnorm_inv; |
| 432 | } |
| 433 | |
| 434 | template <typename T, typename TP> |
| 435 | inline void ex_bits_code_with_factor( |
| 436 | const T* data, |
nothing calls this directly
no test coverage detected