* Index into a Tensor object. * @param {number} index The index to access. * @returns {Tensor} The data at the specified index.
(index)
| 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 |
no test coverage detected