-
Notifications
You must be signed in to change notification settings - Fork 152
bring back fixedsizearrays #138
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
Uh, this seems to still pass, but I pulled in newest master and it doesn't pass anymore... Base.ArgumentError(msg="Size mismatch in Static Array parameters. Got size Tuple{1,2}, dimension 2 and length 1.") |
Lol, just spent way too much time to figure out, that Line 42 in b1714d9
|
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 generally looks good, thanks!
Which parts of this do you still need? I'd like to think of the FixedSizeArrays
submodule as something we can eventually remove, and have everyone using the same fixed size API.
src/FixedSizeArrays.jl
Outdated
size_or{T}(::Type{$(name){TypeVar(:S), T}}, or) = or | ||
size_or{S}(::Type{$(name){S, TypeVar(:T)}}, or) = (S,) | ||
size_or{S, T}(::Type{$(name){S, T}}, or) = (S,) | ||
if VERSION < v"0.6.0-dev" |
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.
StaticArrays as a whole is now 0.6 only. Is there any use in having this version check?
end | ||
|
||
if L != tuple_prod(Size) || L < 0 || tuple_minimum(Size) < 0 || tuple_length(Size) != N | ||
throw(ArgumentError("Size mismatch in Static Array parameters. Got size $Size, dimension $N and length $L.")) | ||
return :(throw(ArgumentError("Size mismatch in Static Array parameters. Got size $Size, dimension $N and length $L."))) |
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 I'm still a bit confused about why this is absolutely necessary. But I'm not surprised that this is another concession required for the new @generated
rules :-)
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 also don't get why this helps... I had actually removed the quotes from the errors in most parts of the package because they seemed to not be required...
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 arguably it's better to throw an error early rather than late (ie, in the generator rather than the generated code - so to leave this without the quotes). I just figured it was some funky new limitation of @generated
... @SimonDanisch what exactly happens without this?
src/util.jl
Outdated
!isa(T, Type) && throw(ArgumentError("Static Array parameter T must be a type, got $T")) | ||
!isa(N.parameters[1], Int) && throw(ArgumenError("Static Array parameter N must be an integer, got $(N.parameters[1])")) | ||
!isa(L.parameters[1], Int) && throw(ArgumentError("Static Array parameter L must be an integer, got $(L.parameters[1])")) | ||
@generated function check_array_parameters(Size, T, N, L) |
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 don't think this needs to be @generated
, because this method only exists as a fallback signature for when the valid check_array_parameters
signature further down fails to match. So codegen does not need to be good for this one.
It took me five minutes to figure out why we even have two versions of check_array_parameters
though. Would be good to add a comment along the lines of
# This version of check_array_parameters() is a fallback signature to catch cases when invalid type
# parameters are passed. It exists only for improved error reporting and should not be called by
# correct code.
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.
Oh.... That probably wasn't intended... I got a bit confused because I started testing with an old version of master, where this was still a generated function...
src/StaticArrays.jl
Outdated
@@ -93,7 +93,7 @@ include("eigen.jl") | |||
include("cholesky.jl") | |||
include("deque.jl") | |||
|
|||
#include("FixedSizeArrays.jl") # Currently defunct | |||
include("FixedSizeArrays.jl") # Currently defunct |
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.
Obsolete comment.
All! I wouldn't mind to have this come as standard functionality of StaticArrays! |
Certainly it would be great to have any distinct functionality which still lives in here as part of StaticArrays proper, provided it doesn't conflict with |
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 all looks fine to me, with the exception of check_array_parameters
, which I'm still a bit suspicious of ;-)
src/util.jl
Outdated
(!isa(Size, DataType) || (Size.name !== Tuple.name)) && return throw(ArgumentError("Static Array parameter Size must be a Tuple type, got $Size")) | ||
!isa(T, Type) && return throw(ArgumentError("Static Array parameter T must be a type, got $T")) | ||
!isa(N.parameters[1], Int) && return throw(ArgumenError("Static Array parameter N must be an integer, got $(N.parameters[1])")) | ||
!isa(L.parameters[1], Int) && return throw(ArgumentError("Static Array parameter L must be an integer, got $(L.parameters[1])")) |
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.
These return
s don't do anything - leftovers from previous changes, I think?
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.
Yeah, ditch the return
s.
src/util.jl
Outdated
end | ||
|
||
@generated function check_array_parameters{Size,T,N,L}(::Type{Size}, ::Type{T}, ::Type{Val{N}}, ::Type{Val{L}}) | ||
function check_array_parameters{Size,T,N,L}(::Type{Size}, ::Type{T}, ::Type{Val{N}}, ::Type{Val{L}}) |
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 is the version of check_array_parameters()
which will be called, and I think there was a reason to have it as a @generated
function - it's fairly important that this does compile down to nothing in the case that the checks pass.
Did you check that this actually compiles down to nothing, even when it's not a generated function? I'd suggest you just leave this as it was, but include the fix you had before, to throw in the generated code, rather than in the generator itself.
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.
Oh I see where my confusion comes from... Only one of them where @generated
.
It's a pity, that Julia's dead code elimination just removes this in theory...
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.
Right, this is why I suggested adding that explanatory comment in my previous review of this PR ;-)
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.
Yeah this is a bit annoying. Generally the compiler tries to compute things which are either pure or "effect free" and perform dead branch elimination, but I think this function is just too complex. However inference is getting better all the time at this so its worth keeping an eye on in the future.
Not 100% sure about that, now that people should use isnan.(Vector) for element wise application, which should disambiguate this case... Also, I feel like there are tons of examples, where StaticVectors are rightfully treated as scalars. |
True, once 0.6 deprecations are of the way
Not at all, I'm fine merging it inside the |
Should we merge it as is and get rid of the fixedsizearray module in a later release? |
FYI the reductions generally take a function, like |
Simon - I'm happy that you have worked on this. Let's fix (revert?) |
Actually, can you explain the (Would it have been better to have generic bugfixes in a separate PR?) |
Tests have not been updated
Still having an inference problem in test/solve.jl. Can't reproduce, however.
Yes I guess... Problem is, it's much nicer (for me) to have all fixes for GeometryTypes/GLVisualize in one branch.... The change makes |
I thought so - got it! Base in v0.6 actually has a rather fancy implementation of |
ooooh, that'd be sweet :) I checked out utils.jl and only put the error in quotes for the generated function... otherwise the error looks just plain horrible! |
Thanks Simon, this looks a lot better 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.
This looks good to me now 👍
Okay, that was way too easy :D |
This needs a rebase |
Done! |
No description provided.