-
Notifications
You must be signed in to change notification settings - Fork 37
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
make pick
more useful
#44
Conversation
If the case of manually writing out the desired fields is important, we could do it very efficiently with a macro
To extend that to Columns, we could instead expand to
where
or something along those lines. |
That's a neat idea! Gives us a chance to generate the required output type during macro expansion time (esp. since it's not possible with We specialize |
c72ef63
to
4276963
Compare
I've updated the PR. Added |
Tests now pass except on OSX nightly (same problem of missing native library or something). |
src/utils.jl
Outdated
tup = if all([isa(x, Symbol) for x in ex]) | ||
# Named tuple | ||
T = NamedTuples.create_tuple([x for x in ex]) | ||
:(NamedTuples.$T($([:(getfield(x, $(Expr(:quote, f)))) for f in ex]...))) |
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.
This line fails in a multi-process situation because the symbol $T only gets defined on the master process... This can be fixed by adding @everywhere
to the previous line, but do we want to do such things during macro expansion??
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.
If the new type gets eval'd in Main
then it will be sent to other processes, which would be good for now. Related to JuliaData/NamedTuples.jl#27 (comment) --- that change to NamedTuples might help fix things like this more comprehensively.
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.
it will be sent to other processes
I'm trying to make this change to NamedTuples but it doesn't look like we can send new types on release-0.6
branch of Julia:
> jl -p 1
julia> struct Foo
x
end
julia> remotecall_fetch(identity, 2, Foo("x"))
ERROR: On worker 2:
UndefVarError: Foo not defined
deserialize_datatype at ./serialize.jl:861
handle_deserialize at ./serialize.jl:601
deserialize at ./serialize.jl:571
ntuple at ./tuple.jl:108
handle_deserialize at ./serialize.jl:592
deserialize_msg at ./distributed/messages.jl:100
deserialize_msg at ./distributed/messages.jl:110
message_handler_loop at ./distributed/process_messages.jl:161
process_tcp_streams at ./distributed/process_messages.jl:118
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.
Doesn't https://github.com/JuliaLang/julia/blob/50c2a378ba2171250b9bee04d4ea63eb1f348932/base/serialize.jl#L487-L504 only work for functions? I don't think we ever sent type definitions automatically.
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.
Oops, you're right. We should actually try to rely on the serialize
method we've added for NamedTuple types (which is in JuliaDB, but should be moved to NamedTuples).
It would also be nice if this macro could do less work. Ideally it should expand to a @NT(...)
expression, i.e. expand to exactly what you'd write if the macro didn't exist, instead of using NamedTuple internals.
To make all that work, we could have NamedTuples put the type it creates directly into its macro output, instead of generating a GlobalRef.
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 was using @NT
but running into some problem I can't remember now, but it was about creating the correct expression. I guess I needed to use Expr(:macrocall,...)
instead of :(@NT(...))
, will try again, thanks.
type it creates directly into its macro output
Can we use @NT
inside a function then?
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.
Yes, it should fix that. I'll work on a NamedTuples PR.
src/utils.jl
Outdated
@@ -56,11 +58,51 @@ end | |||
|
|||
# family of projection functions | |||
|
|||
immutable Proj{field}; end | |||
immutable Proj{F} | |||
f::F |
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 find this definition very confusing. A Proj{f}()
is supposed to be a function that selects field f
, period. Anything else should be a different type.
Also I realize the definition for (p::Proj)(c::Columns)
isn't really right anymore, and should be a method of broadcast now.
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.
Okay, I can separate this out into a ProjFunction
type. Right now I use Val{f}
for the case you mentioned above.
(p::Proj)(c::Columns)
can be removed.
should be a method of broadcast now.
And map
too right?
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.
Yes.
Updated. Works in the multi-process case with JuliaData/NamedTuples.jl#34 , but safe to merge here as-is. |
Codecov Report
@@ Coverage Diff @@
## master #44 +/- ##
==========================================
+ Coverage 91.98% 92.77% +0.78%
==========================================
Files 6 6
Lines 836 844 +8
==========================================
+ Hits 769 783 +14
+ Misses 67 61 -6
Continue to review full report at Codecov.
|
The multiple column version is not inferable in the case the columns are of different types. That can be fixed by using
Base.@pure
if required.