(
value: number|boolean|string|Uint8Array, dtype?: DataType)
| 36 | * @doc {heading: 'Tensors', subheading: 'Creation'} |
| 37 | */ |
| 38 | export function scalar( |
| 39 | value: number|boolean|string|Uint8Array, dtype?: DataType): Scalar { |
| 40 | if (((isTypedArray(value) && dtype !== 'string') || Array.isArray(value)) && |
| 41 | dtype !== 'complex64') { |
| 42 | throw new Error( |
| 43 | 'Error creating a new Scalar: value must be a primitive ' + |
| 44 | '(number|boolean|string)'); |
| 45 | } |
| 46 | if (dtype === 'string' && isTypedArray(value) && |
| 47 | !(value instanceof Uint8Array)) { |
| 48 | throw new Error( |
| 49 | 'When making a scalar from encoded string, ' + |
| 50 | 'the value must be `Uint8Array`.'); |
| 51 | } |
| 52 | const shape: number[] = []; |
| 53 | const inferredShape: number[] = []; |
| 54 | return makeTensor(value, shape, inferredShape, dtype) as Scalar; |
| 55 | } |
no test coverage detected
searching dependent graphs…