-
Notifications
You must be signed in to change notification settings - Fork 45
Allow StructArray arguments in CUDAnative kernels. #87
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,20 +28,50 @@ else | |
| const _getproperty = getproperty | ||
| end | ||
|
|
||
| function _foreachfield(names, xs) | ||
| function _sstuple(::Type{<:NTuple{N, Any}}) where {N} | ||
| ntuple(j->Symbol(j), N) | ||
| end | ||
|
|
||
| function _sstuple(::Type{NT}) where {NT<:NamedTuple} | ||
| _map_params(x->_sstuple(staticschema(x)), NT) | ||
| end | ||
|
|
||
| function _getcolproperties!(exprs, s, es=[]) | ||
| if typeof(s) <: Symbol | ||
| push!(exprs, es) | ||
| return | ||
| end | ||
| for key in keys(s) | ||
| _getcolproperties!(exprs, getproperty(s,key), vcat(es, key)) | ||
| end | ||
| end | ||
|
|
||
| @generated function foreachfield(::Type{T}, f, xs...) where {T<:Tup} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This introduces a lot of code complexity, while the original implementation is just a few lines of code: I'm not completely sure I understand conceptually what this refactor is trying to do. Is there an intuitive explanation as to way the original |
||
| # TODO get columnsproperties directly from T without converting to the | ||
| # tuple s. | ||
| s = _sstuple(T) | ||
| columnsproperties = [] | ||
| _getcolproperties!(columnsproperties, s) | ||
|
|
||
| exprs = Expr[] | ||
| for field in names | ||
| sym = QuoteNode(field) | ||
| args = [Expr(:call, :_getproperty, :(getfield(xs, $j)), sym) for j in 1:length(xs)] | ||
| for col in columnsproperties | ||
| args = Expr[] | ||
| for prop in col | ||
| sym = QuoteNode(prop) | ||
| if length(args) == 0 | ||
| args = [Expr(:call, :_getproperty, :(getfield(xs, $j)), sym) for j in 1:length(xs)] | ||
| else | ||
| for j in 1:length(xs) | ||
| args[j] = Expr(:call, :_getproperty, args[j], sym) | ||
| end | ||
| end | ||
| end | ||
| push!(exprs, Expr(:call, :f, args...)) | ||
| end | ||
| push!(exprs, :(return nothing)) | ||
| return Expr(:block, exprs...) | ||
| end | ||
|
|
||
| @generated foreachfield(::Type{<:NamedTuple{names}}, f, xs...) where {names} = _foreachfield(names, xs) | ||
| @generated foreachfield(::Type{<:NTuple{N, Any}}, f, xs...) where {N} = _foreachfield(Base.OneTo(N), xs) | ||
|
|
||
| foreachfield(f, x::T, xs...) where {T} = foreachfield(staticschema(T), f, x, xs...) | ||
|
|
||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to be
But the generated function works as well.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried
but still got a dynamic function
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, I would prefer a normal function over a generated function. What is the cause of "dynamic function invocation"?
Is it due to theNever mind, splatting seems fine.I...splatting?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it would be nice to avoid generated functions. I am not sure why this has to be generated but there is definitely something wrong with what I did for
foreachfieldas the test suite doesn't pass. Maybe that is causing issues. If you get a chance, could you take a peak at what I did and see if you can spot something astray?