You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works but is not very ergonomic and also involves copying everything twice.
Because LazyTree is already iterable, I tried to get the following to work
julia> AwkwardArray.from_iter(t)
# errors because `to_layout` doesn't understand `LazyEvent`# so I implement this to say "LazyEvent is same as NamedTuple"
julia>function AwkwardArray.layout_for(x::Type{UnROOT.LazyEvent{T}}) where T
AwkwardArray.layout_for(T)
end
then I hit a infinite recursion:
ERROR: StackOverflowError:
Stacktrace:
[1] push!(a::AwkwardArray.RecordArray{(:Muon_phi, :Muon_pt, :Muon_eta), Tuple{…}, :default}, iter::UnROOT.LazyEvent)
@ Base ./array.jl:1186
[2] append!
@ AwkwardArray ~/.julia/dev/AwkwardArray/src/AwkwardArray.jl:150 [inlined]
--- the last 2 lines are repeated 52332 more times ---
[104667] push!(a::AwkwardArray.RecordArray{(:Muon_phi, :Muon_pt, :Muon_eta), Tuple{…}, :default}, iter::UnROOT.LazyEvent)
@ Base ./array.jl:1186
[104668] from_iter(input::LazyTree with 3 branches:
Muon_phi, Muon_pt, Muon_eta
)
@ AwkwardArray ~/.julia/dev/AwkwardArray/src/AwkwardArray.jl:2358
Some type information was truncated. Use `show(err)` to see complete types.
to me it all just means that:
we can probably use something that doesn't involve for ... push!() end
we need to change design of to_layout and from_iter a little bit to allow easy custom type
What I really want to do here is to tell AwkwardArray:
when you see evt::LazyEvent, you can just call collect(evt) first and you will get a NamedTuple which you know how to handle
The text was updated successfully, but these errors were encountered:
Moelf
changed the title
[feat] need Tables.jl interface compatible constructor
[feat] need better to_layout and from_iter design
Oct 13, 2023
# need a better name
AwkwardArray.akconvert(x) = x #default no-op
and then define from_iter to something like:
functionfrom_iter(input)
ItemType =eltype(input)
AwkwardType =layout_for(ItemType)
out =AwkwardType()
for item in input
push!(out, Awkward.akconvert(item))
end
out
end
and the user-facing interface/contract for custom type is: if you have a custom type, you need to specialize two functions:
AwkwardArray.layout_for(::Type{MyType}) which must return a type that is (eventually) recognized by Awkward
AwkwardArray.akconvert(x::MyType) which must convert to the same type as returned by 1
I'm test driving using a function from AK as a
sink
to UnROOT:This works but is not very ergonomic and also involves copying everything twice.
Because
LazyTree
is already iterable, I tried to get the following to workthen I hit a infinite recursion:
to me it all just means that:
for ... push!() end
to_layout
andfrom_iter
a little bit to allow easy custom typeWhat I really want to do here is to tell
AwkwardArray
:evt::LazyEvent
, you can just callcollect(evt)
first and you will get aNamedTuple
which you know how to handleThe text was updated successfully, but these errors were encountered: