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

deprecate constructors with type as first argument #34

Merged
merged 1 commit into from
Jan 15, 2018

Conversation

fredrikekre
Copy link
Member

This type of Array constructors where deprecated in JuliaLang/julia#19989, so OffsetArrays should do the same. Including the comma and the space, the replacement is even the same number of characters 😄

@fredrikekre
Copy link
Member Author

Tests fail because of JuliaLang/Compat.jl#416 (comment), so need to wait for Compat v0.39.

OffsetArray(f(map(length, shape)), map(indexoffset, shape))
Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:OffsetArray} =
OffsetArray(T(map(length, shape)), map(indexoffset, shape))
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to split this into two methods to fix this on julia master:

julia> Test.detect_ambiguities(OffsetArrays, Base, Core)
Skipping Base.Date
2-element Array{Tuple{Method,Method},1}:
 (similar(f::Union{Function, Type}, shape::Tuple{UnitRange,Vararg{UnitRange,N} where N}) in OffsetArrays at /Users/Fredrik/.julia/v0.7/OffsetArrays/src/OffsetArrays.jl:89, similar(::Type{T}, shape::Tuple) where T<:BitArray in Base at bitarray.jl:355)
 (similar(f::Union{Function, Type}, shape::Tuple{UnitRange,Vararg{UnitRange,N} where N}) in OffsetArrays at /Users/Fredrik/.julia/v0.7/OffsetArrays/src/OffsetArrays.jl:89, similar(::Type{T}, shape::Tuple) where T<:Array in Base at array.jl:254)

Copy link
Member

@timholy timholy left a comment

Choose a reason for hiding this comment

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

Looks good, though the test failures and depwarns indicate that we have a ways to go yet.

OffsetArray(f(map(length, shape)), map(indexoffset, shape))
Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:OffsetArray} =
OffsetArray(T(map(length, shape)), map(indexoffset, shape))
Copy link
Member

Choose a reason for hiding this comment

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

Will the T version trigger your deprecation warning?

@fredrikekre
Copy link
Member Author

Yes there is some more stuff to work out here, see e.g. JuliaLang/julia#24785 (comment)

I'm planning to take a look tonight.

Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:Array} =
OffsetArray(T(map(length, shape)), map(indexoffset, shape))
Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:BitArray} =
OffsetArray(T(map(length, shape)), map(indexoffset, shape))
Copy link
Member Author

Choose a reason for hiding this comment

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

These two similar methods make me a bit uncomfortable.

Copy link
Member

Choose a reason for hiding this comment

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

What motivated their addition? Presumably a test failure?

@fredrikekre
Copy link
Member Author

Tests pass locally with JuliaLang/julia#24918 now, but not sure about those similar methods.

@fredrikekre
Copy link
Member Author

Rebased after #37

OffsetVector{T}(inds::AbstractUnitRange) where {T} = OffsetArray{T}(inds)

# https://github.com/JuliaLang/julia/pull/19989
Base.@deprecate OffsetArray(::Type{T}, inds::Vararg{UnitRange{Int},N}) where {T,N} OffsetArray{T}(inds)
Copy link
Member

Choose a reason for hiding this comment

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

What about switching to uninitialized syntax now? We're moving now to ArrayType(iterator) constructs the array from the contents of iterator, but since -3:3 is an iterator it's ambiguous whether that's supposed to be treated as the initializing values or the axes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have that change as another PR in the pipeline, I can include it in this one if you prefer?

Copy link
Member

Choose a reason for hiding this comment

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

Either way is fine with me. I'll merge this and you can do that in a next one.

@timholy timholy merged commit ce24a51 into JuliaArrays:master Jan 15, 2018
@fredrikekre fredrikekre deleted the fe/type-constructor branch January 15, 2018 19:10
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.

2 participants