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
{{ message }}
Repository navigation
Verify VECTOR ELM MAP / VECTOR SORT ORDER 0-based vs 1-based indexing #351
The interpreter's VECTOR SORT ORDER returns 1-based position indices (line 533: i + 1), while VECTOR ELM MAP uses offsets as 0-based array indices (line 519: source_values[offset]). If these are composed -- a standard Vensim pattern -- the 1-based indices from sort-order could be off-by-one when used as 0-based lookups in elm-map.
In Vensim, VECTOR SORT ORDER returns 1-based indices and VECTOR ELM MAP expects 0-based offsets. This asymmetry may be intentional (users subtract 1 in their equations), but it needs verification against Vensim reference output.
Why it matters
Correctness: If the indexing convention is wrong, any model composing these two functions will produce silently incorrect results or panic on out-of-bounds access.
Developer experience: The semantics are non-obvious and underdocumented in the codebase; future contributors could easily introduce regressions.
The test model test/sdeverywhere/models/vector_simple/vector_simple.mdl exercises these functions but has no expected output data (.dat file) to validate against. Without reference output, correctness cannot be confirmed through the existing test infrastructure.
Possible approaches
Run the vector_simple model in Vensim and capture the .dat output as a reference file, then add it to the test suite.
Create a minimal dedicated test model that composes VECTOR SORT ORDER output into VECTOR ELM MAP and compare against known-correct Vensim output.
Review the Vensim documentation for the exact indexing conventions of both functions and add code comments documenting the expected behavior.
Context
Identified during code review of the MDL full-compat interpreter implementation on branch mdl-full-compat.
Activity
engine: add why-comments for VectorElmMap/VectorSortOrder indexing as…
engine: add why-comments for VectorElmMap/VectorSortOrder indexing as…