Skip to content

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

Merged
merged 16 commits into from
Apr 24, 2017
Merged

bring back fixedsizearrays #138

merged 16 commits into from
Apr 24, 2017

Conversation

SimonDanisch
Copy link
Member

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 69.191% when pulling d588e60 on sd/fixedsizearrays into 8d3ec32 on master.

@SimonDanisch
Copy link
Member Author

Uh, this seems to still pass, but I pulled in newest master and it doesn't pass anymore...
Also master doesn't pass on newest Julia master. Is there some branch fixing this that I should include here?
Error:

Base.ArgumentError(msg="Size mismatch in Static Array parameters. Got size Tuple{1,2}, dimension 2 and length 1.")

@andyferris @c42f @Keno

@SimonDanisch
Copy link
Member Author

Lol, just spent way too much time to figure out, that test_broken exists, doesn't leave a stacktrace, but turns up as a broken test in the summary -.-
I think I fixed the errors I mention above by putting the error message of the generated function in quotes:

function check_array_parameters(Size, T, N, L)
, so that they don't make the body of the staged function impure!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 70.213% when pulling 6b6f519 on sd/fixedsizearrays into 8d3ec32 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 70.274% when pulling 2433157 on sd/fixedsizearrays into 8d3ec32 on master.

Copy link
Member

@c42f c42f left a 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.

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"
Copy link
Member

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.")))
Copy link
Member

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 :-)

Copy link
Member

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...

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

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...

@@ -93,7 +93,7 @@ include("eigen.jl")
include("cholesky.jl")
include("deque.jl")

#include("FixedSizeArrays.jl") # Currently defunct
include("FixedSizeArrays.jl") # Currently defunct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obsolete comment.

@SimonDanisch
Copy link
Member Author

Which parts of this do you still need?

All!

I wouldn't mind to have this come as standard functionality of StaticArrays!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 70.427% when pulling 80342bf on sd/fixedsizearrays into 8d3ec32 on master.

@c42f
Copy link
Member

c42f commented Apr 11, 2017

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 Base.AbstractArray conventions. (For example, Base.isnan is an elementwise operation in julia 0.5, but FixedSizeArrays.isnan is a reduction. You could/should use any(isnan.(v)) instead.)

Copy link
Member

@c42f c42f left a 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])"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These returns don't do anything - leftovers from previous changes, I think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, ditch the returns.

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}})
Copy link
Member

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.

Copy link
Member Author

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...

Copy link
Member

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 ;-)

Copy link
Member

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.

@SimonDanisch
Copy link
Member Author

FixedSizeArrays.isnan is a reduction. You could/should use any(isnan.(v)) instead.)

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.
But I guess I can remove it, if that would make it hard to merge for you!

@c42f
Copy link
Member

c42f commented Apr 11, 2017

Not 100% sure about that, now that people should use isnan.(Vector) for element wise application, which should disambiguate this case

True, once 0.6 deprecations are of the way isnan(::Vector) could take on a new meaning in Base, in principle. Though I'm not sure it should - as a Base function, would it mean all(isnan.(v)) or any(isnan.(v)) for instance? Seems potentially ambiguous.

But I guess I can remove it, if that would make it hard to merge for you!

Not at all, I'm fine merging it inside the StaticArrays.FixedSizeArrays submodule. I just meant this as an example of where the utilities in StaticArrays.FixedSizeArrays diverge from AbstractArray, which would make me uncomfortable about including them in the main StaticArrays module.

@SimonDanisch
Copy link
Member Author

Should we merge it as is and get rid of the fixedsizearray module in a later release?

@andyferris
Copy link
Member

FYI the reductions generally take a function, like any(isnan, vector) (much faster than any(isnan.(vector)))

@andyferris
Copy link
Member

Simon - I'm happy that you have worked on this. Let's fix (revert?) util.jl and merge.

@andyferris
Copy link
Member

andyferris commented Apr 19, 2017

Actually, can you explain the broadcast changes?

(Would it have been better to have generic bugfixes in a separate PR?)

Andy Ferris added 3 commits April 19, 2017 14:06
Tests have not been updated
Still having an inference problem in test/solve.jl. Can't reproduce,
however.
@SimonDanisch
Copy link
Member Author

Actually, can you explain the broadcast changes?
(Would it have been better to have generic bugfixes in a separate PR?)

Yes I guess... Problem is, it's much nicer (for me) to have all fixes for GeometryTypes/GLVisualize in one branch....

The change makes round.(Int, vec) work and opens up support for similar behaviour to what base is doing - treating everything not an array as a scalar!

@andyferris
Copy link
Member

I thought so - got it!

Base in v0.6 actually has a rather fancy implementation of broadcast. Ideally we'd hook into this (assuming it is inlined).

@coveralls
Copy link

Coverage Status

Coverage increased (+0.9%) to 70.472% when pulling 8c8a5ca on sd/fixedsizearrays into 8d3ec32 on master.

@SimonDanisch
Copy link
Member Author

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!

@c42f
Copy link
Member

c42f commented Apr 19, 2017

I checked out utils.jl and only put the error in quotes for the generated function

Thanks Simon, this looks a lot better now.

Copy link
Member

@c42f c42f left a 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 👍

@andyferris
Copy link
Member

Simon - I'd really like to also merge #134. However, it is a bit breaking... Because I am lazy 😄, could I ask you to (a) give your opinion of #134, and (b) if you like it, consider rebasing this upon that?

@c42f c42f mentioned this pull request Apr 19, 2017
@SimonDanisch
Copy link
Member Author

Okay, that was way too easy :D

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 70.115% when pulling 380c44b on sd/fixedsizearrays into b643ff5 on master.

@andyferris
Copy link
Member

This needs a rebase

@SimonDanisch
Copy link
Member Author

Done!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 70.636% when pulling e1f68b1 on sd/fixedsizearrays into c4008ff on master.

@c42f c42f merged commit 2a09e2c into master Apr 24, 2017
@SimonDanisch SimonDanisch deleted the sd/fixedsizearrays branch April 25, 2017 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants