MCPcopy Create free account
hub / github.com/DFin/Neural-Network-Visualisation / decodeFloat16Base64

Function decodeFloat16Base64

assets/main.js:726–744  ·  view source on GitHub ↗
(base64, expectedLength)

Source from the content-addressed store, hash-verified

724}
725
726function decodeFloat16Base64(base64, expectedLength) {
727 const bytes = decodeBase64ToUint8Array(base64);
728 if (bytes.byteLength % 2 !== 0) {
729 throw new Error("Float16-Daten haben eine ungültige Länge.");
730 }
731 const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
732 const length = bytes.byteLength / 2;
733 if (Number.isFinite(expectedLength) && expectedLength > 0 && length !== expectedLength) {
734 throw new Error(
735 `Erwartete ${expectedLength} Float16-Werte, erhalten wurden jedoch ${length}.`,
736 );
737 }
738 const result = new Float32Array(length);
739 for (let index = 0; index < length; index += 1) {
740 const half = view.getUint16(index * 2, true);
741 result[index] = float16ToFloat32(half);
742 }
743 return result;
744}
745
746function decodeWeightMatrix(encoded, shape) {
747 const rows = Math.max(0, Number(shape?.[0]) || 0);

Callers 2

decodeWeightMatrixFunction · 0.85
decodeSnapshotLayersFunction · 0.85

Calls 2

decodeBase64ToUint8ArrayFunction · 0.85
float16ToFloat32Function · 0.85

Tested by

no test coverage detected