()
| 718 | * the Uint16Array of Float16 bytes to a Float32Array. |
| 719 | */ |
| 720 | export 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 | } |
no test coverage detected
searching dependent graphs…