@@ -1008,11 +1008,37 @@ for sys in [sys1, sys2]
10081008 end
10091009end
10101010
1011- @testset " Non-1-indexed variable array (issue #2670)" begin
1012- @variables x (t)[0 : 1 ] # 0-indexed variable array
1011+ @testset " Non-1-indexed variable array (issue #2670 + #3659)" begin
1012+ # 0-indexed vector
1013+ @variables x (t)[0 : 1 ]
10131014 @named sys = System ([x[0 ] ~ 0.0 , D (x[1 ]) ~ x[0 ]], t, [x], [])
10141015 @test_nowarn sys = mtkcompile (sys)
10151016 @test equations (sys) == [D (x[1 ]) ~ 0.0 ]
1017+
1018+ # 1-indexed vector
1019+ @variables x (t)[1 : 3 ]
1020+ @named M = System ([D (x[i]) ~ 0 for i in eachindex (x)], t)
1021+ prob = ODEProblem (mtkcompile (M), [x[1 ] => 1 , x[2 ] => 2 , x[3 ] => 3 ], (0.0 , 1.0 ))
1022+ @test prob[x[1 ]] == 1
1023+ @test prob[x[2 ]] == 2
1024+ @test prob[x[3 ]] == 3
1025+
1026+ # non-1-indexed vector
1027+ @variables x (t)[3 : 5 ]
1028+ @named M = System ([D (x[i]) ~ 0 for i in eachindex (x)], t)
1029+ prob = ODEProblem (mtkcompile (M), [x[3 ] => 3 , x[4 ] => 4 , x[5 ] => 5 ], (0.0 , 1.0 ))
1030+ @test prob[x[3 ]] == 3
1031+ @test prob[x[4 ]] == 4
1032+ @test prob[x[5 ]] == 5
1033+
1034+ # non-(1,1)-indexed matrix
1035+ @variables x (t)[3 : 4 ,7 : 8 ]
1036+ @named M = System (vec ([D (x[i]) ~ 0 for i in eachindex (x)]), t)
1037+ prob = ODEProblem (mtkcompile (M), [x[3 ,7 ] => 37 , x[3 ,8 ] => 38 , x[4 ,7 ] => 47 , x[4 ,8 ] => 48 ], (0.0 , 1.0 ))
1038+ @test prob[x[3 ,7 ]] == 37
1039+ @test prob[x[3 ,8 ]] == 38
1040+ @test prob[x[4 ,7 ]] == 47
1041+ @test prob[x[4 ,8 ]] == 48
10161042end
10171043
10181044# Namespacing of array variables
0 commit comments