MCPcopy Create free account
hub / github.com/tensorflow/tfjs / getFloat16Decoder

Function getFloat16Decoder

tfjs-core/src/io/io_utils.ts:720–741  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

718 * the Uint16Array of Float16 bytes to a Float32Array.
719 */
720export function getFloat16Decoder(): (buffer: Uint16Array) => Float32Array {
721 // Algorithm is based off of
722 // http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
723
724 // Cache lookup tables
725 const mantisaTable = computeFloat16MantisaTable();
726 const exponentTable = computeFloat16ExponentTable();
727 const offsetTable = computeFloat16OffsetTable();
728
729 return (quantizedArray: Uint16Array) => {
730 const buffer = new ArrayBuffer(4 * quantizedArray.length);
731 const bufferUint32View = new Uint32Array(buffer);
732 for (let index = 0; index < quantizedArray.length; index++) {
733 const float16Bits = quantizedArray[index];
734 const float32Bits =
735 mantisaTable[offsetTable[float16Bits >> 10] + (float16Bits & 0x3ff)] +
736 exponentTable[float16Bits >> 10];
737 bufferUint32View[index] = float32Bits;
738 }
739 return new Float32Array(buffer);
740 };
741}

Callers 2

io_utils_test.tsFile · 0.90
decodeWeightFunction · 0.85

Calls 3

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…