Skip to content

Commit f0e245b

Browse files
committed
Add docs for display helper structs
1 parent 33a045f commit f0e245b

File tree

2 files changed

+76
-8
lines changed

2 files changed

+76
-8
lines changed

ext/MTKDeepDiffsExt.jl

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ using ModelingToolkit.BipartiteGraphs: Label, BipartiteAdjacencyList, unassigned
55
using ModelingToolkit.SystemStructures: SystemStructure, MatchedSystemStructure,
66
SystemStructurePrintMatrix, HighlightInt
77

8+
"""
9+
A utility struct for displaying the difference between two HighlightInts.
10+
11+
# Example
12+
```julia
13+
using ModelingToolkit, DeepDiffs
14+
15+
old_i = HighlightInt(1, :default, true)
16+
new_i = HighlightInt(2, :default, false)
17+
diff = HighlightIntDiff(new_i, old_i)
18+
19+
show(diff)
20+
```
21+
"""
822
struct HighlightIntDiff
923
new::HighlightInt
1024
old::HighlightInt
@@ -26,6 +40,21 @@ function Base.show(io::IO, d::HighlightIntDiff)
2640
(d.new.match || d.old.match) && printstyled(io, ")", color = p_color)
2741
end
2842

43+
"""
44+
A utility struct for displaying the difference between two
45+
BipartiteAdjacencyList's.
46+
47+
# Example
48+
```julia
49+
using ModelingToolkit, DeepDiffs
50+
51+
old = BipartiteAdjacencyList(...)
52+
new = BipartiteAdjacencyList(...)
53+
diff = BipartiteAdjacencyListDiff(new, old)
54+
55+
show(diff)
56+
```
57+
"""
2958
struct BipartiteAdjacencyListDiff
3059
new::BipartiteAdjacencyList
3160
old::BipartiteAdjacencyList
@@ -77,6 +106,21 @@ function Base.show(io::IO, l::BipartiteAdjacencyListDiff)
77106
end
78107
end
79108

109+
"""
110+
A utility struct for displaying the difference between two Labels
111+
in git-style red/green highlighting.
112+
113+
# Example
114+
```julia
115+
using ModelingToolkit, DeepDiffs
116+
117+
old = Label("before")
118+
new = Label("after")
119+
diff = LabelDiff(new, old)
120+
121+
show(diff)
122+
```
123+
"""
80124
struct LabelDiff
81125
new::Label
82126
old::Label
@@ -91,19 +135,27 @@ function Base.show(io::IO, l::LabelDiff)
91135
end
92136
end
93137

138+
"""
139+
A utility struct for displaying the difference between two
140+
(Matched)SystemStructure's in git-style red/green highlighting.
141+
142+
# Example
143+
```julia
144+
using ModelingToolkit, DeepDiffs
145+
146+
old = SystemStructurePrintMatrix(...)
147+
new = SystemStructurePrintMatrix(...)
148+
diff = SystemStructureDiffPrintMatrix(new, old)
149+
150+
show(diff)
151+
```
152+
"""
94153
struct SystemStructureDiffPrintMatrix <:
95154
AbstractMatrix{Union{LabelDiff, BipartiteAdjacencyListDiff}}
96155
new::SystemStructurePrintMatrix
97156
old::SystemStructurePrintMatrix
98157
end
99158

100-
function DeepDiffs.deepdiff(old::Union{MatchedSystemStructure, SystemStructure},
101-
new::Union{MatchedSystemStructure, SystemStructure})
102-
new_sspm = SystemStructurePrintMatrix(new)
103-
old_sspm = SystemStructurePrintMatrix(old)
104-
Base.print_matrix(stdout, SystemStructureDiffPrintMatrix(new_sspm, old_sspm))
105-
end
106-
107159
function Base.size(ssdpm::SystemStructureDiffPrintMatrix)
108160
max.(Base.size(ssdpm.new), Base.size(ssdpm.old))
109161
end
@@ -123,4 +175,11 @@ function Base.getindex(ssdpm::SystemStructureDiffPrintMatrix, i::Integer, j::Int
123175
end
124176
end
125177

178+
function DeepDiffs.deepdiff(old::Union{MatchedSystemStructure, SystemStructure},
179+
new::Union{MatchedSystemStructure, SystemStructure})
180+
new_sspm = SystemStructurePrintMatrix(new)
181+
old_sspm = SystemStructurePrintMatrix(old)
182+
Base.print_matrix(stdout, SystemStructureDiffPrintMatrix(new_sspm, old_sspm))
183+
end
184+
126185
end # module

src/systems/systemstructure.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ..ModelingToolkit: isdiffeq, var_from_nested_derivative, vars!, flatten,
1212
equations, isirreducible, input_timedomain, TimeDomain,
1313
VariableType, getvariabletype
1414
using ..BipartiteGraphs
15-
import ..BipartiteGraphs: invview, complete, HighlightInt
15+
import ..BipartiteGraphs: invview, complete
1616
using Graphs
1717
using UnPack
1818
using Setfield
@@ -393,6 +393,11 @@ struct SystemStructurePrintMatrix <:
393393
eq_to_diff::DiffGraph
394394
var_eq_matching::Union{Matching, Nothing}
395395
end
396+
397+
"""
398+
Create a SystemStructurePrintMatrix to display the contents
399+
of the provided SystemStructure.
400+
"""
396401
function SystemStructurePrintMatrix(s::SystemStructure)
397402
return SystemStructurePrintMatrix(complete(s.graph),
398403
complete(s.solvable_graph),
@@ -469,6 +474,10 @@ struct MatchedSystemStructure
469474
var_eq_matching::Matching
470475
end
471476

477+
"""
478+
Create a SystemStructurePrintMatrix to display the contents
479+
of the provided MatchedSystemStructure.
480+
"""
472481
function SystemStructurePrintMatrix(ms::MatchedSystemStructure)
473482
return SystemStructurePrintMatrix(complete(ms.structure.graph),
474483
complete(ms.structure.solvable_graph),

0 commit comments

Comments
 (0)