|
1 |
| -using ModelingToolkit |
2 |
| -using LinearAlgebra |
3 |
| -@variables a,b,c,d |
4 |
| -X = [a b;c d] |
5 |
| -det(X) |
6 |
| -lu(X) |
7 |
| -inv(X) |
| 1 | +using ModelingToolkit |
| 2 | +using LinearAlgebra |
| 3 | +using SparseArrays: sparse |
| 4 | +using Test |
| 5 | + |
| 6 | +@variables a,b,c,d |
| 7 | + |
| 8 | +# test some matrix operations don't throw errors |
| 9 | +X = [a b;c d] |
| 10 | +det(X) |
| 11 | +lu(X) |
| 12 | +inv(X) |
| 13 | + |
| 14 | +# test operations with sparse arrays and Operations |
| 15 | +# note `isequal` instead of `==` because `==` would give another Operation |
| 16 | + |
| 17 | +# test that we can create a sparse array of Operation |
| 18 | +Oarray = zeros(Operation, 2,2) |
| 19 | +Oarray[2,2] = a |
| 20 | +@test isequal(sparse(Oarray), sparse([2], [2], [a])) |
| 21 | + |
| 22 | +# test Operation * sparse |
| 23 | +@test isequal(a * sparse([2], [2], [1]), sparse([2], [2], [a * 1])) |
| 24 | + |
| 25 | +# test sparse{Operation} + sparse{Operation} |
| 26 | +A = sparse([2], [2], [a]) |
| 27 | +B = sparse([2], [2], [b]) |
| 28 | +@test isequal(A + B, sparse([2], [2], [a+b])) |
| 29 | + |
| 30 | +# test sparse{Operation} * sparse{Operation} |
| 31 | +C = sparse([1, 2], [2, 1], [c, c]) |
| 32 | +D = sparse([1, 2], [2, 1], [d, d]) |
| 33 | + |
| 34 | +@test isequal(C * D, sparse([1,2], [1,2], [c * d, c * d])) |
0 commit comments