-
Notifications
You must be signed in to change notification settings - Fork 22
WIP add constructors for base array wrappers #36
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #36 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 2 +1
Lines 38 60 +22
=========================================
+ Hits 38 60 +22
Continue to review full report at Codecov.
|
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 think we can have this. It is a bit tough since it forces us to decide more precisely whether we want constructorof(obj)(public_fields...)
or constructorof(public_and_private_fields...)
.
I am not sure, what's the right decision there, but I am okay with merging this and we will see later how it plays out.
Alternatively, we could also include a propertyvalues
function, which by default returns all the fields, and specify
constructorof(obj)(propertyvalues(obj)...) == obj
I was thinking about a |
Ok lets go this path. How about a slight tweak. Instead of @generated function properties(obj)
fnames = fieldnames(obj)
fvals = map(fnames) do fname
Expr(:call, :getproperty, :obj, QuoteNode(fname))
end
fvals = Expr(:tuple, fvals...)
:(NamedTuple{$fnames}($fvals))
end
struct S;a;b;end
s = S(1,2)
properties(s)
(a = 1, b = 2) You can still splat it into a function call, like it was a tuple. S(properties(s)...)
S(1,2) But it has nicer symmetry with |
That looks good to me. Maybe we can call it |
|
9a04691
to
b65b8f2
Compare
This is updated to use the changes in the getproperties PR, and can be merged once that is rebased into master. |
b65b8f2
to
8941417
Compare
This is ready to rebase. |
7b98ff5
to
dce6a09
Compare
Made some changes to the tests if you want to hit merge if you're happy with them. I guess we should do a minor version bump after that. |
Some
constructorof
methods for Base and LinearAlgebra array wrappers, as discussed in #34.Probably we shouldn't add a constructor for
Tridiagonal
because of the undef field - seems it would break Accessors.jl/Flatten.jl etc?I'm not sure what to do about it long-term, possibly a PR to base using
nothing
instead ofundef
fordu2
? How many other structs have undef fields?Closes #34
There are probably a bunch of other base objects that need
constuctorof
methods. Feel free to list more for me to add to this PR.