@@ -2,23 +2,33 @@ using ModelingToolkit, Test
2
2
@variables a b c1 c2 c3 d e g
3
3
4
4
# Multiple argument matrix
5
- h = [a + b + c1 + c2; c3 + d + e + g] # uses the same number of arguments as our application
6
- h_julia (a, b, c, d, e, g) = [a[1 ] + b[1 ] + c[1 ] + c[2 ]; c[3 ] + d[1 ] + e[1 ] + g[1 ]]
5
+ h = [a + b + c1 + c2,
6
+ c3 + d + e + g,
7
+ 0 ] # uses the same number of arguments as our application
8
+ h_julia (a, b, c, d, e, g) = [a[1 ] + b[1 ] + c[1 ] + c[2 ],
9
+ c[3 ] + d[1 ] + e[1 ] + g[1 ],
10
+ 0 ]
7
11
function h_julia! (out, a, b, c, d, e, g)
8
- out .= [a[1 ] + b[1 ] + c[1 ] + c[2 ]; c[3 ] + d[1 ] + e[1 ] + g[1 ]]
12
+ out .= [a[1 ] + b[1 ] + c[1 ] + c[2 ], c[3 ] + d[1 ] + e[1 ] + g[1 ], 0 ]
9
13
end
10
14
11
15
h_str = ModelingToolkit. build_function (h, [a], [b], [c1, c2, c3], [d], [e], [g])
12
16
h_oop = eval (h_str[1 ])
13
17
h_ip! = eval (h_str[2 ])
18
+ h_ip_skip! = eval (ModelingToolkit. build_function (h, [a], [b], [c1, c2, c3], [d], [e], [g], skipzeros= true )[2 ])
14
19
inputs = ([1 ], [2 ], [3 , 4 , 5 ], [6 ], [7 ], [8 ])
15
20
16
21
@test h_oop (inputs... ) == h_julia (inputs... )
17
- out_1 = Array {Int64} (undef, 2 )
22
+ out_1 = similar (h, Int )
18
23
out_2 = similar (out_1)
19
24
h_ip! (out_1, inputs... )
20
25
h_julia! (out_2, inputs... )
21
26
@test out_1 == out_2
27
+ fill! (out_1, 10 )
28
+ h_ip_skip! (out_1, inputs... )
29
+ @test out_1[3 ] == 10
30
+ out_1[3 ] = 0
31
+ @test out_1 == out_2
22
32
23
33
# Multiple input matrix, some unused arguments
24
34
h_skip = [a + b + c1; c2 + c3 + g] # skip d, e
0 commit comments