Quantize data: encode the float input to uint32_t output
| 38 | |
| 39 | //! Quantize data: encode the float input to uint32_t output |
| 40 | void BinaryQuantizer::encode(const float *in, size_t dim, uint32_t *out) const { |
| 41 | for (size_t i = 0; i < dim; i += 32) { |
| 42 | size_t remain = i + 32 <= dim ? 32 : dim - i; |
| 43 | uint32_t data = 0; |
| 44 | uint32_t mask = 1; |
| 45 | |
| 46 | for (size_t j = 0; j < remain; j++) { |
| 47 | if (in[i + j] >= threshold_) { |
| 48 | data |= mask; |
| 49 | } |
| 50 | |
| 51 | mask <<= 1; |
| 52 | } |
| 53 | |
| 54 | *out = data; |
| 55 | out++; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | //! De-quantize data: decode the input uint32_t to float output |
| 60 | //! bit value 1 will be mapped to 1.0 |
no outgoing calls