(base64, expectedLength)
| 724 | } |
| 725 | |
| 726 | function 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 | |
| 746 | function decodeWeightMatrix(encoded, shape) { |
| 747 | const rows = Math.max(0, Number(shape?.[0]) || 0); |
no test coverage detected