Skip to content

Commit 8cb9c8a

Browse files
committed
Formatting
1 parent d5b329e commit 8cb9c8a

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

src/Equation.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ constructorof(::Type{N}) where {N<:AbstractNode} = Base.typename(N).wrapper
131131
constructorof(::Type{<:Node}) = Node
132132
constructorof(::Type{<:GraphNode}) = GraphNode
133133

134-
with_type_parameters(::Type{N}, ::Type{T}) where {N<:AbstractExpressionNode,T} = constructorof(N){T}
134+
function with_type_parameters(::Type{N}, ::Type{T}) where {N<:AbstractExpressionNode,T}
135+
return constructorof(N){T}
136+
end
135137
with_type_parameters(::Type{<:Node}, ::Type{T}) where {T} = Node{T}
136138
with_type_parameters(::Type{<:GraphNode}, ::Type{T}) where {T} = GraphNode{T}
137139

src/EquationUtils.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,16 @@ struct NodeIndex{T} <: AbstractNode
117117
NodeIndex(::Type{_T}) where {_T} = new{_T}(0, zero(_T))
118118
NodeIndex(::Type{_T}, val) where {_T} = new{_T}(0, convert(_T, val))
119119
NodeIndex(::Type{_T}, l::NodeIndex) where {_T} = new{_T}(1, zero(_T), l)
120-
NodeIndex(::Type{_T}, l::NodeIndex, r::NodeIndex) where {_T} = new{_T}(2, zero(_T), l, r)
120+
function NodeIndex(::Type{_T}, l::NodeIndex, r::NodeIndex) where {_T}
121+
return new{_T}(2, zero(_T), l, r)
122+
end
121123
end
122124
# Sharing is never needed for NodeIndex,
123125
# as we trace over the node we are indexing on.
124126
preserve_sharing(::Type{<:NodeIndex}) = false
125127
function Base.copy(node::NodeIndex{T}) where {T}
126128
return tree_mapreduce(
127-
t -> NodeIndex(T, t.val),
128-
(_, c...) -> NodeIndex(T, c...),
129-
node,
130-
NodeIndex{T};
129+
t -> NodeIndex(T, t.val), (_, c...) -> NodeIndex(T, c...), node, NodeIndex{T};
131130
)
132131
end
133132

src/base.jl

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ Apply a function to each node in a tree.
227227
"""
228228
function foreach(f::Function, tree::AbstractNode; break_sharing::Val=Val(false))
229229
tree_mapreduce(
230-
t -> (@inline(f(t)); nothing),
231-
Returns(nothing),
232-
tree,
233-
Nothing;
234-
break_sharing,
230+
t -> (@inline(f(t)); nothing), Returns(nothing), tree, Nothing; break_sharing
235231
)
236232
return nothing
237233
end
@@ -245,8 +241,11 @@ specifying the `result_type` of `map_fnc` so the resultant array can
245241
be preallocated.
246242
"""
247243
function filter_map(
248-
filter_fnc::F, map_fnc::G, tree::AbstractNode, result_type::Type{GT};
249-
break_sharing::Val=Val(false)
244+
filter_fnc::F,
245+
map_fnc::G,
246+
tree::AbstractNode,
247+
result_type::Type{GT};
248+
break_sharing::Val=Val(false),
250249
) where {F<:Function,G<:Function,GT}
251250
stack = Array{GT}(undef, count(filter_fnc, tree; init=0, break_sharing))
252251
filter_map!(filter_fnc, map_fnc, stack, tree; break_sharing)
@@ -259,8 +258,11 @@ end
259258
Equivalent to `filter_map`, but stores the results in a preallocated array.
260259
"""
261260
function filter_map!(
262-
filter_fnc::Function, map_fnc::Function, destination::Vector{GT}, tree::AbstractNode;
263-
break_sharing::Val=Val(false)
261+
filter_fnc::Function,
262+
map_fnc::Function,
263+
destination::Vector{GT},
264+
tree::AbstractNode;
265+
break_sharing::Val=Val(false),
264266
) where {GT}
265267
pointer = Ref(0)
266268
foreach(tree; break_sharing) do t
@@ -291,15 +293,19 @@ end
291293
Map a function over a tree and return a flat array of the results in depth-first order.
292294
Pre-specifying the `result_type` of the function can be used to avoid extra allocations.
293295
"""
294-
function map(f::F, tree::AbstractNode, result_type::Type{RT}=Nothing; break_sharing::Val=Val(false)) where {F<:Function,RT}
296+
function map(
297+
f::F, tree::AbstractNode, result_type::Type{RT}=Nothing; break_sharing::Val=Val(false)
298+
) where {F<:Function,RT}
295299
if RT == Nothing
296300
return f.(collect(tree; break_sharing))
297301
else
298302
return filter_map(Returns(true), f, tree, result_type; break_sharing)
299303
end
300304
end
301305

