* Return selected values in the TensorArray as a packed Tensor. All of * selected values must have been written and their shapes must all match. * @param [indices] number[] Optional. Taking values in [0, max_value). If the * TensorArray is not dynamic, max_value=size(). If not specified
(indices?: number[], dtype?: DataType)
| 182 | * @param [dtype] |
| 183 | */ |
| 184 | gather(indices?: number[], dtype?: DataType): Tensor { |
| 185 | if (!!dtype && dtype !== this.dtype) { |
| 186 | throw new Error(`TensorArray dtype is ${ |
| 187 | this.dtype} but gather requested dtype ${dtype}`); |
| 188 | } |
| 189 | |
| 190 | if (!indices) { |
| 191 | indices = []; |
| 192 | for (let i = 0; i < this.size(); i++) { |
| 193 | indices.push(i); |
| 194 | } |
| 195 | } else { |
| 196 | indices = indices.slice(0, this.size()); |
| 197 | } |
| 198 | |
| 199 | if (indices.length === 0) { |
| 200 | return tensor([], [0].concat(this.elementShape)); |
| 201 | } |
| 202 | |
| 203 | // Read all the PersistentTensors into a vector to keep track of |
| 204 | // their memory. |
| 205 | const tensors = this.readMany(indices); |
| 206 | |
| 207 | assertShapesMatchAllowUndefinedSize( |
| 208 | this.elementShape, tensors[0].shape, 'TensorArray shape mismatch: '); |
| 209 | |
| 210 | return stack(tensors, 0); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Return the values in the TensorArray as a concatenated Tensor. |