* Synchronously downloads the values from the `tf.Tensor`. This blocks the * UI thread until the values are ready, which can cause performance issues. * * @doc {heading: 'Tensors', subheading: 'Classes'}
()
| 409 | * @doc {heading: 'Tensors', subheading: 'Classes'} |
| 410 | */ |
| 411 | dataSync<D extends DataType = NumericDataType>(): DataTypeMap[D] { |
| 412 | this.throwIfDisposed(); |
| 413 | const data = trackerFn().readSync(this.dataId); |
| 414 | if (this.dtype === 'string') { |
| 415 | try { |
| 416 | return (data as Uint8Array[]).map(b => util.decodeString(b)) as |
| 417 | DataTypeMap[D]; |
| 418 | } catch { |
| 419 | throw new Error( |
| 420 | 'Failed to decode the string bytes into utf-8. ' + |
| 421 | 'To get the original bytes, call tensor.bytes().'); |
| 422 | } |
| 423 | } |
| 424 | return data as DataTypeMap[D]; |
| 425 | } |
| 426 | |
| 427 | /** Returns the underlying bytes of the tensor's data. */ |
| 428 | async bytes(): Promise<Uint8Array[]|Uint8Array> { |
no test coverage detected