302-
function count(f::F, tree::AbstractNode; init=0, break_sharing::Val=Val(false)) where {F<:Function}
306+
function count(
307+
f::F, tree::AbstractNode; init=0, break_sharing::Val=Val(false)
308+
) where {F<:Function}
303309
return tree_mapreduce(
304310
t -> @inline(f(t)) ? 1 : 0,
305311
+,
@@ -348,11 +354,15 @@ function mapreduce(
348354
if preserve_sharing(typeof(tree))
349355
@assert typeof(return_type) !== Undefined "Must specify `return_type` as a keyword argument to `mapreduce` if `preserve_sharing` is true."
350356
end
351-
return tree_mapreduce(f, (n...) -> reduce(op, n), tree, return_type; f_on_shared, break_sharing)
357+
return tree_mapreduce(
358+
f, (n...) -> reduce(op, n), tree, return_type; f_on_shared, break_sharing
359+
)
352360
end
353361

354362
isempty(::AbstractNode) = false
355-
iterate(root::AbstractNode) = (root, collect(root; break_sharing=Val(true))[(begin + 1):end])
363+
function iterate(root::AbstractNode)
364+
return (root, collect(root; break_sharing=Val(true))[(begin + 1):end])
365+
end
356366
iterate(::AbstractNode, stack) = isempty(stack) ? nothing : (popfirst!(stack), stack)
357367
in(item, tree::AbstractNode) = any(t -> t == item, tree)
358368
function length(tree::AbstractNode; break_sharing::Val=Val(false))

test/test_graphs.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,14 @@ end
260260
end
261261

262262
@testset "Hashing" begin
263-
x = GraphNode(feature=1)
264-
x2 = GraphNode(feature=1)
263+
x = GraphNode(; feature=1)
264+
x2 = GraphNode(; feature=1)
265265
tree = GraphNode(1, x, x)
266266
tree2 = GraphNode(1, x2, x2)
267267
@test hash(tree) == hash(tree2)
268268
@test hash(tree) != hash(copy_node(tree; break_sharing=Val(true)))
269-
@test hash(copy_node(tree; break_sharing=Val(true))) == hash(copy_node(tree; break_sharing=Val(true)))
269+
@test hash(copy_node(tree; break_sharing=Val(true))) ==
270+
hash(copy_node(tree; break_sharing=Val(true)))
270271
@test hash(Node(tree)) == hash(copy_node(tree; break_sharing=Val(true)))
271272
end
272273

@@ -309,7 +310,7 @@ end
309310
end
310311

311312
@testset "Various base utils" begin
312-
x = GraphNode(feature=1)
313+
x = GraphNode(; feature=1)
313314
tree = GraphNode(1, x, x)
314315
@test collect(tree) == [tree, x]
315316
@test collect(tree; break_sharing=Val(true)) == [tree, x, x]

0 commit comments

Comments
 (0)