numjs
numjs copied to clipboard
views don't share the same data after reshape
I'm using numjs to work over data inside an ArrayBuffer. I expect that, if I use reshape, I obtain a view on the same ArrayBuffer. Unfortunately, in this short example this doesn't work.
let a=nj.arange(0, 256, 1, "float32").reshape(16, 16);
let b=a.reshape(-1);
let sameData = a.selection.data===b.selection.data; // sameData=false
b.set(0, 1);
console.log(b.get(0)); // output: 1
console.log(a.get(0,0); // output: 0
But if I create the arrays in the opposite order, it works:
let a=nj.arange(0, 256, 1, "float32").reshape(16, 16);
let b=a.reshape(-1);
let c=b.reshape(16,16);
let sameData = b.selection.data===c.selection.data; // sameData=true
b.set(0, 1);
console.log(b.get(0)); // output: 1
console.log(c.get(0,0); // output: 1