mateogianolio / mateogianolio/vectorious
Infinite loop in `multiply` when applied to NxN and N shaped arrays
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 918
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
In browser environment, when I used `multiply`, it got stuck on [`NDIter`](https://github.com/mateogianolio/vectorious/blob/7876984b6cf6e8c924fc67dae1cd87a946891624/src/core/multiply.ts#L51) 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`](https://github.com/mateogianolio/vectorious/blob/7876984b6cf6e8c924fc67dae1cd87a946891624/src/core/multiply.ts#L33) value is undefined.
- This causes a subsequently constructed [result matrix](https://github.com/mateogianolio/vectorious/blob/7876984b6cf6e8c924fc67dae1cd87a946891624/src/core/multiply.ts#L41) 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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/core/multiply.ts around the NDIter construction and result-matrix setup referenced in the issue. Reproduce multiply with an NxN matrix and an N-shaped vector, then trace how vector inputs, including those from NDIter, are handled. Done means this input no longer enters an infinite loop and the intended vector case is supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100