(
data: BackendValues|ArrayBuffer, dtype: DataType)
| 618 | } |
| 619 | |
| 620 | export function convertBackendValuesAndArrayBuffer( |
| 621 | data: BackendValues|ArrayBuffer, dtype: DataType) { |
| 622 | // If is type Uint8Array[], return it directly. |
| 623 | if (Array.isArray(data)) { |
| 624 | return data; |
| 625 | } |
| 626 | if (dtype === 'float32') { |
| 627 | return data instanceof Float32Array ? data : new Float32Array(data); |
| 628 | } else if (dtype === 'int32') { |
| 629 | return data instanceof Int32Array ? data : new Int32Array(data); |
| 630 | } else if (dtype === 'bool' || dtype === 'string') { |
| 631 | return Uint8Array.from(new Int32Array(data)); |
| 632 | } else { |
| 633 | throw new Error(`Unknown dtype ${dtype}`); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | export function makeOnesTypedArray<D extends DataType>( |
| 638 | size: number, dtype: D): DataTypeMap[D] { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…