(
x: Tensor|TensorInfo, numOrSizeSplits: number[]|number,
axis = 0)
| 24 | * rest of the axis is allocated toward that. |
| 25 | */ |
| 26 | export 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…