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

Function stringSplit

tfjs-backend-cpu/src/kernels/StringSplit.ts:24–55  ·  view source on GitHub ↗
(args: {
  inputs: StringSplitInputs,
  backend: MathBackendCPU,
  attrs: StringSplitAttrs
})

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

stringSplitImplFunction · 0.90
getMethod · 0.45
makeTensorInfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…