greta-dev / greta-dev/greta.dynamics
r_iterate_matrix function in tests returns incorrect stable state if loop reaches niter
- Dominant language
- R
- Stars
- 6
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
I think there is a mismatch in the stable states returned by the r_iterate_matrix and iterate_matrix functions if the loop runs to the final iteration. Not sure if current tests are ending the loop before niter, hence not erroring.
The (possible) issue arises when the while loop never breaks due to `diff > tol`, in which case the final iteration is (`i < niter` => `i = niter - 1`). This iteration increments `i` by 1, then stores the output to `states[[i+1]]`. So the final element of states is at `niter + 1`.
https://github.com/greta-dev/greta.dynamics/blob/e89309d2e851373adc38e7d3eb77e9175ef9dc5c/tests/testthat/helpers.R#L23-L25
But then the stable state is returned as `states[[i]]`, which is `states[[niter]]` in this case:
https://github.com/greta-dev/greta.dynamics/blob/e89309d2e851373adc38e7d3eb77e9175ef9dc5c/tests/testthat/helpers.R#L32
Is this intentional? If not, I can prepare a PR. The same issue arises on the iterate_dynamic_matrix branch.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.