@@ -16,25 +16,41 @@ function runtests()
1616 return
1717end
1818
19- function test_array_product ()
19+ function test_neural ()
2020 n = 2
2121 X = rand (n, n)
2222 model = Model ()
23- @variable (model, W[1 : n, 1 : n], container = ArrayDiff. ArrayOfVariables)
24- @test W isa ArrayDiff. MatrixOfVariables{Float64}
25- @test JuMP. index (W[1 , 1 ]) == MOI. VariableIndex (1 )
26- @test JuMP. index (W[2 , 1 ]) == MOI. VariableIndex (2 )
27- @test JuMP. index (W[2 ]) == MOI. VariableIndex (2 )
28- @test sprint (show, W) ==
23+ @variable (model, W1[1 : n, 1 : n], container = ArrayDiff. ArrayOfVariables)
24+ @variable (model, W2[1 : n, 1 : n], container = ArrayDiff. ArrayOfVariables)
25+ @test W1 isa ArrayDiff. MatrixOfVariables{Float64}
26+ @test JuMP. index (W1[1 , 1 ]) == MOI. VariableIndex (1 )
27+ @test JuMP. index (W1[2 , 1 ]) == MOI. VariableIndex (2 )
28+ @test JuMP. index (W1[2 ]) == MOI. VariableIndex (2 )
29+ @test sprint (show, W1) ==
2930 " 2×2 ArrayDiff.ArrayOfVariables{Float64, 2} with offset 0"
30- prod = W * X
31- @test prod isa ArrayDiff. ArrayExpr{2 }
32- @test sprint (show, prod) ==
33- " 2×2 ArrayDiff.GenericArrayExpr{JuMP.VariableRef, 2}"
34- err = ErrorException (
35- " `getindex` not implemented, build vectorized expression instead" ,
36- )
37- @test_throws err prod[1 , 1 ]
31+ for prod in [W1 * X, X * W1]
32+ @test prod isa ArrayDiff. MatrixExpr
33+ @test prod. head == :*
34+ @test ! prod. broadcasted
35+ @test sprint (show, prod) ==
36+ " 2×2 ArrayDiff.GenericArrayExpr{JuMP.VariableRef, 2}"
37+ err = ErrorException (
38+ " `getindex` not implemented, build vectorized expression instead" ,
39+ )
40+ @test_throws err prod[1 , 1 ]
41+ end
42+ Y1 = W1 * X
43+ X1 = tanh .(Y1)
44+ @test X1 isa ArrayDiff. MatrixExpr
45+ @test X1. head == :tanh
46+ @test X1. broadcasted
47+ @test X1. args[] === Y1
48+ Y2 = W2 * X1
49+ @test Y2. head == :*
50+ @test ! Y2. broadcasted
51+ @test length (Y2. args) == 2
52+ @test Y2. args[1 ] === W2
53+ @test Y2. args[2 ] === X1
3854 return
3955end
4056
0 commit comments