Skip to content
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

Loosen the signature on indices passed to _flatten. Fixes #17275. #17283

Merged
merged 1 commit into from
Jul 5, 2016

Conversation

timholy
Copy link
Member

@timholy timholy commented Jul 5, 2016

Ref #17275.

@timholy timholy merged commit b25739d into master Jul 5, 2016
@timholy timholy deleted the teh/fix_flatten branch July 5, 2016 20:28
@inline _flatten(out, i::Integer, I...) = _flatten((out..., i), I...)
@inline _flatten(out, i::CartesianIndex, I...) = _flatten((out..., i.I...), I...)
CartesianIndex(index::Union{Integer, CartesianIndex}...) = CartesianIndex(flatten(index))
Base.@pure flatten(I) = (_flatten(I...)...,)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this different than the flatten in iterators.jl ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It produces the same outcome, but it's non-lazy. Note that I'm not importing Base.flatten, so this doesn't "globally" extend flatten.

Copy link
Member

Choose a reason for hiding this comment

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

fwiw, I think a pure function should usually not be extended, but I'm not certain.

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean, there should be only one method?

Copy link
Member

Choose a reason for hiding this comment

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

perhaps. although more importantly, external code need to be careful about how they overload it (e.g. don't write code that could trigger a #265-style error)

Copy link
Member Author

Choose a reason for hiding this comment

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

For sure. Come to think of it, I don't need the @pure annotation on _flatten, just on flatten. (right?)

The only reason it was marked pure is because of #17126, but this flatten has since been redesigned several times, and in testing with this version I'm getting equal performance with @inline. So I'll change it.

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