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