* Returns the value of this tensor as a standard JavaScript Number. This only works * for tensors with one element. For other cases, see `Tensor.tolist()`. * @returns {number|bigint} The value of this tensor as a standard JavaScript Number. * @throws {Error} If the tensor has more tha
()
| 187 | * @throws {Error} If the tensor has more than one element. |
| 188 | */ |
| 189 | item() { |
| 190 | const this_data = this.data; |
| 191 | if (this_data.length !== 1) { |
| 192 | throw new Error(`a Tensor with ${this_data.length} elements cannot be converted to Scalar`); |
| 193 | } |
| 194 | return this_data[0]; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Convert tensor data to a n-dimensional JS list |
no outgoing calls
no test coverage detected