* Return the values in the TensorArray as a concatenated Tensor.
(dtype?: DataType)
| 214 | * Return the values in the TensorArray as a concatenated Tensor. |
| 215 | */ |
| 216 | concat(dtype?: DataType): Tensor { |
| 217 | if (!!dtype && dtype !== this.dtype) { |
| 218 | throw new Error(`TensorArray dtype is ${ |
| 219 | this.dtype} but concat requested dtype ${dtype}`); |
| 220 | } |
| 221 | |
| 222 | if (this.size() === 0) { |
| 223 | return tensor([], [0].concat(this.elementShape)); |
| 224 | } |
| 225 | |
| 226 | const indices = []; |
| 227 | for (let i = 0; i < this.size(); i++) { |
| 228 | indices.push(i); |
| 229 | } |
| 230 | // Collect all the tensors from the tensors array. |
| 231 | const tensors = this.readMany(indices); |
| 232 | |
| 233 | assertShapesMatchAllowUndefinedSize( |
| 234 | this.elementShape, tensors[0].shape, |
| 235 | `TensorArray shape mismatch: tensor array shape (${ |
| 236 | this.elementShape}) vs first tensor shape (${tensors[0].shape})`); |
| 237 | |
| 238 | return concat(tensors, 0); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Scatter the values of a Tensor in specific indices of a TensorArray. |