You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The test with byteOffset is not enough, you also have to use byteLength
For example, if you want to multiply a matrix with a vector extracted from the matrix
The full test could be something like this:
consta=newFloat32Array(25);// 5x5 matrixconstb=newFloat32Array(a.buffer,10*4,5);// offset by 10 elements (4 bytes per element), take 5 elements// Translation of the conditions:// [ A and B are the same array ]// OR// [// A uses a buffer AND// B uses the same buffer AND// NOT ( A is completely before B OR B is completely before A )// ]constshouldCopy=a===b||(a.buffer&&a.buffer===b.buffer&&!(a.byteOffset+a.byteLength<=b.byteOffset||b.byteOffset+b.byteLength<=a.byteOffset));// An equivalent, if you convert the `!(P || Q)` into a `!P && !Q`constshouldCopyBis=a===b||(a.buffer&&a.buffer===b.buffer&&a.byteOffset+a.byteLength>b.byteOffset&&b.byteOffset+b.byteLength>a.byteOffset);
This is to check if the two arrays overlap but in this particular case of matrix multiplication, you can for example use the first 16 elements of an array of size 100 as a matrix. So you could replace the x.byteLength with numberOfElements * x.BYTES_PER_ELEMENT.
Originally posted by @finetjul in #3009 (comment)
The text was updated successfully, but these errors were encountered: