-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Traversal order of Recursive
#143
Comments
I think the only achievable order is determined by whatever the passed Btw, using |
That sounds good. Do
I feel this interface is related to Transducers which makes me think it's going to eventually become parallel so order is going to become indeterminate for code like this or similar. julia> let i = 0
modify((;a=10, b=20), @o _ |> Elements()) do x
i += 1
end
end
(a = 1, b = 2) |
It is not documented, but I agree with what @aplavin said:
|
@jariji if you have some specific usecases in mind, that would benefit from well-defined traversal order or from parallelization, I'd be curious to hear about them :) Also, for more traversal options, see julia> obj = (a=1, b=(c=2, d=3))
# don't step into matching elements:
julia> modify(Dict∘pairs, obj, RecursiveOfType(NamedTuple))
Dict{Symbol, Any} with 2 entries:
:a => 1
:b => (c = 2, d = 3)
# step into matches as well:
julia> modify(Dict∘pairs, obj, RecursiveOfType(NamedTuple, order=:pre)) # here, :post would be the same
Dict{Symbol, Any} with 2 entries:
:a => 1
:b => Dict(:d=>3, :c=>2) |
There are plenty of other ways to do this that don't rely on order, but here's a use case that came to mind. Optim.optimize wants an array, so one way to turn a struct into an array and back is
That relies on the traversal going the same way both times.
All the parallel monoid operations we often do on vectors are quite tree-shaped. Eg summing up the nodes in a tree, searching an XML/HTML/JSON tree for a pattern. |
The first (optimization) case is very convenient with
Oh, this is a weaker and totally reasonable guarantee to have (in sequential code) – to avoid any potential confusion. That is, "modify() can traverse in any order, but the order remains the same for multiple calls".
Does summing (or another simple operation) really benefits from multithreading? I thought they are really memory-access-limited. |
Alright. getall/setall might want to document that they traverse in the same order as each other.
Good point. What happens if setall adds new nodes: which properties of the traversal order are preserved: order, distance, etc?
Maybe. If the cpu is waiting for x.a to arrive it could simultaneously work on x.b. |
What are "new nodes"? I don't think |
If we have Are we guaranteed breadth-first traversal? |
Wdym by breath-first here, could you give a more complete explanation/code example? |
I'm not sure what I meant.... |
Are there any guarantees on the traversal order of
Recursive
?The text was updated successfully, but these errors were encountered: