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

Function stringSplit

tfjs-backend-webgl/src/kernels/StringSplit.ts:23–54  ·  view source on GitHub ↗
(args: {
  inputs: StringSplitInputs,
  backend: MathBackendWebGL,
  attrs: StringSplitAttrs
})

Source from the content-addressed store, hash-verified

21import {stringSplitImplCPU} from '../kernel_utils/shared';
22
23export function stringSplit(args: {
24 inputs: StringSplitInputs,
25 backend: MathBackendWebGL,
26 attrs: StringSplitAttrs
27}): [TensorInfo, TensorInfo, TensorInfo] {
28 const {inputs, backend, attrs} = args;
29 const {skipEmpty} = attrs;
30 const {input, delimiter} = inputs;
31
32 if (input.dtype !== 'string') {
33 throw new Error('Input must be of datatype string');
34 }
35 if (input.shape.length !== 1) {
36 throw new Error(`Input must be a vector, got shape: ${input.shape}`);
37 }
38 if (delimiter.shape.length !== 0) {
39 throw new Error(
40 `Delimiter must be a scalar, got shape: ${delimiter.shape}`);
41 }
42
43 const $input = backend.readSync(input.dataId) as Uint8Array[];
44 const $delimiter = backend.readSync(delimiter.dataId)[0] as Uint8Array;
45
46 const [indices, values, shape] =
47 stringSplitImplCPU($input, $delimiter, skipEmpty);
48 const outputSize = values.length;
49 return [
50 backend.makeTensorInfo([outputSize, 2], 'int32', indices),
51 backend.makeTensorInfo([outputSize], 'string', values),
52 backend.makeTensorInfo([2], 'int32', new Int32Array(shape))
53 ];
54}
55
56export const stringSplitConfig: KernelConfig = {
57 kernelName: StringSplit,

Callers

nothing calls this directly

Calls 2

readSyncMethod · 0.65
makeTensorInfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…