-
Notifications
You must be signed in to change notification settings - Fork 40
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
[WIP] fixes for julia 0.7 #37
[WIP] fixes for julia 0.7 #37
Conversation
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.
👍
src/OffsetArrays.jl
Outdated
# Broadcasting interface | ||
@static if VERSION > v"0.7.0-DEV.2638" # https://github.com/JuliaLang/julia/pull/23939 | ||
struct OffsetArrayStyle <: Broadcast.BroadcastStyle end | ||
Broadcast.BroadcastStyle(::Type{<:OffsetArray}) = OffsetArrayStyle() |
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 you can save several lines with
Broadcast.BroadcastStyle(::Type{<:OffsetArray}) = Broadcast.ArrayStyle{OffsetArray}()
You shouldn't need broadcast_indices
or define the rule with respect to Scalar
. More importantly, it should also successfully take precedence over, e.g., Array
.
test/runtests.jl
Outdated
@@ -312,12 +312,12 @@ seek(io, 0) | |||
amin, amax = extrema(parent(A)) | |||
@test clamp.(A, (amax+amin)/2, amax) == OffsetArray(clamp.(parent(A), (amax+amin)/2, amax), indices(A)) | |||
|
|||
@test unique(A, 1) == parent(A) | |||
@test unique(A, 2) == parent(A) | |||
# @test unique(A, 1) == parent(A) |
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.
Why do these need to be commented out?
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, sorry, I see you explained.
I'm less worried about the hijacking than you. To me similar(BitArray, inds)
means "give me something that acts like a BitArray but has the following inds." If that's not a BitArray (generally, it will turn out to be a wrapped BitArray), that's fine.
test/runtests.jl
Outdated
v = OffsetArray(rand(8), (-2,)) | ||
@test sort(v) == OffsetArray(sort(parent(v)), v.offsets) | ||
@test sortrows(A) == OffsetArray(sortrows(parent(A)), A.offsets) | ||
@test sortcols(A) == OffsetArray(sortcols(parent(A)), A.offsets) | ||
# @test sortrows(A) == OffsetArray(sortrows(parent(A)), A.offsets) |
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.
Here too?
f6b40d3
to
ca511d6
Compare
Alright, this just needs JuliaLang/Compat.jl#427 and JuliaLang/Compat.jl#429 now, then a new Compat version. |
src/OffsetArrays.jl
Outdated
OffsetArray(T(uninitialized, map(length, shape)), map(indexoffset, shape)) | ||
|
||
# Broadcasting interface | ||
@static if VERSION > v"0.7.0-DEV.2638" # https://github.com/JuliaLang/julia/pull/23939 |
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.
Do we need this anymore or is it handled by similar
?
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.
No 😞 But it was fun to try the new interface 😄
Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:Array} = | ||
OffsetArray(T(uninitialized, map(length, shape)), map(indexoffset, shape)) | ||
Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:BitArray} = | ||
OffsetArray(T(uninitialized, map(length, shape)), map(indexoffset, shape)) |
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.
Do we need all three of these specializations or would
Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:AbstractArray} =
OffsetArray(T(map(length, shape)), map(indexoffset, shape))
be good enough? (OffsetArray being the defacto "owner" of UnitRange
indices.)
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, the are needed for ambiguity resolution with https://github.com/JuliaLang/julia/blob/7d7d81af41448aeaafb2dadedf54e831616c25cf/base/array.jl#L254 and https://github.com/JuliaLang/julia/blob/7d7d81af41448aeaafb2dadedf54e831616c25cf/base/bitarray.jl#L355. And we also need a separate for OffsetArray
, which does not use the new uninitialized
singleton for construction. I plan to implement that in a separate PR.
ca511d6
to
8c8f4f3
Compare
This seems ready to go except for the 0.6 breakage. |
Yes, for 0.6 this needs a new |
8c8f4f3
to
9d0e8c3
Compare
b06b453
to
1988cf2
Compare
- indices -> axes - ind2sub -> CartesianIndices - CartesianRange -> CartesianIndices - copy! -> copyto!
1988cf2
to
ce854a7
Compare
Looks like tests passes on both 0.6 and 0.7 now :) |
Wonderful, many thanks for seeing this through. |
Split out from #34: This PR aims to just get things working on julia master, and then I will rebase #34 on top of this.
So after investigating a bit further regarding the
similiar
methods discussed in #34 there seem to be two problems:With the new broadcasting interface,
broadcast_similar
used the fallback method. I fixed this by hooking into the broadcast machinery (excellent interface btw Tim 🎉)The other problems show up in the tests I commented out for now. For instance:
which is because
unique
calls thesimilar(::Type{BitArray}, inds)
method here: https://github.com/JuliaLang/julia/blob/c697415e5d665e2085846dc3a3313cff296ef98f/base/multidimensional.jl#L1606 which forces us to hijack that method.Similarly, for
sortcols
/sortrows
we end up here: https://github.com/JuliaLang/julia/blob/c697415e5d665e2085846dc3a3313cff296ef98f/base/sort.jl#L964 which forces us to hijack that method.sortcols
/sortrows
can be fixed, I think with the following patch to base: