* Read the value at location index in the TensorArray. * @param index Number the index to read from.
(index: number)
| 72 | * @param index Number the index to read from. |
| 73 | */ |
| 74 | read(index: number): Tensor { |
| 75 | if (this.closed_) { |
| 76 | throw new Error(`TensorArray ${this.name} has already been closed.`); |
| 77 | } |
| 78 | |
| 79 | if (index < 0 || index >= this.size()) { |
| 80 | throw new Error(`Tried to read from index ${index}, but array size is: ${ |
| 81 | this.size()}`); |
| 82 | } |
| 83 | |
| 84 | const tensorWithState = this.tensors[index]; |
| 85 | if (tensorWithState.cleared) { |
| 86 | throw new Error( |
| 87 | `TensorArray ${this.name}: Could not read index ${ |
| 88 | index} twice because it was cleared after a previous read ` + |
| 89 | `(perhaps try setting clear_after_read = false?).`); |
| 90 | } |
| 91 | |
| 92 | if (this.clearAfterRead) { |
| 93 | tensorWithState.cleared = true; |
| 94 | } |
| 95 | |
| 96 | tensorWithState.read = true; |
| 97 | return tensorWithState.tensor; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Helper method to read multiple tensors from the specified indices. |