Skip to content

Commit

Permalink
Remove code specific to Julia v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
oschulz committed Jan 15, 2019
1 parent cfe767f commit 88c5be9
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 153 deletions.
8 changes: 3 additions & 5 deletions src/unsafe_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Base.@propagate_inbounds _unsafe_view_impl(IFwd::NTuple{M,Base.ViewIndex}, A::Un
@boundscheck checkbounds(A, I_all...)
startidxs = map(first, (IFwd..., i, I...))
sub_s = _sub_size(I_all...)
p = pointer(A, _fast_sub2ind(size(A), startidxs...))
p = pointer(A, LinearIndices(size(A))[startidxs...])
UnsafeArray(p, sub_s)
end

Expand Down Expand Up @@ -162,8 +162,6 @@ Base.deepcopy(A::UnsafeArray) = copyto!(similar(A), A)
# # some reason, even when it shouldn't be called. By default, unaliascopy
# # results in an error for UnsafeArray.
#
# @static if VERSION >= v"1.7.0-DEV.4404"
# Base.unaliascopy(A::UnsafeArray) = begin
# copy(A)
# end
# Base.unaliascopy(A::UnsafeArray) = begin
# copy(A)
# end
20 changes: 1 addition & 19 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ const IdxUnitRange = AbstractUnitRange{<:Integer}
const DenseIdx = Union{IdxUnitRange,Integer}


@static if VERSION < v"0.7.0-DEV.3025"
# LinearIndices(dims...)[I...] is slow on Julia v0.6, use sub2ind instead:
Base.@propagate_inbounds _fast_sub2ind(dims::Dims{N}, I::Vararg{Integer,N}) where {N} = sub2ind(dims, I...)
else
Base.@propagate_inbounds _fast_sub2ind(dims::Dims{N}, I::Vararg{Integer,N}) where {N} = LinearIndices(dims)[I...]
end


# Similar to Base._indices_sub:
@inline _sub_axes() = ()
@inline _sub_axes(::Real, I...) = _sub_axes(I...)
Expand Down Expand Up @@ -58,15 +50,5 @@ macro gc_preserve(args...)
s isa Symbol || error("@gc_preserve targets must be a symbols")
end

@static if VERSION >= v"0.7.0-DEV.3465"
esc(:(GC.@preserve $(syms...) $(Expr(:let, Expr(:block), expr))))
else
esc(quote
try
$expr
finally
$(Expr(:call, :(UnsafeArrays._noinline_nop), syms))
end
end)
end
esc(:(GC.@preserve $(syms...) $(Expr(:let, Expr(:block), expr))))
end
91 changes: 32 additions & 59 deletions src/uview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,7 @@ function uviews end
export uviews

@inline function uviews(f::Function, As::AbstractArray...)
@static if VERSION >= v"0.7.0-DEV.3465"
GC.@preserve(As, f(map(uview, As)...))
else
try
f(map(uview, As)...)
finally
_noinline_nop(As)
end
end
GC.@preserve(As, f(map(uview, As)...))
end


Expand Down Expand Up @@ -136,69 +128,50 @@ macro uviews(args...)
syms = args[1:end-1]
expr = args[end]

@static if VERSION >= v"0.7.0-DEV.3465"
binds = Expr(:block)
for s in syms
s isa Symbol || error("@uviews targets must be a symbols")
push!(binds.args, :($s = UnsafeArrays.uview($s)))
end
let_expr = Expr(:let, binds, expr)
esc(:(GC.@preserve $(syms...) $(let_expr)))
else
let_expr = Expr(:let)
push!(let_expr.args, expr)
for s in syms
s isa Symbol || error("@uviews targets must be a symbols")
push!(let_expr.args, :($s = UnsafeArrays.uview($s)))
end

esc(quote
try
$let_expr
finally
$(Expr(:call, :(UnsafeArrays._noinline_nop), syms))
end
end)
binds = Expr(:block)
for s in syms
s isa Symbol || error("@uviews targets must be a symbols")
push!(binds.args, :($s = UnsafeArrays.uview($s)))
end
let_expr = Expr(:let, binds, expr)
esc(:(GC.@preserve $(syms...) $(let_expr)))
end

export @uviews


@static if VERSION >= v"0.7.0-DEV.4404"
function Base.mightalias(A::UnsafeArray, B::UnsafeArray)
pfA = pointer(A, firstindex(A))
plA = pointer(A, lastindex(A))
pfB = pointer(B, firstindex(B))
plB = pointer(B, lastindex(B))
function Base.mightalias(A::UnsafeArray, B::UnsafeArray)
pfA = pointer(A, firstindex(A))
plA = pointer(A, lastindex(A))
pfB = pointer(B, firstindex(B))
plB = pointer(B, lastindex(B))

(pfA <= pfB <= plA) || (pfA <= plB <= plA) || (pfB <= pfA <= plB)
end
(pfA <= pfB <= plA) || (pfA <= plB <= plA) || (pfB <= pfA <= plB)
end

function Base.mightalias(A::UnsafeArray, B::AbstractArray)
@uviews B begin
if typeof(B) <: UnsafeArray
Base.mightalias(A, B)
else
false
end
function Base.mightalias(A::UnsafeArray, B::AbstractArray)
@uviews B begin
if typeof(B) <: UnsafeArray
Base.mightalias(A, B)
else
false
end
end
end

Base.mightalias(A::AbstractArray, B::UnsafeArray) = Base.mightalias(B, A)
Base.mightalias(A::AbstractArray, B::UnsafeArray) = Base.mightalias(B, A)

Base.mightalias(A::SubArray{T,N,<:UnsafeArray}, B::AbstractArray) where {T,N} =
Base.mightalias(parent(A), B)
Base.mightalias(A::SubArray{T,N,<:UnsafeArray}, B::AbstractArray) where {T,N} =
Base.mightalias(parent(A), B)

Base.mightalias(A::SubArray{T1,N1,<:UnsafeArray}, B::SubArray{T2,N2,<:UnsafeArray}) where {T1,N1,T2,N2} =
Base.mightalias(parent(A), parent(B))
Base.mightalias(A::SubArray{T1,N1,<:UnsafeArray}, B::SubArray{T2,N2,<:UnsafeArray}) where {T1,N1,T2,N2} =
Base.mightalias(parent(A), parent(B))

Base.mightalias(A::SubArray{T,N,<:UnsafeArray}, B::UnsafeArray) where {T,N} =
Base.mightalias(parent(A), B)
Base.mightalias(A::SubArray{T,N,<:UnsafeArray}, B::UnsafeArray) where {T,N} =
Base.mightalias(parent(A), B)

Base.mightalias(A::AbstractArray, B::SubArray{T,N,<:UnsafeArray}) where {T,N} =
Base.mightalias(B, A)
Base.mightalias(A::AbstractArray, B::SubArray{T,N,<:UnsafeArray}) where {T,N} =
Base.mightalias(B, A)

Base.mightalias(A::UnsafeArray, B::SubArray{T,N,<:UnsafeArray}) where {T,N} =
Base.mightalias(B, A)
end
Base.mightalias(A::UnsafeArray, B::SubArray{T,N,<:UnsafeArray}) where {T,N} =
Base.mightalias(B, A)
30 changes: 11 additions & 19 deletions test/unsafe_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ using Compat: axes
@test @inferred(length(UA)) == length(A)
@test @inferred(IndexStyle(UA)) == IndexLinear()
@test @inferred(LinearIndices(UA)) == LinearIndices(A)
@static if VERSION < v"0.7.0-DEV.3025"
@test @inferred(linearindices(UA)) == linearindices(A)
end
@test @inferred(eachindex(UA)) == eachindex(A)

@test @inferred(Base.unsafe_convert(Ptr{T}, UA)) == Base.unsafe_convert(Ptr{T}, A)
Expand Down Expand Up @@ -129,12 +126,9 @@ using Compat: axes
test_A_UA(Float32, Val(3)) do A, UA
@test typeof(@inferred(view(UA, :))) == UnsafeArray{Float32,1}
@test typeof(@inferred(view(UA, :, :, :))) == UnsafeArray{Float32,3}
@static if VERSION < v"0.7.0-DEV"
@test typeof(@inferred(view(UA, :, 3, :))) <: SubArray
else
# Inference fails on Julia v0.7, for some reason
@test typeof(view(UA, :, 3, :)) <: SubArray
end
# TODO: Type inference fails for some reason:
# @test typeof(@inferred(view(UA, :, 3, :))) <: SubArray
@test typeof((view(UA, :, 3, :))) <: SubArray
@test typeof(@inferred(view(UA, :, :, 3))) == UnsafeArray{Float32,2}
@test typeof(@inferred(view(UA, :, 2:4, 3))) == UnsafeArray{Float32,2}
@test typeof(@inferred(view(UA, :, 2, 3))) == UnsafeArray{Float32,1}
Expand Down Expand Up @@ -287,17 +281,15 @@ using Compat: axes

# # Disabled, as specialization of Base.unaliascopy is disabled:
#
# @static if VERSION >= v"0.7.0-DEV.4404"
# @testset "unaliascopy" begin
# test_A_UA(Float32, Val(3)) do A, UA
# @test typeof(@inferred(Base.unaliascopy(UA))) == typeof(A)
# @test Base.unaliascopy(UA) == A
# end
# @testset "unaliascopy" begin
# test_A_UA(Float32, Val(3)) do A, UA
# @test typeof(@inferred(Base.unaliascopy(UA))) == typeof(A)
# @test Base.unaliascopy(UA) == A
# end
#
# test_A_UA(Int16, Val(1)) do A, UA
# @test typeof(@inferred(Base.unaliascopy(UA))) == typeof(A)
# @test Base.unaliascopy(UA) == A
# end
# test_A_UA(Int16, Val(1)) do A, UA
# @test typeof(@inferred(Base.unaliascopy(UA))) == typeof(A)
# @test Base.unaliascopy(UA) == A
# end
# end

Expand Down
97 changes: 46 additions & 51 deletions test/uview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ using Compat: axes
@test typeof(@inferred(uview(A, :, 2:4, 3))) == UnsafeArray{ComplexF32,2}
@test typeof(@inferred(uview(A, :))) == UnsafeArray{ComplexF32,1}
@test typeof(@inferred(uview(A, 2, 3, 4))) == UnsafeArray{ComplexF32,0}
@static if VERSION < v"0.7.0-DEV"
@test typeof(@inferred(uview(A, :, 2:4, :))) <: SubArray
else
# Inference fails on Julia v0.7, for some reason
@test typeof(uview(A, :, 2:4, :)) <: SubArray
end
# TODO: Type inference fails for some reason:
# @test typeof(@inferred(uview(A, :, 2:4, :))) <: SubArray
@test typeof((uview(A, :, 2:4, :))) <: SubArray

@test uview(A) == A
@test uview(A, :, 2:4, 3) == view(A, :, 2:4, 3)
Expand Down Expand Up @@ -111,62 +108,60 @@ using Compat: axes
end


@static if VERSION >= v"0.7.0-DEV.4404"
@testset "Base.mightalias" begin
A = rand(Int32, 10, 15)
B = rand(Int32, 12, 17)
C = ["foo", "bar", "a", "b", "c", "d", "e"]
@testset "Base.mightalias" begin
A = rand(Int32, 10, 15)
B = rand(Int32, 12, 17)
C = ["foo", "bar", "a", "b", "c", "d", "e"]

@uviews A B begin
@test true == @inferred Base.mightalias(A, A)
@test false == @inferred Base.mightalias(A, B)
@uviews A B begin
@test true == @inferred Base.mightalias(A, A)
@test false == @inferred Base.mightalias(A, B)

@test false == @inferred Base.mightalias(view(A, :, 2:5), view(A, :, 6:10))
@test false == @inferred Base.mightalias(view(A, :, 6:10), view(A, :, 2:5))
@test false == @inferred Base.mightalias(view(A, :, 2:5), view(A, :, 6:10))
@test false == @inferred Base.mightalias(view(A, :, 6:10), view(A, :, 2:5))

@test true == @inferred Base.mightalias(view(A, :, 2:6), view(A, :, 5:10))
@test true == @inferred Base.mightalias(view(A, :, 5:10), view(A, :, 2:6))
@test true == @inferred Base.mightalias(view(A, :, 2:10), view(A, :, 5:6))
@test true == @inferred Base.mightalias(view(A, :, 5:6), view(A, :, 2:10))
@test true == @inferred Base.mightalias(view(A, :, 2:6), view(A, :, 5:10))
@test true == @inferred Base.mightalias(view(A, :, 5:10), view(A, :, 2:6))
@test true == @inferred Base.mightalias(view(A, :, 2:10), view(A, :, 5:6))
@test true == @inferred Base.mightalias(view(A, :, 5:6), view(A, :, 2:10))

@test false == @inferred Base.mightalias(view(A, :, 2:5), view(A, :, 6:10))
@test true == @inferred Base.mightalias(view(A, 2:5, :), view(A, :, 6:10))
@test true == @inferred Base.mightalias(view(A, :, 2:5), view(A, 6:10, :))
@test true == @inferred Base.mightalias(view(A, 2:5, :), view(A, 6:10, :))
end
@test false == @inferred Base.mightalias(view(A, :, 2:5), view(A, :, 6:10))
@test true == @inferred Base.mightalias(view(A, 2:5, :), view(A, :, 6:10))
@test true == @inferred Base.mightalias(view(A, :, 2:5), view(A, 6:10, :))
@test true == @inferred Base.mightalias(view(A, 2:5, :), view(A, 6:10, :))
end

@uviews A begin
@test false == @inferred Base.mightalias(A, B)
@test false == @inferred Base.mightalias(view(A, 2:5, :), B)
@test false == @inferred Base.mightalias(A, view(B, :, 2:5))
@test false == @inferred Base.mightalias(view(A, 2:5, :), view(B, :, 2:5))
@uviews A begin
@test false == @inferred Base.mightalias(A, B)
@test false == @inferred Base.mightalias(view(A, 2:5, :), B)
@test false == @inferred Base.mightalias(A, view(B, :, 2:5))
@test false == @inferred Base.mightalias(view(A, 2:5, :), view(B, :, 2:5))

@test false == @inferred Base.mightalias(B, A)
@test false == @inferred Base.mightalias(B, view(A, 2:5, :))
@test false == @inferred Base.mightalias(view(B, :, 2:5), A)
@test false == @inferred Base.mightalias(view(B, :, 2:5), view(A, 2:5, :))
end
@test false == @inferred Base.mightalias(B, A)
@test false == @inferred Base.mightalias(B, view(A, 2:5, :))
@test false == @inferred Base.mightalias(view(B, :, 2:5), A)
@test false == @inferred Base.mightalias(view(B, :, 2:5), view(A, 2:5, :))
end


@uviews A C begin
@test false == @inferred Base.mightalias(A, C)
@uviews A C begin
@test false == @inferred Base.mightalias(A, C)

@test false == @inferred Base.mightalias(view(A, 2:5, :), C)
@test false == @inferred Base.mightalias(A, view(C, 2:5))
@test false == @inferred Base.mightalias(view(A, 2:5, :), view(C, 2:5))
end
@test false == @inferred Base.mightalias(view(A, 2:5, :), C)
@test false == @inferred Base.mightalias(A, view(C, 2:5))
@test false == @inferred Base.mightalias(view(A, 2:5, :), view(C, 2:5))
end

@uviews A begin
@test false == @inferred Base.mightalias(A, C)
@test false == @inferred Base.mightalias(view(A, 2:5, :), C)
@test false == @inferred Base.mightalias(A, view(C, 2:5))
@test false == @inferred Base.mightalias(view(A, 2:5, :), view(C, 2:5))
@uviews A begin
@test false == @inferred Base.mightalias(A, C)
@test false == @inferred Base.mightalias(view(A, 2:5, :), C)
@test false == @inferred Base.mightalias(A, view(C, 2:5))
@test false == @inferred Base.mightalias(view(A, 2:5, :), view(C, 2:5))

@test false == @inferred Base.mightalias(C, A)
@test false == @inferred Base.mightalias(C, view(A, 2:5, :))
@test false == @inferred Base.mightalias(view(C, 2:5), A)
@test false == @inferred Base.mightalias(view(C, 2:5), view(A, 2:5, :))
end
@test false == @inferred Base.mightalias(C, A)
@test false == @inferred Base.mightalias(C, view(A, 2:5, :))
@test false == @inferred Base.mightalias(view(C, 2:5), A)
@test false == @inferred Base.mightalias(view(C, 2:5), view(A, 2:5, :))
end
end
end

0 comments on commit 88c5be9

Please sign in to comment.