@@ -26,6 +26,23 @@ h_dense_arraymat_julia!(out_1_arraymat, input)
26
26
h_dense_arraymat_ip! (out_2_arraymat, input)
27
27
@test out_1_arraymat == out_2_arraymat
28
28
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
+
29
46
# Arrays of 1D Vectors
30
47
h_dense_arrayvec = [[a, 0 , c], [0 , 0 , 0 ], [1 , a, b]] # same for empty vectors, etc.
31
48
function h_dense_arrayvec_julia! (out, x)
@@ -61,6 +78,24 @@ h_dense_arrayNestedMat_julia!(out_1_arrayNestedMat, input)
61
78
h_dense_arrayNestedMat_ip! (out_2_arrayNestedMat, input)
62
79
@test out_1_arrayNestedMat == out_2_arrayNestedMat
63
80
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
+
64
99
# ===== Sparse tests =====
65
100
# Array of Matrices
66
101
h_sparse_arraymat = sparse .([[a 1 ; b 0 ], [0 0 ; 0 0 ], [a c; 1 0 ]])
0 commit comments