(args: {
inputs: StringSplitInputs,
backend: MathBackendWebGL,
attrs: StringSplitAttrs
})
| 21 | import {stringSplitImplCPU} from '../kernel_utils/shared'; |
| 22 | |
| 23 | export 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 | |
| 56 | export const stringSplitConfig: KernelConfig = { |
| 57 | kernelName: StringSplit, |
nothing calls this directly
no test coverage detected
searching dependent graphs…