* Returns the value in the buffer at the provided location. * * @param locs The location indices. * * @doc {heading: 'Tensors', subheading: 'Creation'}
(...locs: number[])
| 98 | * @doc {heading: 'Tensors', subheading: 'Creation'} |
| 99 | */ |
| 100 | get(...locs: number[]): SingleValueMap[D] { |
| 101 | if (locs.length === 0) { |
| 102 | locs = [0]; |
| 103 | } |
| 104 | let i = 0; |
| 105 | for (const loc of locs) { |
| 106 | if (loc < 0 || loc >= this.shape[i]) { |
| 107 | const msg = `Requested out of range element at ${locs}. ` + |
| 108 | ` Buffer shape=${this.shape}`; |
| 109 | throw new Error(msg); |
| 110 | } |
| 111 | i++; |
| 112 | } |
| 113 | let index = locs[locs.length - 1]; |
| 114 | for (let i = 0; i < locs.length - 1; ++i) { |
| 115 | index += this.strides[i] * locs[i]; |
| 116 | } |
| 117 | return this.values[index] as SingleValueMap[D]; |
| 118 | } |
| 119 | |
| 120 | locToIndex(locs: number[]): number { |
| 121 | if (this.rank === 0) { |
no outgoing calls