Problem
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.
Component(s) affected
src/simlin-engine/src/interpreter.rs (lines 512-548)
Current state
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.
Problem
The interpreter's
VECTOR SORT ORDERreturns 1-based position indices (line 533:i + 1), whileVECTOR ELM MAPuses 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 ORDERreturns 1-based indices andVECTOR ELM MAPexpects 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
Component(s) affected
src/simlin-engine/src/interpreter.rs(lines 512-548)Current state
The test model
test/sdeverywhere/models/vector_simple/vector_simple.mdlexercises 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
vector_simplemodel in Vensim and capture the .dat output as a reference file, then add it to the test suite.VECTOR SORT ORDERoutput intoVECTOR ELM MAPand compare against known-correct Vensim output.Context
Identified during code review of the MDL full-compat interpreter implementation on branch
mdl-full-compat.