Skip to content

Commit 564e5ed

Browse files
authored
update related tests
1 parent 8762d2b commit 564e5ed

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/build_function_arrayofarray.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ h_dense_arraymat_julia!(out_1_arraymat, input)
2626
h_dense_arraymat_ip!(out_2_arraymat, input)
2727
@test out_1_arraymat == out_2_arraymat
2828

29+
# Arrays of Matrices, Heterogeneous element types
30+
test_exp = [exp(a) * exp(b), a]
31+
h_dense_arraymat_het = [ModelingToolkit.hessian(t, [a, b]) for t in test_exp]
32+
function h_dense_arraymat_het_julia!(out, x)
33+
a, b, c = x
34+
out[1] .= [exp(a[1]) * exp(b[1]) exp(a[1]) * exp(b[1]); exp(a[1]) * exp(b[1]) exp(a[1]) * exp(b[1])]
35+
out[2] .= [0 0; 0 0]
36+
end
37+
38+
h_dense_arraymat_het_str = ModelingToolkit.build_function(h_dense_arraymat_het, [a, b, c])
39+
h_dense_arraymat_het_ip! = eval(h_dense_arraymat_het_str[2])
40+
out_1_arraymat_het = [Array{Float64}(undef, 2, 2) for i in 1:2]
41+
out_2_arraymat_het = [similar(x) for x in out_1_arraymat_het]
42+
h_dense_arraymat_het_julia!(out_1_arraymat_het, input)
43+
h_dense_arraymat_het_ip!(out_2_arraymat_het, input)
44+
@test out_1_arraymat_het == out_2_arraymat_het
45+
2946
# Arrays of 1D Vectors
3047
h_dense_arrayvec = [[a, 0, c], [0, 0, 0], [1, a, b]] # same for empty vectors, etc.
3148
function h_dense_arrayvec_julia!(out, x)
@@ -61,6 +78,24 @@ h_dense_arrayNestedMat_julia!(out_1_arrayNestedMat, input)
6178
h_dense_arrayNestedMat_ip!(out_2_arrayNestedMat, input)
6279
@test out_1_arrayNestedMat == out_2_arrayNestedMat
6380

81+
# Arrays of Arrays of Matrices, Heterogeneous element types
82+
test_exp = [exp(a) * exp(b), a]
83+
h_dense_arrayNestedMat_het = [[ModelingToolkit.hessian(t, [a, b]) for t in test_exp], [[ModelingToolkit.Constant(0) ModelingToolkit.Constant(0); ModelingToolkit.Constant(0) ModelingToolkit.Constant(0)], [ModelingToolkit.Constant(0) ModelingToolkit.Constant(0); ModelingToolkit.Constant(0) ModelingToolkit.Constant(0)]]]
84+
function h_dense_arrayNestedMat_het_julia!(out, x)
85+
a, b, c = x
86+
out[1][1] .= [exp(a[1]) * exp(b[1]) exp(a[1]) * exp(b[1]); exp(a[1]) * exp(b[1]) exp(a[1]) * exp(b[1])]
87+
out[1][2] .= [0 0; 0 0]
88+
out[2][1] .= [0 0; 0 0]
89+
out[2][2] .= [0 0; 0 0]
90+
end
91+
h_dense_arrayNestedMat_het_str = ModelingToolkit.build_function(h_dense_arrayNestedMat_het, [a, b, c])
92+
h_dense_arrayNestedMat_het_ip! = eval(h_dense_arrayNestedMat_het_str[2])
93+
out_1_arrayNestedMat_het = [[rand(Int64, 2, 2), rand(Int64, 2, 2)], [rand(Int64, 2, 2), rand(Int64, 2, 2)]] # avoid undef broadcasting issue
94+
out_2_arrayNestedMat_het = [[rand(Int64, 2, 2), rand(Int64, 2, 2)], [rand(Int64, 2, 2), rand(Int64, 2, 2)]]
95+
h_dense_arrayNestedMat_julia!(out_1_arrayNestedMat_het, input)
96+
h_dense_arrayNestedMat_ip!(out_2_arrayNestedMat_het, input)
97+
@test out_1_arrayNestedMat_het == out_2_arrayNestedMat_het
98+
6499
# ===== Sparse tests =====
65100
# Array of Matrices
66101
h_sparse_arraymat = sparse.([[a 1; b 0], [0 0; 0 0], [a c; 1 0]])

0 commit comments

Comments
 (0)