|
1 | | -using RecursiveArrayTools, Test, LabelledArrays |
| 1 | +using RecursiveArrayTools, Test, LabelledArrays, SymbolicIndexingInterface |
2 | 2 |
|
3 | 3 | t = 0.0:0.1:1.0 |
4 | 4 | f(x) = 2x |
5 | 5 | f2(x) = 3x |
6 | 6 |
|
7 | 7 | dx = DiffEqArray([[f(x), f2(x)] for x in t], |
8 | | - t; |
| 8 | + t, |
| 9 | + [1.0, 2.0]; |
9 | 10 | variables = [:a, :b], |
| 11 | + parameters = [:p, :q], |
10 | 12 | independent_variables = [:t]) |
11 | 13 | @test dx[:t] == t |
12 | 14 | @test dx[:a] == [f(x) for x in t] |
13 | | -@test dx[:b] == [f2(x) for x in t] |
14 | | - |
15 | | -dx = DiffEqArray([[f(x), f2(x)] for x in t], |
16 | | - t; |
17 | | - variables = [:a, :b], |
18 | | - independent_variables = [:t]) |
| 15 | +@test dx[:a, 2] ≈ f(t[2]) |
| 16 | +@test dx[:b, 3] ≈ f2(t[3]) |
| 17 | +@test dx[:a, 2:4] ≈ [f(x) for x in t[2:4]] |
| 18 | +@test dx[:b, 4:6] ≈ [f2(x) for x in t[4:6]] |
| 19 | +@test dx[:b] ≈ [f2(x) for x in t] |
| 20 | +@test dx[[:a, :b]] ≈ [[f(x), f2(x)] for x in t] |
| 21 | +@test dx[(:a, :b)] == [(f(x), f2(x)) for x in t] |
| 22 | +@test dx[[:a, :b], 3] ≈ [f(t[3]), f2(t[3])] |
| 23 | +@test dx[[:a, :b], 4:5] ≈ vcat(f.(t[4:5])', f2.(t[4:5])') |
| 24 | +@test dx.ps[[:p, :q]] == [1.0, 2.0] |
| 25 | +@test dx.ps[:p] == 1.0 |
| 26 | +@test dx.ps[:q] == 2.0 |
19 | 27 | @test dx[:t] == t |
| 28 | + |
| 29 | +@test symbolic_container(dx) isa SymbolCache |
| 30 | +@test parameter_values(dx) == [1.0, 2.0] |
| 31 | +@test is_variable.((dx,), [:a, :b, :p, :q, :t]) == [true, true, false, false, false] |
| 32 | +@test variable_index.((dx,), [:a, :b, :p, :q, :t]) == [1, 2, nothing, nothing, nothing] |
| 33 | +@test is_parameter.((dx,), [:a, :b, :p, :q, :t]) == [false, false, true, true, false] |
| 34 | +@test parameter_index.((dx,), [:a, :b, :p, :q, :t]) == [nothing, nothing, 1, 2, nothing] |
| 35 | +@test is_independent_variable.((dx,), [:a, :b, :p, :q, :t]) == [false, false, false, false, true] |
| 36 | +@test variable_symbols(dx) == [:a, :b] |
| 37 | +@test parameter_symbols(dx) == [:p, :q] |
| 38 | +@test independent_variable_symbols(dx) == [:t] |
| 39 | +@test is_time_dependent(dx) |
| 40 | +@test constant_structure(dx) |
| 41 | + |
20 | 42 | dx = DiffEqArray([[f(x), f2(x)] for x in t], t; variables = [:a, :b]) |
21 | 43 | @test_throws Exception dx[nothing] # make sure it isn't storing [nothing] as indepsym |
22 | 44 |
|
23 | 45 | ABC = @SLVector (:a, :b, :c); |
24 | 46 | A = ABC(1, 2, 3); |
25 | 47 | B = RecursiveArrayTools.DiffEqArray([A, A], [0.0, 2.0]); |
26 | 48 | @test getindex(B, :a) == [1, 1] |
| 49 | + |
0 commit comments