* Scatter the values of a Tensor in specific indices of a TensorArray. * @param indices number[] values in [0, max_value). If the * TensorArray is not dynamic, max_value=size(). * @param tensor Tensor input tensor.
(indices: number[], tensor: Tensor)
| 245 | * @param tensor Tensor input tensor. |
| 246 | */ |
| 247 | scatter(indices: number[], tensor: Tensor) { |
| 248 | if (tensor.dtype !== this.dtype) { |
| 249 | throw new Error(`TensorArray dtype is ${ |
| 250 | this.dtype} but tensor has dtype ${tensor.dtype}`); |
| 251 | } |
| 252 | |
| 253 | if (indices.length !== tensor.shape[0]) { |
| 254 | throw new Error(`Expected len(indices) == tensor.shape[0], but saw: ${ |
| 255 | indices.length} vs. ${tensor.shape[0]}`); |
| 256 | } |
| 257 | |
| 258 | const maxIndex = Math.max(...indices); |
| 259 | |
| 260 | if (!this.dynamicSize && maxIndex >= this.maxSize) { |
| 261 | throw new Error( |
| 262 | `Max index must be < array size (${maxIndex} vs. ${this.maxSize})`); |
| 263 | } |
| 264 | |
| 265 | this.writeMany(indices, unstack(tensor, 0)); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Split the values of a Tensor into the TensorArray. |
no test coverage detected