Skip to content

Commit

Permalink
update for Julia v0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
RalphAS committed Jul 21, 2018
1 parent 926e76a commit 9245cb3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- nightly
notifications:
email: false
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.6
julia 0.7beta
Compat 0.53
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand All @@ -28,8 +28,8 @@ install:
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
- C:\projects\julia\bin\julia -e "using InteractiveUtils; import Pkg; versioninfo();
Pkg.clone(pwd(), \"IndirectArrays\"); Pkg.build(\"IndirectArrays\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"IndirectArrays\")"
- C:\projects\julia\bin\julia -e "import Pkg; Pkg.test(\"IndirectArrays\")"
22 changes: 4 additions & 18 deletions src/IndirectArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ __precompile__(true)

module IndirectArrays

using Compat

export IndirectArray

"""
Expand All @@ -27,31 +25,19 @@ struct IndirectArray{T,N,A<:AbstractArray{<:Integer,N},V<:AbstractVector{T}} <:
end
Base.@propagate_inbounds IndirectArray(index::AbstractArray{<:Integer,N}, values::AbstractVector{T}) where {T,N} =
IndirectArray{T,N,typeof(index),typeof(values)}(index, values)
function (::Type{IndirectArray{T}})(A::AbstractArray) where {T}
function IndirectArray{T}(A::AbstractArray) where {T}
values = unique(A)
index = convert(Array{T}, indexin(A, values))
return IndirectArray(index, values)
end
IndirectArray(A::AbstractArray) = IndirectArray{UInt8}(A)

Base.size(A::IndirectArray) = size(A.index)
Base.indices(A::IndirectArray) = indices(A.index)
Base.axes(A::IndirectArray) = axes(A.index)
Base.IndexStyle(::Type{IndirectArray{T,N,A,V}}) where {T,N,A,V} = IndexStyle(A)

Base.copy(A::IndirectArray) = IndirectArray(copy(A.index), copy(A.values))

if VERSION < v"0.6.3"
# This method is only necessary because of a bug in Julia 0.6.2 and can be removed
# when we no longer support that version
@inline function Base.getindex(A::IndirectArray{<:Any,1}, i::Int)
@boundscheck checkbounds(A.index, i)
@inbounds idx = A.index[i]
@boundscheck checkbounds(A.values, idx)
@inbounds ret = A.values[idx]
ret
end
end

@inline function Base.getindex(A::IndirectArray, i::Int)
@boundscheck checkbounds(A.index, i)
@inbounds idx = A.index[i]
Expand All @@ -70,7 +56,7 @@ end

@inline function Base.setindex!(A::IndirectArray, x, i::Int)
@boundscheck checkbounds(A.index, i)
idx = Compat.findfirst(A.values, x)
idx = findfirst(isequal(x), A.values)
if idx == nothing
push!(A.values, x)
A.index[i] = length(A.values)
Expand All @@ -81,7 +67,7 @@ end
end

@inline function Base.push!(A::IndirectArray{T,1} where T, x)
idx = Compat.findfirst(A.values, x)
idx = findfirst(isequal(x), A.values)
if idx == nothing
push!(A.values, x)
push!(A.index, length(A.values))
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using IndirectArrays, MappedArrays
using Base.Test, FixedPointNumbers, Colors
using Test, FixedPointNumbers, Colors

colors = [RGB(1,0,0) RGB(0,1,0);
RGB(0,0,1) RGB(1,0,0)]
Expand Down

0 comments on commit 9245cb3

Please sign in to comment.