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

Function stringSplitImpl

tfjs-backend-cpu/src/kernels/StringSplit_impl.ts:64–100  ·  view source on GitHub ↗
(
    input: Uint8Array[], delimiter: Uint8Array,
    skipEmpty: boolean)

Source from the content-addressed store, hash-verified

62}
63
64export 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}

Callers 1

stringSplitFunction · 0.90

Calls 2

maxMethod · 0.80
splitFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…