(
shape: number[], a: TypedArray, isComplex = false)
| 599 | |
| 600 | // Provide a nested array of TypedArray in given shape. |
| 601 | export function toNestedArray( |
| 602 | shape: number[], a: TypedArray, isComplex = false) { |
| 603 | if (shape.length === 0) { |
| 604 | // Scalar type should return a single number. |
| 605 | return a[0]; |
| 606 | } |
| 607 | const size = shape.reduce((acc, c) => acc * c) * (isComplex ? 2 : 1); |
| 608 | if (size === 0) { |
| 609 | // A tensor with shape zero should be turned into empty list. |
| 610 | return []; |
| 611 | } |
| 612 | if (size !== a.length) { |
| 613 | throw new Error(`[${shape}] does not match the input size ${a.length}${ |
| 614 | isComplex ? ' for a complex tensor' : ''}.`); |
| 615 | } |
| 616 | |
| 617 | return createNestedArray(0, shape, a, isComplex); |
| 618 | } |
| 619 | |
| 620 | export function convertBackendValuesAndArrayBuffer( |
| 621 | data: BackendValues|ArrayBuffer, dtype: DataType) { |
no test coverage detected
searching dependent graphs…