Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Feb 26, 2021
2 parents 19f5cdb + 6f57942 commit df67c52
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ TreeViews = "0.3"
julia = "1.2"

[extras]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "SafeTestsets"]
test = ["Test", "SafeTestsets", "Pkg"]
66 changes: 55 additions & 11 deletions test/array.jl → test/overloads.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Symbolics
using ModelingToolkit
using LinearAlgebra
using SparseArrays: sparse
using Test


@variables a,b,c,d,e,f,g,h,i

# test hashing
Expand All @@ -14,6 +13,10 @@ aa = a; # old a
@test isequal(a, aa)
@test hash(a) == hash(aa)

@test isequal(get_variables(a+aa+1), [a])

@test hash(a+b ~ c+d) == hash(a+b ~ c+d)

# test some matrix operations don't throw errors
X = [0 b c; d e f; g h i]
@test iszero(simplify(det(X) - ((d * ((b * i) - (c * h))) + (g * ((b * f) - (c * e))))))
Expand All @@ -22,7 +25,7 @@ F = lu(X)
R = simplify.(F.L * F.U - X[F.p, :], polynorm=true)
@test iszero(R)
@test simplify.(F \ X) == I
@test Symbolics._solve(X, X) == I
@test ModelingToolkit._solve(X, X, true) == I
inv(X)
qr(X)

Expand Down Expand Up @@ -53,24 +56,25 @@ D = sparse([1, 2], [2, 1], [d, d])

@test isequal(C * D, sparse([1,2], [1,2], [c * d, c * d]))

@variables t σ ρ β
@parameters t σ ρ β
@variables x(t) y(t) z(t)

D = Differential(t)
Dx = Differential(x)
Dy = Differential(y)
Dz = Differential(z)

eqs =*(y-x),
x*-z)-y,
x*y - β*z]
J = Num[Dx(eqs[1]) Dy(eqs[1]) Dz(eqs[1])
Dx(eqs[2]) Dy(eqs[2]) Dz(eqs[2])
Dx(eqs[3]) Dy(eqs[3]) Dz(eqs[3])]
eqs = [D(x) ~ σ*(y-x),
D(y) ~ x*-z)-y,
D(z) ~ x*y - β*z]
J = Num[Dx(eqs[1].rhs) Dy(eqs[1].rhs) Dz(eqs[1].rhs)
Dx(eqs[2].rhs) Dy(eqs[2].rhs) Dz(eqs[2].rhs)
Dx(eqs[3].rhs) Dy(eqs[3].rhs) Dz(eqs[3].rhs)]

J = expand_derivatives.(J)
using LinearAlgebra
luJ = lu(J,Val(false))

using ModelingToolkit
@variables M[1:2,1:2]
inv(M)

Expand All @@ -85,3 +89,43 @@ M \ reshape(b,2,1)
M = [1 a; 0 2]
M \ b
M \ [1, 2]

# test det
@variables X[1:4,1:4]
d1 = det(X, laplace=true)
d2 = det(X, laplace=false)
_det1 = eval(build_function(d1, X))
_det2 = eval(build_function(d2, X))
A = [1 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0]
@test _det1(A) == -1
@test _det2(A) == -1

@variables X[1:3,1:3]
d1 = det(X, laplace=true)
d2 = det(X, laplace=false)
_det1 = eval(build_function(d1, X))
_det2 = eval(build_function(d2, X))
A = [1 1 1
1 0 1
1 1 1]
@test _det1(A) == 0
@test _det2(A) == 0

@variables a b c d
z1 = a + b * im
z2 = c + d * im
@test z1 * 2 - Complex(2a, 2b) == 0
@test isequal(2z1, Complex(2a, 2b))
@test isequal(z1 / z1, 1)
@test isequal(z1 / z2, Complex((a*c + b*d)/(c^2 + d^2), (b*c - a*d)/(c^2 + d^2)))
@test isequal(1 / z2, Complex(c/(c^2 + d^2), -d/(c^2 + d^2)))
@test isequal(z1 * z2, Complex(a*c - b*d, a*d + b*c))
@test isequal(z1 - z2, Complex(a - c, b - d))
@test isequal(z1 + z2, Complex(a + c, b + d))
@test isequal(z1 + 2, Complex(a + 2, b))
@test isequal(2 + z1, Complex(2 + a, b))
@test isequal(z1 - 2, Complex(a - 2, b))
@test isequal(2 - z1, Complex(2 - a, -b))
8 changes: 7 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using SafeTestsets, Test

@safetestset "Differentiation Test" begin include("diff.jl") end
@safetestset "Array Test" begin include("array.jl") end
@safetestset "Overloading Test" begin include("overloads.jl") end

if haskey(ENV, "CI")
using Pkg
Pkg.add(url="https://github.com/SciML/ModelingToolkit.jl.git", rev="master")
Pkg.test("ModelingToolkit")
end

2 comments on commit df67c52

@YingboMa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/30900

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" df67c5267fa428173e6c5b5e495bd6c1f952127f
git push origin v0.1.0

Please sign in to comment.