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

Function createNestedArray

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

Source from the content-addressed store, hash-verified

579}
580
581function createNestedArray(
582 offset: number, shape: number[], a: TypedArray, isComplex = false) {
583 const ret = new Array();
584 if (shape.length === 1) {
585 const d = shape[0] * (isComplex ? 2 : 1);
586 for (let i = 0; i < d; i++) {
587 ret[i] = a[offset + i];
588 }
589 } else {
590 const d = shape[0];
591 const rest = shape.slice(1);
592 const len = rest.reduce((acc, c) => acc * c) * (isComplex ? 2 : 1);
593 for (let i = 0; i < d; i++) {
594 ret[i] = createNestedArray(offset + i * len, rest, a, isComplex);
595 }
596 }
597 return ret;
598}
599
600// Provide a nested array of TypedArray in given shape.
601export function toNestedArray(

Callers 1

toNestedArrayFunction · 0.85

Calls 1

sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…