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

Method _getitem

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

* Index into a Tensor object. * @param {number} index The index to access. * @returns {Tensor} The data at the specified index.

(index)

Source from the content-addressed store, hash-verified

138 * @returns {Tensor} The data at the specified index.
139 */
140 _getitem(index) {
141 const [iterLength, ...iterDims] = this.dims;
142
143 index = safeIndex(index, iterLength);
144
145 if (iterDims.length > 0) {
146 const iterSize = iterDims.reduce((a, b) => a * b);
147 return this._subarray(index, iterSize, iterDims);
148 } else {
149 return new Tensor(this.type, [this.data[index]], iterDims);
150 }
151 }
152
153 /**
154 * @param {number|bigint} item The item to search for in the tensor

Callers 1

constructorMethod · 0.80

Calls 2

_subarrayMethod · 0.95
safeIndexFunction · 0.85

Tested by

no test coverage detected