MCPcopy Create free account
hub / github.com/tensorflow/tfjs / prepareSplitSize

Function prepareSplitSize

tfjs-core/src/ops/split_util.ts:26–60  ·  view source on GitHub ↗
(
    x: Tensor|TensorInfo, numOrSizeSplits: number[]|number,
    axis = 0)

Source from the content-addressed store, hash-verified

24 * rest of the axis is allocated toward that.
25 */
26export function prepareSplitSize(
27 x: Tensor|TensorInfo, numOrSizeSplits: number[]|number,
28 axis = 0): number[] {
29 let splitSizes = [];
30 if (typeof (numOrSizeSplits) === 'number') {
31 assert(
32 x.shape[axis] % numOrSizeSplits === 0,
33 () => 'Number of splits must evenly divide the axis.');
34 splitSizes =
35 new Array(numOrSizeSplits).fill(x.shape[axis] / numOrSizeSplits);
36 } else {
37 const numOfNegs = numOrSizeSplits.reduce((count, value) => {
38 if (value === -1) {
39 count += 1;
40 }
41 return count;
42 }, 0);
43 assert(
44 numOfNegs <= 1,
45 () => 'There should be only one negative value in split array.');
46 const negIndex = numOrSizeSplits.indexOf(-1);
47 // Allow the number of split array to be -1, which indicates the rest
48 // of dimension is allocated to that split.
49 if (negIndex !== -1) {
50 const total = numOrSizeSplits.reduce((a, b) => b > 0 ? a + b : a);
51 numOrSizeSplits[negIndex] = x.shape[axis] - total;
52 }
53 assert(
54 x.shape[axis] === numOrSizeSplits.reduce((a, b) => a + b),
55 () => 'The sum of sizes must match the size of the axis dimension.');
56 splitSizes = numOrSizeSplits;
57 }
58
59 return splitSizes;
60}

Callers

nothing calls this directly

Calls 1

assertFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…