* Return a tensor that stacks a list of rank-R tf.Tensors into one rank-(R+1) * tf.Tensor. * @param elementShape shape of each tensor * @param elementDtype data type of each tensor * @param numElements the number of elements to stack
(elementShape: number[], elementDtype: DataType, numElements = -1)
| 105 | * @param numElements the number of elements to stack |
| 106 | */ |
| 107 | stack(elementShape: number[], elementDtype: DataType, numElements = -1): |
| 108 | Tensor { |
| 109 | if (elementDtype !== this.elementDtype) { |
| 110 | throw new Error(`Invalid data types; op elements ${ |
| 111 | elementDtype}, but list elements ${this.elementDtype}`); |
| 112 | } |
| 113 | if (numElements !== -1 && this.tensors.length !== numElements) { |
| 114 | throw new Error(`Operation expected a list with ${ |
| 115 | numElements} elements but got a list with ${ |
| 116 | this.tensors.length} elements.`); |
| 117 | } |
| 118 | assertShapesMatchAllowUndefinedSize( |
| 119 | elementShape, this.elementShape, 'TensorList shape mismatch: '); |
| 120 | const outputElementShape = |
| 121 | inferElementShape(this.elementShape, this.tensors, elementShape); |
| 122 | return tidy(() => { |
| 123 | const reshapedTensors = |
| 124 | this.tensors.map(tensor => reshape(tensor, outputElementShape)); |
| 125 | return stack(reshapedTensors, 0); |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Pop a tensor from the end of the list. |
nothing calls this directly
no test coverage detected