From 054fd01e1f370d0b1b200e40db6185d882cbed2c Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Wed, 21 Feb 2024 14:15:17 -0500 Subject: [PATCH 1/4] `StateMachineOperator <: Real` for tracing and convenience --- src/equations.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/equations.jl b/src/equations.jl index 9739f51de..62c5934e2 100644 --- a/src/equations.jl +++ b/src/equations.jl @@ -33,7 +33,7 @@ end ### _nameof(s) = nameof(s) _nameof(s::Union{Int, Symbol}) = s -abstract type StateMachineOperator end +abstract type StateMachineOperator <: Real end hide_lhs(_::StateMachineOperator) = true struct InitialState <: StateMachineOperator s From d04c8cf8e185aed8b555668a81fd34e00be7bd4e Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Wed, 21 Feb 2024 14:25:37 -0500 Subject: [PATCH 2/4] Connection should be a scalar as well --- src/equations.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/equations.jl b/src/equations.jl index 62c5934e2..77be376ca 100644 --- a/src/equations.jl +++ b/src/equations.jl @@ -5,7 +5,7 @@ hide_lhs(_) = false ### ### Connection ### -struct Connection +struct Connection <: Real systems end Connection() = Connection(nothing) From b0d61aa746d75dda3fb182ad8633220947765c3a Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Wed, 21 Feb 2024 14:49:18 -0500 Subject: [PATCH 3/4] Add hashes --- src/equations.jl | 1 + src/struct.jl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/equations.jl b/src/equations.jl index 77be376ca..d27b0df7a 100644 --- a/src/equations.jl +++ b/src/equations.jl @@ -9,6 +9,7 @@ struct Connection <: Real systems end Connection() = Connection(nothing) +Base.hash(c::Connection, seed::UInt) = hash(c.systems, (0xc80093537bdc1311 % UInt) ⊻ seed) hide_lhs(_::Connection) = true function connect(sys1, sys2, syss...) diff --git a/src/struct.jl b/src/struct.jl index c96706d30..f829c7a5f 100644 --- a/src/struct.jl +++ b/src/struct.jl @@ -72,6 +72,11 @@ struct Struct <: Real v::Vector{StructElement} end +function Base.hash(x::Struct, seed::UInt) + h1 = hash(juliatype(x), seed) + h2 = foldr(hash, getelements(x), init = h1) + h2 ⊻ (0x0e39036b7de2101a % UInt) +end """ symstruct(T) From 450414a08a9736176e8016e068bdb762e830b314 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Wed, 21 Feb 2024 15:01:17 -0500 Subject: [PATCH 4/4] Connection and StateMachineOperator should behave like scalars --- src/equations.jl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/equations.jl b/src/equations.jl index d27b0df7a..58e5d4e4e 100644 --- a/src/equations.jl +++ b/src/equations.jl @@ -5,9 +5,10 @@ hide_lhs(_) = false ### ### Connection ### -struct Connection <: Real +struct Connection systems end +Base.broadcastable(x::Connection) = Ref(x) Connection() = Connection(nothing) Base.hash(c::Connection, seed::UInt) = hash(c.systems, (0xc80093537bdc1311 % UInt) ⊻ seed) hide_lhs(_::Connection) = true @@ -20,11 +21,13 @@ end function Base.show(io::IO, c::Connection) print(io, "connect(") - n = length(c.systems) - for (i, s) in enumerate(c.systems) - str = join(split(string(nameof(s)), NAMESPACE_SEPARATOR), '.') - print(io, str) - i != n && print(io, ", ") + if c.systems isa AbstractArray + n = length(c.systems) + for (i, s) in enumerate(c.systems) + str = join(split(string(nameof(s)), NAMESPACE_SEPARATOR), '.') + print(io, str) + i != n && print(io, ", ") + end end print(io, ")") end @@ -34,7 +37,8 @@ end ### _nameof(s) = nameof(s) _nameof(s::Union{Int, Symbol}) = s -abstract type StateMachineOperator <: Real end +abstract type StateMachineOperator end +Base.broadcastable(x::StateMachineOperator) = Ref(x) hide_lhs(_::StateMachineOperator) = true struct InitialState <: StateMachineOperator s