Skip to content

Commit ad7c920

Browse files
committed
Rename "topology" to "sharing"
1 parent 1034aca commit ad7c920

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

benchmark/benchmarks.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ function benchmark_utilities()
8585
options = Options(; binary_operators=[+, -, /, *], unary_operators=[cos, exp])
8686
for func_k in ("copy", "convert", "simplify_tree", "combine_operators")
8787
suite[func_k] = let s = BenchmarkGroup()
88-
for k in ("break_topology", "preserve_topology")
89-
k == "preserve_topology" &&
88+
for k in ("break_sharing", "preserve_sharing")
89+
k == "preserve_sharing" &&
9090
func_k in ("simplify_tree", "combine_operators") &&
9191
continue
9292

9393
f = if func_k == "copy"
94-
tree -> copy_node(tree; preserve_topology=(k == "preserve_topology"))
94+
tree -> copy_node(tree; preserve_sharing=(k == "preserve_sharing"))
9595
elseif func_k == "convert"
9696
if v_PACKAGE_VERSION >= v"0.6.1"
9797
tree -> convert(
9898
Node{Float64},
9999
tree;
100-
preserve_topology=(k == "preserve_topology"),
100+
preserve_sharing=(k == "preserve_sharing"),
101101
)
102102
else
103103
tree -> convert(Node{Float64}, tree)

