Skip to content

Commit 77307fe

Browse files
fix and test LabelledArrays in OOP
1 parent d440864 commit 77307fe

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
1212
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1313
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1414
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
15+
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
1516
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
1617
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1718
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ModelingToolkit
22

33
using DiffEqBase, Distributed
4-
using StaticArrays, LinearAlgebra, SparseArrays
4+
using StaticArrays, LinearAlgebra, SparseArrays, LabelledArrays
55
using Latexify, Unitful, ArrayInterface
66
using MacroTools
77
using UnPack: @unpack

src/build_function.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ function _build_function(target::JuliaTarget, rhss, args...;
331331
arr_sys_expr = build_expr(:vect, [conv(rhs) for rhs rhss])
332332
end
333333

334-
arr_sys_expr = !(typeof(rhss) <: SparseMatrixCSC || eltype(rhss) <: Number) ? quote
335-
convert(typeof($(fargs.args[1])),if typeof($(fargs.args[1])) <: Union{SArray,SLArray}
334+
arr_sys_expr = !(typeof(rhss) <: SparseMatrixCSC || eltype(rhss) <: AbstractArray) ? quote
335+
convert(typeof($(fargs.args[1])),if typeof($(fargs.args[1])) <: Union{StaticArrays.SArray,ModelingToolkit.LabelledArrays.SLArray}
336336
@SArray $arr_sys_expr
337337
else
338338
$arr_sys_expr

test/labelledarrays.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using ModelingToolkit, StaticArrays, LinearAlgebra, LabelledArrays
2+
using DiffEqBase
3+
using Test
4+
5+
# Define some variables
6+
@parameters t σ ρ β
7+
@variables x(t) y(t) z(t)
8+
@derivatives D'~t
9+
10+
# Define a differential equation
11+
eqs = [D(x) ~ σ*(y-x),
12+
D(y) ~ x*-z)-y,
13+
D(z) ~ x*y - β*z]
14+
15+
de = ODESystem(eqs)
16+
f = ODEFunction(de, [x,y,z], [σ,ρ,β])
17+
18+
a = @SVector [1.0,2.0,3.0]
19+
b = SLVector(x=1.0,y=2.0,z=3.0)
20+
c = [1.0,2.0,3.0]
21+
p = SLVector=10.0=26.0=8/3)
22+
@test f(a,p,0.0) isa SVector
23+
@test typeof(f(b,p,0.0)) <: SLArray
24+
@test f(c,p,0.0) isa Vector
25+
@test f(a,p,0.0) == f(b,p,0.0)
26+
@test f(a,p,0.0) == f(c,p,0.0)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using SafeTestsets, Test
77
@safetestset "Direct Usage Test" begin include("direct.jl") end
88
@safetestset "Build Function Test" begin include("build_function.jl") end
99
@safetestset "ODESystem Test" begin include("odesystem.jl") end
10+
@safetestset "LabelledArrays Test" begin include("labelledarrays.jl") end
1011
@safetestset "Mass Matrix Test" begin include("mass_matrix.jl") end
1112
@safetestset "SteadyStateSystem Test" begin include("steadystatesystems.jl") end
1213
@safetestset "SDESystem Test" begin include("sdesystem.jl") end

0 commit comments

Comments
 (0)