MCPcopy
hub / github.com/huggingface/transformers.js / item

Method item

packages/transformers/src/utils/tensor.js:189–195  ·  view source on GitHub ↗

* 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

()

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by

no test coverage detected