diff --git a/.travis.yml b/.travis.yml index 1ce59d4..36504be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,27 @@ language: julia + os: - - linux - osx + - linux + julia: - - 0.4 - - 0.5 + - 0.7 + - 1.0 - nightly + +# # Uncomment the following lines to allow failures on nightly julia +# # (tests will run but not make your overall status red) +# matrix: +# allow_failures: +# - julia: nightly + notifications: email: false -script: - - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("StructsOfArrays"); Pkg.test("StructsOfArrays"; coverage=true)' + +#script: # the default script is equivalent to the following +# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi +# - julia -e 'Pkg.clone(pwd()); Pkg.build("Example"); Pkg.test("Example"; coverage=true)'; + after_success: - - julia -e 'cd(Pkg.dir("StructsOfArrays")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' + # - julia -e 'if VERSION >= v"0.7.0-" using Pkg end; cd(Pkg.dir("StructsOfArrays")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; + - julia -e 'if VERSION >= v"0.7.0-" using Pkg end; cd(Pkg.dir("StructsOfArrays")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'; diff --git a/REQUIRE b/REQUIRE index 33ed633..859ad46 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1 @@ -julia 0.4 -Compat 0.19 +julia 0.7 diff --git a/appveyor.yml b/appveyor.yml index 979983a..c2588f1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,18 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-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" + - julia_version: 0.7 + - julia_version: 1 + - julia_version: nightly + +platform: + - x86 # 32-bit + - x64 # 64-bit + +# # Uncomment the following lines to allow failures on nightly julia +# # (tests will run but not make your overall status red) +# matrix: +# allow_failures: +# - julia_version: nightly branches: only: @@ -19,19 +26,18 @@ notifications: on_build_status_changed: false install: - - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $env:JULIA_URL, - "C:\projects\julia-binary.exe") -# Run installer silently, output to C:\projects\julia - - C:\projects\julia-binary.exe /S /D=C:\projects\julia + - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) 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(); - Pkg.clone(pwd(), \"StructsOfArrays\"); Pkg.build(\"StructsOfArrays\")" + - echo "%JL_BUILD_SCRIPT%" + - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" test_script: - - C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"StructsOfArrays\")" + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" + +# # Uncomment to support code coverage upload. Should only be enabled for packages +# # which would have coverage gaps without running on Windows +# on_success: +# - echo "%JL_CODECOV_SCRIPT%" +# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" diff --git a/src/StructsOfArrays.jl b/src/StructsOfArrays.jl index eb4226a..272eac7 100644 --- a/src/StructsOfArrays.jl +++ b/src/StructsOfArrays.jl @@ -1,15 +1,13 @@ module StructsOfArrays -using Compat - export StructOfArrays -immutable StructOfArrays{T,N,U<:Tuple} <: AbstractArray{T,N} +struct StructOfArrays{T,N,U<:Tuple} <: AbstractArray{T,N} arrays::U end function gather_eltypes(T, visited = Set{Type}()) - (!isleaftype(T) || T.mutable) && throw(ArgumentError("can only create an StructOfArrays of leaf type immutables")) + (!isconcretetype(T) || T.mutable) && throw(ArgumentError("can only create an StructOfArrays of concrete type immutable structs")) isempty(T.types) && throw(ArgumentError("cannot create an StructOfArrays of an empty or bitstype")) types = Type[] push!(visited, T) @@ -25,29 +23,29 @@ function gather_eltypes(T, visited = Set{Type}()) types end -@generated function StructOfArrays{T}(::Type{T}, dims::Integer...) +@generated function StructOfArrays(::Type{T}, dims::Integer...) where {T} N = length(dims) types = gather_eltypes(T) arrtuple = Tuple{[Array{S,N} for S in types]...} - :(StructOfArrays{T,$N,$arrtuple}(($([:(Array{$(S)}(dims)) for S in types]...),))) + :(StructOfArrays{T,$N,$arrtuple}(($([:(Array{$(S)}(undef, dims)) for S in types]...),))) end StructOfArrays(T::Type, dims::Tuple{Vararg{Integer}}) = StructOfArrays(T, dims...) -@compat Base.IndexStyle{T<:StructOfArrays}(::Type{T}) = IndexLinear() +Base.IndexStyle(::Type{T}) where {T<:StructOfArrays} = IndexLinear() -@generated function Base.similar{T}(A::StructOfArrays, ::Type{T}, dims::Dims) - if isbits(T) && length(T.types) > 1 +@generated function Base.similar(A::StructOfArrays, ::Type{T}, dims::Dims) where {T} + if isbitstype(T) && length(T.types) > 1 :(StructOfArrays(T, dims)) else - :(Array{T}(dims)) + :(Array{T}(undef, dims)) end end -Base.convert{T,S,N}(::Type{StructOfArrays{T,N}}, A::AbstractArray{S,N}) = - copy!(StructOfArrays(T, size(A)), A) -Base.convert{T,S,N}(::Type{StructOfArrays{T}}, A::AbstractArray{S,N}) = +Base.convert(::Type{StructOfArrays{T,N}}, A::AbstractArray{S,N}) where {T,S,N} = + copyto!(StructOfArrays(T, size(A)), A) +Base.convert(::Type{StructOfArrays{T}}, A::AbstractArray{S,N}) where {T,S,N} = convert(StructOfArrays{T,N}, A) -Base.convert{T,N}(::Type{StructOfArrays}, A::AbstractArray{T,N}) = +Base.convert(::Type{StructOfArrays}, A::AbstractArray{T,N}) where {T,N} = convert(StructOfArrays{T,N}, A) Base.size(A::StructOfArrays) = size(A.arrays[1]) @@ -68,7 +66,7 @@ function generate_getindex(T, arraynum) Expr(:new, T, members...), arraynum end -@generated function Base.getindex{T}(A::StructOfArrays{T}, i::Integer...) +@generated function Base.getindex(A::StructOfArrays{T}, i::Integer...) where {T} strct, _ = generate_getindex(T, 1) Expr(:block, Expr(:meta, :inline), strct) end @@ -89,7 +87,7 @@ function generate_setindex(T, x, arraynum) exprs, arraynum end -@generated function Base.setindex!{T}(A::StructOfArrays{T}, x, i::Integer...) +@generated function Base.setindex!(A::StructOfArrays{T}, x, i::Integer...) where {T} exprs = Expr(:block, generate_setindex(T, :x, 1)[1]...) quote $(Expr(:meta, :inline)) diff --git a/test/REQUIRE b/test/REQUIRE deleted file mode 100644 index fbb6170..0000000 --- a/test/REQUIRE +++ /dev/null @@ -1 +0,0 @@ -Compat 0.9.1 diff --git a/test/runtests.jl b/test/runtests.jl index 98b30bc..3acbe72 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,20 +1,19 @@ using StructsOfArrays -using Base.Test -using Compat +using Test -regular = @compat complex.(randn(10000), randn(10000)) +regular = complex.(randn(10000), randn(10000)) soa = convert(StructOfArrays, regular) @test regular == soa @test sum(regular) ≈ sum(soa) -soa64 = convert(StructOfArrays{Complex64}, regular) -@test convert(Array{Complex64}, regular) == soa64 +soa64 = convert(StructOfArrays{ComplexF32}, regular) +@test convert(Array{ComplexF32}, regular) == soa64 sim = similar(soa) @test typeof(sim) == typeof(soa) @test size(sim) == size(soa) -regular = @compat complex.(randn(10, 5), randn(10, 5)) +regular = complex.(randn(10, 5), randn(10, 5)) soa = convert(StructOfArrays, regular) for i = 1:10, j = 1:5 @test regular[i, j] == soa[i, j] @@ -22,19 +21,19 @@ end @test size(soa, 1) == 10 @test size(soa, 2) == 5 -immutable OneField +struct OneField x::Int end -small = StructOfArrays(Complex64, 2) +small = StructOfArrays(ComplexF32, 2) @test typeof(similar(small, Complex)) === Vector{Complex} @test typeof(similar(small, Int)) === Vector{Int} @test typeof(similar(small, SubString)) === Vector{SubString} @test typeof(similar(small, OneField)) === Vector{OneField} -@test typeof(similar(small, Complex128)) <: StructOfArrays +@test typeof(similar(small, ComplexF64)) <: StructOfArrays # Recursive structs -immutable TwoField +struct TwoField one::OneField two::OneField end