src/Equation.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ using `convert(T1, tree.val)` at constant nodes.
7474
- `tree::Node{T2}`: Node to convert.
7575
"""
7676
function Base.convert(
77-
::Type{Node{T1}}, tree::Node{T2}; preserve_topology::Bool=false
77+
::Type{Node{T1}}, tree::Node{T2}; preserve_sharing::Bool=false
7878
) where {T1,T2}
7979
if T1 == T2
8080
return tree
8181
end
82-
if preserve_topology
82+
if preserve_sharing
8383
@use_idmap(_convert(Node{T1}, tree), IdDict{Node{T2},Node{T1}}())
8484
else
8585
_convert(Node{T1}, tree)
@@ -225,11 +225,11 @@ function set_node!(tree::Node{T}, new_tree::Node{T}) where {T}
225225
end
226226

227227
"""
228-
copy_node(tree::Node; preserve_topology::Bool=false)
228+
copy_node(tree::Node; preserve_sharing::Bool=false)
229229
230230
Copy a node, recursively copying all children nodes.
231231
This is more efficient than the built-in copy.
232-
With `preserve_topology=true`, this will also
232+
With `preserve_sharing=true`, this will also
233233
preserve linkage between a node and
234234
multiple parents, whereas without, this would create
235235
duplicate child node copies.
@@ -241,8 +241,8 @@ we can simply reference the existing copy.
241241
242242
Note that this will *not* preserve loops in graphs.
243243
"""
244-
function copy_node(tree::Node{T}; preserve_topology::Bool=false)::Node{T} where {T}
245-
if preserve_topology
244+
function copy_node(tree::Node{T}; preserve_sharing::Bool=false)::Node{T} where {T}
245+
if preserve_sharing
246246
@use_idmap(_copy_node(tree), IdDict{Node{T},Node{T}}())
247247
else
248248
_copy_node(tree)
@@ -406,7 +406,7 @@ end
406406

407407
function Base.:(==)(a::Node{T1}, b::Node{T2})::Bool where {T1,T2}
408408
T = promote_type(T1, T2)
409-
# TODO: Should also have preserve_topology check...
409+
# TODO: Should also have preserve_sharing check...
410410
return is_equal(convert(Node{T}, a), convert(Node{T}, b))
411411
end
412412

src/precompile.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ function test_functions_on_trees(::Type{T}, operators) where {T}
144144
tree = Node(i_bin, a8, a7)
145145
end
146146
tree = convert(Node{T}, tree)
147-
for preserve_topology in [true, false]
148-
tree = copy_node(tree; preserve_topology)
149-
set_node!(tree, copy_node(tree; preserve_topology))
147+
for preserve_sharing in [true, false]
148+
tree = copy_node(tree; preserve_sharing)
149+
set_node!(tree, copy_node(tree; preserve_sharing))
150150
end
151151

152152
string_tree(tree, operators)

test/test_equality.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ tree = x1 + x2 * x3 - log(x2 * 3.2) + 1.5 * cos(x2 / x1)
1414
same_tree = x1 + x2 * x3 - log(x2 * 3.2) + 1.5 * cos(x2 / x1)
1515
@test tree == same_tree
1616

17-
copied_tree = copy_node(tree; preserve_topology=true)
17+
copied_tree = copy_node(tree; preserve_sharing=true)
1818
@test tree == copied_tree
1919

20-
copied_tree2 = copy_node(tree; preserve_topology=false)
20+
copied_tree2 = copy_node(tree; preserve_sharing=false)
2121
@test tree == copied_tree2
2222

2323
modifed_tree = x1 + x2 * x1 - log(x2 * 3.2) + 1.5 * cos(x2 / x1)

test/test_preserve_multiple_parents.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,42 @@ include("test_params.jl")
2626
@test tree.l.l === tree.r
2727
@test hash(tree.l.l) == hash(tree.r)
2828

29-
# When we copy with the normal copy, the topology breaks:
30-
copy_without_topology = copy_node(tree)
31-
@test !(copy_without_topology.l.l === copy_without_topology.r)
29+
# When we copy with the normal copy, the sharing breaks:
30+
copy_without_sharing = copy_node(tree)
31+
@test !(copy_without_sharing.l.l === copy_without_sharing.r)
3232

33-
# But with the topology preserved in the copy, it should be the same:
34-
copy_with_topology = copy_node(tree; preserve_topology=true)
35-
@test copy_with_topology.l.l === copy_with_topology.r
33+
# But with the sharing preserved in the copy, it should be the same:
34+
copy_with_sharing = copy_node(tree; preserve_sharing=true)
35+
@test copy_with_sharing.l.l === copy_with_sharing.r
3636

3737
# We can also tweak the new tree, and the edits should be propagated:
38-
copied_base_tree = copy_with_topology.l.l
38+
copied_base_tree = copy_with_sharing.l.l
3939
# (First, assert that it is the same as the old base tree)
4040
@test string_tree(copied_base_tree, operators) == string_tree(base_tree, operators)
4141

4242
# Now, let's tweak the new tree's base tree:
4343
copied_base_tree.l.l = x1 * x2 * 5.2 - exp(x3)
4444
# "exp" should appear *twice* now:
45-
copy_with_topology
46-
@test length(collect(eachmatch(r"exp", string_tree(copy_with_topology, operators)))) ==
45+
copy_with_sharing
46+
@test length(collect(eachmatch(r"exp", string_tree(copy_with_sharing, operators)))) ==
4747
2
48-
@test copy_with_topology.l.l === copy_with_topology.r
49-
@test hash(copy_with_topology.l.l) == hash(copy_with_topology.r)
50-
@test string_tree(copy_with_topology.l.l, operators) !=
48+
@test copy_with_sharing.l.l === copy_with_sharing.r
49+
@test hash(copy_with_sharing.l.l) == hash(copy_with_sharing.r)
50+
@test string_tree(copy_with_sharing.l.l, operators) !=
5151
string_tree(base_tree, operators)
5252

5353
# We also test whether `convert` breaks shared children.
5454
# The node type here should be Float64.
5555
@test typeof(tree).parameters[1] == Float64
5656
# Let's convert to Float32:
57-
float32_tree = convert(Node{Float32}, tree; preserve_topology=true)
57+
float32_tree = convert(Node{Float32}, tree; preserve_sharing=true)
5858
@test typeof(float32_tree).parameters[1] == Float32
5959
# The linkage should be kept:
6060
@test float32_tree.l.l === float32_tree.r
6161
end
6262

6363
# We also do tests of the macros related to generating functions that preserve
64-
# topology:
64+
# sharing:
6565
expr_eql(x::LineNumberNode, y::LineNumberNode) = true # Ignore line numbers
6666
expr_eql(x::QuoteNode, y::QuoteNode) = x == y
6767
expr_eql(x::Number, y::Number) = x == y

test/test_simplification.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ output3, flag3 = eval_tree_array(tree_copy2, X, operators)
9494
operators = OperatorEnum(; binary_operators=(+, -, *, /))
9595
base_tree = Node(1, Node(; val=0.3), Node(; val=0.2))
9696
tree = x1 * base_tree + base_tree
97-
simplify_tree(tree, operators; preserve_topology=true)
97+
simplify_tree(tree, operators; preserve_sharing=true)
9898
@test tree.l.r === tree.r
9999

100100
base_tree = (x1 + Node(; val=0.3)) + Node(; val=0.2)
101101
true_simplification_value = 0.5
102102
tree = x2 * base_tree + base_tree
103-
combine_operators(tree, operators; preserve_topology=true)
103+
combine_operators(tree, operators; preserve_sharing=true)
104104
# Should not combine twice!
105105
@test tree.l.r.r.val == true_simplification_value
106106

test/unittest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ end
6262
include("test_hash.jl")
6363
end
6464

65-
@safetestset "Test topology-preserving copy" begin
65+
@safetestset "Test sharing-preserving copy" begin
6666
include("test_preserve_multiple_parents.jl")
6767
end
6868

0 commit comments

Comments
 (0)