fix: allow extra index subscripts in 2D const lists #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #109
This code that was introduced in
EquationGen
in 2ed7e42 for PR #101 (issue #84):is incorrect in this case because the index i is applied to both the
separationDims
andsubscripts
arrays. When theseparationDims
are a proper subset ofsubscripts
, their elements do not correspond.It turns out we don't need to look up anything. The array variable that will be initialized from the const list is already separated into individually indexed elements at this point. We simply have to convert the canonical index names to numerical C indices to look up the variable's position in the const list. Even better, this works for both one- and two-dimensional arrays.
The other problem that needed to be fixed was in
VariableReader
. It assumed that the subscripts only included the separation dimensions. When an additional index subscript is present, as in this case, the separated variables created byVariableReader
would get an incomplete set of subscripts. While fixing this, I was also able to simplify the code by replacing the doubly nested loops with iteration over the cartesian product of the subscript dimensions. This could probably be applied to the 1D case as well, but that code was working with the additional index subscript, so I left it alone.This fix requires the fix for
antlr4-vensim
issue climateinteractive/antlr4-vensim#7.I added a new equation to the arrays_cname test model to cover the case for this issue.