(
input: Uint8Array[], delimiter: Uint8Array,
skipEmpty: boolean)
| 62 | } |
| 63 | |
| 64 | export function stringSplitImpl( |
| 65 | input: Uint8Array[], delimiter: Uint8Array, |
| 66 | skipEmpty: boolean): [TypedArray, Uint8Array[], [number, number]] { |
| 67 | const batchSize = input.length; |
| 68 | |
| 69 | // Empty delimiter means split the input character by character. |
| 70 | const tokens: Uint8Array[] = []; |
| 71 | |
| 72 | let outputSize = 0; |
| 73 | let maxNumEntries = 0; |
| 74 | const numIndices: number[] = new Array(batchSize); |
| 75 | for (let i = 0; i < batchSize; ++i) { |
| 76 | const prevTokensLength = tokens.length; |
| 77 | split(input[i], delimiter, skipEmpty, tokens); |
| 78 | const nEntries = tokens.length - prevTokensLength; |
| 79 | numIndices[i] = nEntries; |
| 80 | outputSize += nEntries; |
| 81 | maxNumEntries = Math.max(maxNumEntries, nEntries); |
| 82 | } |
| 83 | |
| 84 | const indices = util.getArrayFromDType('int32', outputSize * 2) as TypedArray; |
| 85 | const values: Uint8Array[] = new Array(outputSize); |
| 86 | const shape: [number, number] = [batchSize, maxNumEntries]; |
| 87 | |
| 88 | let c = 0; |
| 89 | for (let i = 0; i < batchSize; ++i) { |
| 90 | for (let j = 0; j < numIndices[i]; ++j) { |
| 91 | // indices is a 2d tensor with shape of [outputSize, 2] |
| 92 | indices[c * 2] = i; |
| 93 | indices[c * 2 + 1] = j; |
| 94 | values[c] = tokens[c]; |
| 95 | ++c; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return [indices, values, shape]; |
| 100 | } |
no test coverage detected
searching dependent graphs…