dequantise function

Float32List dequantise(
  1. Uint8List vector
)

Dequantises an SQ8-encoded vector back to float32.

Inverse of quantise:

f = u / 255.0 * 2.0 - 1.0

The reconstructed values are in [-1.0, 1.0] but are no longer L2-normalised (the quantisation error means the norm is slightly off 1.0). For cosine similarity via dot product this is acceptable — the ranking order is preserved.

vector may have any positive length. A debug-mode assertion fires for empty vectors.

Implementation

Float32List dequantise(Uint8List vector) {
  assert(
    vector.isNotEmpty,
    'SQ8 vector must be non-empty, got length ${vector.length}',
  );
  final out = Float32List(vector.length);
  for (var i = 0; i < vector.length; i++) {
    out[i] = vector[i] / 255.0 * 2.0 - 1.0;
  }
  return out;
}