Closed BruceDai closed 2 years ago
The root cause is that negative index for location of TF.js tensor (tfjs-core/src/tensor.ts) is limited,
/**
* Returns the value in the buffer at the provided location.
*
* @param locs The location indices.
*
* @doc {heading: 'Tensors', subheading: 'Creation'}
*/
get(...locs: number[]): SingleValueMap[D] {
if (locs.length === 0) {
locs = [0];
}
let i = 0;
for (const loc of locs) {
if (loc < 0 || loc >= this.shape[i]) {
const msg = `Requested out of range element at ${locs}. ` +
` Buffer shape=${this.shape}`;
throw new Error(msg);
}
i++;
}
let index = locs[locs.length - 1];
for (let i = 0; i < locs.length - 1; ++i) {
index += this.strides[i] * locs[i];
}
return this.values[index] as SingleValueMap[D];
}
I will workaround in polyfill implementation to support it firstly.
According to explanation of
slice
op, we should support negative starts asError
Error: Requested out of range element at -3,-4,-4. Buffer shape=3,4,5
happened.