MCPcopy Index your code
hub / github.com/tensorflow/tfjs / toNestedArray

Function toNestedArray

tfjs-core/src/util_base.ts:601–618  ·  view source on GitHub ↗
(
    shape: number[], a: TypedArray, isComplex = false)

Source from the content-addressed store, hash-verified

599
600// Provide a nested array of TypedArray in given shape.
601export 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
620export function convertBackendValuesAndArrayBuffer(
621 data: BackendValues|ArrayBuffer, dtype: DataType) {

Callers 3

arrayMethod · 0.90
arraySyncMethod · 0.90

Calls 1

createNestedArrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…