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
In browser environment, when I used multiply, it got stuck on NDIter in an infinite loop.
The cause is that NDArray arity isn't checked by the multiply function and it assumes it will work with two matrices. If one tries to multiple a matrix ([[...],[...],[...]]) with a vector [..], the c2 value is undefined.
This causes a subsequently constructed result matrix to have 0 size, i.e. undefined length.
Which isn't checked either when NDIter is constructed, resulting in an infinite loop because index > undefined is true (because undefined is cast to 0).
Solution
Check if vector is provided as second argument and turn it into a matrix.
Handle vectors from NDIter?
The text was updated successfully, but these errors were encountered:
Caellian
changed the title
Infinite loop on multiply in browser.
Infinite loop in multiply when applied to NxN and N shaped arrays
Dec 11, 2024
Hey, thanks for creating an issue! Multiply is not as versatile as numpy's dot in python. As described in the docs, it "Multiplies two matrices x and y of matching dimensions. Accelerated with BLAS ?gemm.".
If you want to multiply a matrix with a vector, you need to first make the vector a column/row matrix and then perform the multiplication.
I think the more correct way to address this shortcoming is to make dot behave like numpy's dot.
EDIT: And also make multiply handle the infinite loop. It should instead throw an error.
Thanks for clarification. I ended up using gl-matrix because it was more in line with what I need algrebra for (WebGL), but it's much less ergonomic because it operates on TypedArrays directly.
I believe it would be good to note this in docs as well and point to dot function. I assume a.size.length !== b.size.length is enough to check for this case, but yeah, whatever doesn't make the whole browser freeze is great haha.
I'd like to point out that ability to distinguish between dot and multiply probably depends on previously used libraries. In my case, I'm coming from nalgebra which overrides the multiply operator so I'm probably expecting dot when I see multiply.
In browser environment, when I used
multiply
, it got stuck onNDIter
in an infinite loop.NDArray
arity isn't checked by themultiply
function and it assumes it will work with two matrices. If one tries to multiple a matrix ([[...],[...],[...]]
) with a vector[..]
, thec2
value is undefined.0
size, i.e.undefined
length.NDIter
is constructed, resulting in an infinite loop becauseindex > undefined
istrue
(becauseundefined
is cast to0
).Solution
The text was updated successfully, but these errors were encountered: